mirror of
https://github.com/nushell/nushell.git
synced 2025-06-30 22:50:14 +02:00
### Description Fixes issue #15135 Result  Also this works with other commands: min, max, sum, product, avg... ### User-Facing Changes Error is returned, instead of console completely blocked and having to be killed I chose "Incorrect value", because commands accept inputs of range type, just cannot work with unbounded ranges. ### Tests + Formatting - ran cargo fmt, clippy - added tests
This commit is contained in:
@ -5,3 +5,10 @@ fn const_abs() {
|
||||
let actual = nu!("const ABS = -5.5 | math abs; $ABS");
|
||||
assert_eq!(actual.out, "5.5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_abs_range() {
|
||||
let actual = nu!("0..5 | math abs");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
@ -21,6 +21,20 @@ fn can_average_bytes() {
|
||||
assert_eq!(actual.out, "34985870");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_average_range() {
|
||||
let actual = nu!("0..5 | math avg");
|
||||
|
||||
assert_eq!(actual.out, "2.5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_average_infinite_range() {
|
||||
let actual = nu!("0.. | math avg");
|
||||
|
||||
assert!(actual.err.contains("nu::shell::incorrect_value"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn const_avg() {
|
||||
let actual = nu!("const AVG = [1 3 5] | math avg; $AVG");
|
||||
|
@ -5,3 +5,10 @@ fn const_ceil() {
|
||||
let actual = nu!("const CEIL = 1.5 | math ceil; $CEIL");
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_ceil_range() {
|
||||
let actual = nu!("0..5 | math ceil");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
@ -5,3 +5,10 @@ fn const_floor() {
|
||||
let actual = nu!("const FLOOR = 15.5 | math floor; $FLOOR");
|
||||
assert_eq!(actual.out, "15");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_floor_range() {
|
||||
let actual = nu!("0.. | math floor");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
@ -5,3 +5,10 @@ fn const_log() {
|
||||
let actual = nu!("const LOG = 16 | math log 2; $LOG");
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_log_range() {
|
||||
let actual = nu!("0.. | math log 2");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
@ -5,3 +5,10 @@ fn const_max() {
|
||||
let actual = nu!("const MAX = [1 3 5] | math max; $MAX");
|
||||
assert_eq!(actual.out, "5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_max_infinite_range() {
|
||||
let actual = nu!("0.. | math max");
|
||||
|
||||
assert!(actual.err.contains("nu::shell::incorrect_value"));
|
||||
}
|
||||
|
@ -41,3 +41,10 @@ fn const_median() {
|
||||
let actual = nu!("const MEDIAN = [1 3 5] | math median; $MEDIAN");
|
||||
assert_eq!(actual.out, "3");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_median_infinite_range() {
|
||||
let actual = nu!("0.. | math median");
|
||||
|
||||
assert!(actual.err.contains("nu::shell::incorrect_value"));
|
||||
}
|
||||
|
@ -5,3 +5,10 @@ fn const_min() {
|
||||
let actual = nu!("const MIN = [1 3 5] | math min; $MIN");
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_min_infinite_range() {
|
||||
let actual = nu!("0.. | math min");
|
||||
|
||||
assert!(actual.err.contains("nu::shell::incorrect_value"));
|
||||
}
|
||||
|
@ -5,3 +5,10 @@ fn const_avg() {
|
||||
let actual = nu!("const MODE = [1 3 3 5] | math mode; $MODE");
|
||||
assert_eq!(actual.out, "╭───┬───╮│ 0 │ 3 │╰───┴───╯");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_mode_range() {
|
||||
let actual = nu!("0..5 | math mode");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
@ -5,3 +5,10 @@ fn const_product() {
|
||||
let actual = nu!("const PROD = [1 3 5] | math product; $PROD");
|
||||
assert_eq!(actual.out, "15");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_product_infinite_range() {
|
||||
let actual = nu!("0.. | math product");
|
||||
|
||||
assert!(actual.err.contains("nu::shell::incorrect_value"));
|
||||
}
|
||||
|
@ -40,3 +40,10 @@ fn const_round() {
|
||||
let actual = nu!("const ROUND = 18.345 | math round; $ROUND");
|
||||
assert_eq!(actual.out, "18");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_round_infinite_range() {
|
||||
let actual = nu!("0..5 | math round");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
@ -26,3 +26,10 @@ fn const_sqrt() {
|
||||
let actual = nu!("const SQRT = 4 | math sqrt; $SQRT");
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_sqrt_range() {
|
||||
let actual = nu!("0..5 | math sqrt");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
@ -5,3 +5,10 @@ fn const_avg() {
|
||||
let actual = nu!("const SDEV = [1 2] | math stddev; $SDEV");
|
||||
assert_eq!(actual.out, "0.5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_stddev_range() {
|
||||
let actual = nu!("0..5 | math stddev");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
@ -81,3 +81,10 @@ fn const_sum() {
|
||||
let actual = nu!("const SUM = [1 3] | math sum; $SUM");
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_sum_infinite_range() {
|
||||
let actual = nu!("0.. | math sum");
|
||||
|
||||
assert!(actual.err.contains("nu::shell::incorrect_value"));
|
||||
}
|
||||
|
@ -5,3 +5,10 @@ fn const_variance() {
|
||||
let actual = nu!("const VAR = [1 2 3 4 5] | math variance; $VAR");
|
||||
assert_eq!(actual.out, "2");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cannot_variance_range() {
|
||||
let actual = nu!("0..5 | math variance");
|
||||
|
||||
assert!(actual.err.contains("nu::parser::input_type_mismatch"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user