Fix parsing of greater/less-than-or-equal-to parameters

This commit is contained in:
Oliver Hamlet
2018-11-14 20:18:28 +00:00
parent 84c46ebe79
commit 26bbda4925
+83 -3
View File
@@ -17,10 +17,10 @@ impl ComparisonOperator {
alt!(
tag!("==") => { |_| ComparisonOperator::Equal } |
tag!("!=") => { |_| ComparisonOperator::NotEqual } |
tag!("<") => { |_| ComparisonOperator::LessThan } |
tag!(">") => { |_| ComparisonOperator::GreaterThan } |
tag!("<=") => { |_| ComparisonOperator::LessThanOrEqual } |
tag!(">=") => { |_| ComparisonOperator::GreaterThanOrEqual }
tag!(">=") => { |_| ComparisonOperator::GreaterThanOrEqual } |
tag!("<") => { |_| ComparisonOperator::LessThan } |
tag!(">") => { |_| ComparisonOperator::GreaterThan }
) >> (operator)
)
}
@@ -432,6 +432,86 @@ mod tests {
}
}
#[test]
fn function_parse_should_parse_a_version_not_equals_function() {
let result = Function::parse("version(\"Cargo.toml\", \"1.2\", !=)".into())
.unwrap()
.1;
match result {
Function::Version(path, version, comparator) => {
assert_eq!(Path::new("Cargo.toml"), path);
assert_eq!("1.2", version);
assert_eq!(ComparisonOperator::NotEqual, comparator);
}
_ => panic!("Expected a version function"),
}
}
#[test]
fn function_parse_should_parse_a_version_less_than_function() {
let result = Function::parse("version(\"Cargo.toml\", \"1.2\", <)".into())
.unwrap()
.1;
match result {
Function::Version(path, version, comparator) => {
assert_eq!(Path::new("Cargo.toml"), path);
assert_eq!("1.2", version);
assert_eq!(ComparisonOperator::LessThan, comparator);
}
_ => panic!("Expected a version function"),
}
}
#[test]
fn function_parse_should_parse_a_version_greater_than_function() {
let result = Function::parse("version(\"Cargo.toml\", \"1.2\", >)".into())
.unwrap()
.1;
match result {
Function::Version(path, version, comparator) => {
assert_eq!(Path::new("Cargo.toml"), path);
assert_eq!("1.2", version);
assert_eq!(ComparisonOperator::GreaterThan, comparator);
}
_ => panic!("Expected a version function"),
}
}
#[test]
fn function_parse_should_parse_a_version_less_than_or_equal_to_function() {
let result = Function::parse("version(\"Cargo.toml\", \"1.2\", <=)".into())
.unwrap()
.1;
match result {
Function::Version(path, version, comparator) => {
assert_eq!(Path::new("Cargo.toml"), path);
assert_eq!("1.2", version);
assert_eq!(ComparisonOperator::LessThanOrEqual, comparator);
}
_ => panic!("Expected a version function"),
}
}
#[test]
fn function_parse_should_parse_a_version_greater_than_or_equal_to_function() {
let result = Function::parse("version(\"Cargo.toml\", \"1.2\", >=)".into())
.unwrap()
.1;
match result {
Function::Version(path, version, comparator) => {
assert_eq!(Path::new("Cargo.toml"), path);
assert_eq!("1.2", version);
assert_eq!(ComparisonOperator::GreaterThanOrEqual, comparator);
}
_ => panic!("Expected a version function"),
}
}
#[test]
fn function_parse_should_error_if_the_version_path_is_outside_the_game_directory() {
assert!(Function::parse("version(\"../../Cargo.toml\", \"1.2\", ==)".into()).is_err());