Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow string to copmpare with another string #11590

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/nu-parser/src/type_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,7 @@ pub fn math_result_type(
(Type::Int, Type::Number) => (Type::Bool, None),
(Type::Number, Type::Float) => (Type::Bool, None),
(Type::Float, Type::Number) => (Type::Bool, None),
(Type::String, Type::String) => (Type::Bool, None),
(Type::Duration, Type::Duration) => (Type::Bool, None),
(Type::Date, Type::Date) => (Type::Bool, None),
(Type::Filesize, Type::Filesize) => (Type::Bool, None),
Expand Down Expand Up @@ -478,6 +479,7 @@ pub fn math_result_type(
(Type::Int, Type::Number) => (Type::Bool, None),
(Type::Number, Type::Float) => (Type::Bool, None),
(Type::Float, Type::Number) => (Type::Bool, None),
(Type::String, Type::String) => (Type::Bool, None),
(Type::Duration, Type::Duration) => (Type::Bool, None),
(Type::Date, Type::Date) => (Type::Bool, None),
(Type::Filesize, Type::Filesize) => (Type::Bool, None),
Expand Down Expand Up @@ -527,6 +529,7 @@ pub fn math_result_type(
(Type::Int, Type::Number) => (Type::Bool, None),
(Type::Number, Type::Float) => (Type::Bool, None),
(Type::Float, Type::Number) => (Type::Bool, None),
(Type::String, Type::String) => (Type::Bool, None),
(Type::Duration, Type::Duration) => (Type::Bool, None),
(Type::Date, Type::Date) => (Type::Bool, None),
(Type::Filesize, Type::Filesize) => (Type::Bool, None),
Expand Down Expand Up @@ -576,6 +579,7 @@ pub fn math_result_type(
(Type::Int, Type::Number) => (Type::Bool, None),
(Type::Number, Type::Float) => (Type::Bool, None),
(Type::Float, Type::Number) => (Type::Bool, None),
(Type::String, Type::String) => (Type::Bool, None),
(Type::Duration, Type::Duration) => (Type::Bool, None),
(Type::Date, Type::Date) => (Type::Bool, None),
(Type::Filesize, Type::Filesize) => (Type::Bool, None),
Expand Down
24 changes: 24 additions & 0 deletions crates/nu-parser/tests/test_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1915,3 +1915,27 @@ mod input_types {
)
}
}

#[cfg(test)]
mod operator {
use super::*;

#[rstest]
#[case(br#""abc" < "bca""#, "string < string")]
#[case(br#""abc" <= "bca""#, "string <= string")]
#[case(br#""abc" > "bca""#, "string > string")]
#[case(br#""abc" >= "bca""#, "string >= string")]
fn parse_comparison_operators_with_string_and_string(
#[case] expr: &[u8],
#[case] test_tag: &str,
) {
let engine_state = EngineState::new();
let mut working_set = StateWorkingSet::new(&engine_state);
parse(&mut working_set, None, expr, false);
assert_eq!(
working_set.parse_errors.len(),
0,
"{test_tag}: expected to be parsed successfully, but failed."
);
}
}