Remove interpretation of Primitive::Nothing as the number 0. (#1836)

This commit is contained in:
Jason Gedge 2020-05-18 15:18:46 -04:00 committed by GitHub
parent 0743b69ad5
commit 6efabef8d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 6 additions and 18 deletions

View File

@ -153,13 +153,7 @@ 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, Nothing) => CompareValues::Ints(BigInt::from(0), 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()),
(Nothing, Nothing) => CompareValues::Booleans(true, true),
(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()),

View File

@ -26,10 +26,6 @@ impl ExtractType for bool {
value: UntaggedValue::Primitive(Primitive::Boolean(b)),
..
} => Ok(*b),
Value {
value: UntaggedValue::Primitive(Primitive::Nothing),
..
} => Ok(false),
other => Err(ShellError::type_error("Boolean", other.spanned_type_name())),
}
}

View File

@ -33,7 +33,7 @@ fn cal_friday_the_thirteenths_in_2015() {
let actual = nu!(
cwd: ".", pipeline(
r#"
cal --full-year 2015 | where friday == 13 | count
cal --full-year 2015 | get friday | compact | where $it == 13 | count
"#
));

View File

@ -14,7 +14,7 @@ fn filters_by_unit_size_comparison() {
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"#
r#"echo '[{"foo": 3}, {"foo": null}, {"foo": 4}]' | from json | get foo | compact | where $it > 1 | sum | echo $it"#
);
assert_eq!(actual.out, "7");

View File

@ -105,7 +105,6 @@ impl num_traits::Zero for Primitive {
Primitive::Int(int) => int.is_zero(),
Primitive::Decimal(decimal) => decimal.is_zero(),
Primitive::Bytes(size) => size.is_zero(),
Primitive::Nothing => true,
_ => false,
}
}

View File

@ -38,7 +38,7 @@ macro_rules! nu {
});
let mut paths = $crate::shell_os_paths();
paths.push(test_bins);
paths.insert(0, test_bins);
let paths_joined = match std::env::join_paths(paths.iter()) {
Ok(all) => all,

View File

@ -17,7 +17,6 @@ impl Average {
pub fn average(&mut self, value: Value) -> Result<(), ShellError> {
match &value.value {
UntaggedValue::Primitive(Primitive::Nothing) => Ok(()),
UntaggedValue::Primitive(Primitive::Int(i)) => match &self.total {
Some(Value {
value: UntaggedValue::Primitive(Primitive::Int(j)),

View File

@ -25,6 +25,7 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() {
| get name
| ^echo $it
| nu --testbin chop
| lines
| nth 3
| echo $it
"#
@ -89,8 +90,7 @@ fn invocation_handles_dot() {
r#"
echo $(open nu_times.csv)
| get name
| ^echo $it
| nu --testbin chop
| nu --testbin chop $it
| nth 3
| echo $it
"#