diff --git a/crates/nu-protocol/src/value/mod.rs b/crates/nu-protocol/src/value/mod.rs index 4ac2d563eb..9aa98f0c2f 100644 --- a/crates/nu-protocol/src/value/mod.rs +++ b/crates/nu-protocol/src/value/mod.rs @@ -1020,17 +1020,40 @@ impl Value { match (self, rhs) { (lhs, Value::Range { val: rhs, .. }) => Ok(Value::Bool { - val: lhs - .gte(Span::unknown(), &rhs.from) + val: if rhs + .incr + .gt( + Span::unknown(), + &Value::Int { + val: 0, + span: Span::unknown(), + }, + ) .map_or(false, |v| v.is_true()) - && match rhs.inclusion { - RangeInclusion::Inclusive => lhs - .lte(Span::unknown(), &rhs.to) - .map_or(false, |v| v.is_true()), - RangeInclusion::RightExclusive => lhs - .lt(Span::unknown(), &rhs.to) - .map_or(false, |v| v.is_true()), - }, + { + lhs.gte(Span::unknown(), &rhs.from) + .map_or(false, |v| v.is_true()) + && match rhs.inclusion { + RangeInclusion::Inclusive => lhs + .lte(Span::unknown(), &rhs.to) + .map_or(false, |v| v.is_true()), + RangeInclusion::RightExclusive => lhs + .lt(Span::unknown(), &rhs.to) + .map_or(false, |v| v.is_true()), + } + } else { + lhs.lte(Span::unknown(), &rhs.from) + .map_or(false, |v| v.is_true()) + && match rhs.inclusion { + RangeInclusion::Inclusive => lhs + .gte(Span::unknown(), &rhs.to) + .map_or(false, |v| v.is_true()), + RangeInclusion::RightExclusive => lhs + .gt(Span::unknown(), &rhs.to) + .map_or(false, |v| v.is_true()), + } + }, + span, }), (Value::String { val: lhs, .. }, Value::String { val: rhs, .. }) => Ok(Value::Bool { diff --git a/src/tests.rs b/src/tests.rs index 5d628b22b0..9acb6913d0 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -590,10 +590,15 @@ fn non_string_in_string() -> TestResult { } #[test] -fn int_in_range() -> TestResult { +fn int_in_inc_range() -> TestResult { run_test(r#"1 in -4..9.42"#, "true") } +#[test] +fn int_in_dec_range() -> TestResult { + run_test(r#"1 in 9.42..-4"#, "true") +} + #[test] fn int_in_exclusive_range() -> TestResult { run_test(r#"3 in 0..<3"#, "false")