diff --git a/src/function/parse.rs b/src/function/parse.rs index 0cfaa8b..4834cfd 100644 --- a/src/function/parse.rs +++ b/src/function/parse.rs @@ -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());