mirror of
https://github.com/nushell/nushell
synced 2024-11-15 09:27:08 +00:00
Fix numeric comparison with nothing (#1508)
This commit is contained in:
parent
ab5e24a0e7
commit
918822ae0d
2 changed files with 16 additions and 0 deletions
|
@ -180,6 +180,12 @@ fn coerce_compare_primitive(
|
|||
(Bytes(left), Decimal(right)) => {
|
||||
CompareValues::Decimals(BigDecimal::from(*left), right.clone())
|
||||
}
|
||||
(Bytes(left), Nothing) => CompareValues::Ints(BigInt::from(*left), BigInt::from(0)),
|
||||
(Nothing, Bytes(right)) => CompareValues::Ints(BigInt::from(0), BigInt::from(*right)),
|
||||
(Int(left), Nothing) => CompareValues::Ints(left.clone(), BigInt::from(0)),
|
||||
(Nothing, Int(right)) => CompareValues::Ints(BigInt::from(0), right.clone()),
|
||||
(Decimal(left), Nothing) => CompareValues::Decimals(left.clone(), BigDecimal::from(0.0)),
|
||||
(Nothing, Decimal(right)) => CompareValues::Decimals(BigDecimal::from(0.0), right.clone()),
|
||||
(String(left), String(right)) => CompareValues::String(left.clone(), right.clone()),
|
||||
(Line(left), String(right)) => CompareValues::String(left.clone(), right.clone()),
|
||||
(String(left), Line(right)) => CompareValues::String(left.clone(), right.clone()),
|
||||
|
|
|
@ -10,6 +10,16 @@ fn filters_by_unit_size_comparison() {
|
|||
assert_eq!(actual, "cargo_sample.toml");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn filters_with_nothing_comparison() {
|
||||
let actual = nu!(
|
||||
cwd: "tests/fixtures/formats",
|
||||
r#"echo '[{"foo": 3}, {"foo": null}, {"foo": 4}]' | from-json | where foo > 1 | get foo | sum | echo $it"#
|
||||
);
|
||||
|
||||
assert_eq!(actual, "7");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn binary_operator_comparisons() {
|
||||
let actual = nu!(
|
||||
|
|
Loading…
Reference in a new issue