2020-06-20 01:20:25 +02:00
|
|
|
mod avg;
|
2020-06-18 23:37:18 +02:00
|
|
|
mod median;
|
2021-03-31 08:01:39 +02:00
|
|
|
mod round;
|
2021-04-01 23:26:05 +02:00
|
|
|
mod sqrt;
|
2020-07-18 06:11:19 +02:00
|
|
|
mod sum;
|
2020-06-18 23:37:18 +02:00
|
|
|
|
2020-04-18 03:50:58 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn one_arg() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "1");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn add() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1 + 1
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "2");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-01-02 05:24:32 +01:00
|
|
|
fn add_compound() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1 + 2 + 2
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "5");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn precedence_of_operators() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1 + 2 * 2
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "5");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn precedence_of_operators2() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1 + 2 * 2 + 1
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "6");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
2022-03-25 04:23:08 +01:00
|
|
|
#[test]
|
|
|
|
fn precedence_of_operators3() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-03-25 04:23:08 +01:00
|
|
|
r#"
|
|
|
|
5 - 5 * 10 + 5
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "-40");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn precedence_of_operators4() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-03-25 04:23:08 +01:00
|
|
|
r#"
|
|
|
|
5 - (5 * 10) + 5
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "-40");
|
|
|
|
}
|
|
|
|
|
2020-04-18 03:50:58 +02:00
|
|
|
#[test]
|
|
|
|
fn division_of_ints() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
4 / 2
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "2");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn division_of_ints2() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1 / 4
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "0.25");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
2020-06-21 22:50:43 +02:00
|
|
|
#[test]
|
|
|
|
fn error_zero_division_int_int() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-21 22:50:43 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1 / 0
|
2020-06-21 22:50:43 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-09-13 23:53:55 +02:00
|
|
|
fn error_zero_division_float_int() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-21 22:50:43 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1.0 / 0
|
2020-06-21 22:50:43 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-09-13 23:53:55 +02:00
|
|
|
fn error_zero_division_int_float() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-21 22:50:43 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1 / 0.0
|
2020-06-21 22:50:43 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-09-13 23:53:55 +02:00
|
|
|
fn error_zero_division_float_float() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-21 22:50:43 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1.0 / 0.0
|
2020-06-21 22:50:43 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
2022-06-13 12:54:47 +02:00
|
|
|
#[test]
|
|
|
|
fn floor_division_of_ints() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-06-13 12:54:47 +02:00
|
|
|
r#"
|
|
|
|
5 // 2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "2");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn floor_division_of_ints2() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-06-13 12:54:47 +02:00
|
|
|
r#"
|
|
|
|
-3 // 2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "-2");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn floor_division_of_floats() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-06-13 12:54:47 +02:00
|
|
|
r#"
|
|
|
|
-3.0 // 2.0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "-2");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn error_zero_floor_division_int_int() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-06-13 12:54:47 +02:00
|
|
|
r#"
|
|
|
|
1 // 0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-09-13 23:53:55 +02:00
|
|
|
fn error_zero_floor_division_float_int() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-06-13 12:54:47 +02:00
|
|
|
r#"
|
|
|
|
1.0 // 0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-09-13 23:53:55 +02:00
|
|
|
fn error_zero_floor_division_int_float() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-06-13 12:54:47 +02:00
|
|
|
r#"
|
|
|
|
1 // 0.0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2023-09-13 23:53:55 +02:00
|
|
|
fn error_zero_floor_division_float_float() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-06-13 12:54:47 +02:00
|
|
|
r#"
|
|
|
|
1.0 // 0.0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
2020-06-11 19:17:08 +02:00
|
|
|
#[test]
|
|
|
|
fn proper_precedence_history() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-11 19:17:08 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
2 / 2 / 2 + 1
|
2020-06-11 19:17:08 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1.5");
|
|
|
|
}
|
|
|
|
|
2020-04-18 03:50:58 +02:00
|
|
|
#[test]
|
|
|
|
fn parens_precedence() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
4 * (6 - 3)
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "12");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
2020-09-07 02:12:55 +02:00
|
|
|
#[test]
|
|
|
|
fn modulo() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-09-07 02:12:55 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
9 mod 2
|
2020-09-07 02:12:55 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1");
|
|
|
|
}
|
|
|
|
|
2022-09-29 00:07:50 +02:00
|
|
|
#[test]
|
|
|
|
fn unit_multiplication_math() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-09-29 00:07:50 +02:00
|
|
|
r#"
|
|
|
|
1mb * 2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1.9 MiB");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unit_multiplication_float_math() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-09-29 00:07:50 +02:00
|
|
|
r#"
|
|
|
|
1mb * 1.2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1.1 MiB");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unit_float_floor_division_math() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-09-29 00:07:50 +02:00
|
|
|
r#"
|
|
|
|
1mb // 3.0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "325.5 KiB");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unit_division_math() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-09-29 00:07:50 +02:00
|
|
|
r#"
|
|
|
|
1mb / 4
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "244.1 KiB");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn unit_float_division_math() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-09-29 00:07:50 +02:00
|
|
|
r#"
|
|
|
|
1mb / 3.1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "315.0 KiB");
|
|
|
|
}
|
|
|
|
|
2020-05-11 03:44:49 +02:00
|
|
|
#[test]
|
|
|
|
fn duration_math() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-05-11 03:44:49 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1wk + 1day
|
2020-05-11 03:44:49 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-07-26 15:05:37 +02:00
|
|
|
assert_eq!(actual.out, "1wk 1day");
|
2020-07-10 19:48:11 +02:00
|
|
|
}
|
|
|
|
|
2021-04-03 10:06:13 +02:00
|
|
|
#[test]
|
|
|
|
fn duration_decimal_math() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2021-04-03 10:06:13 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
5.5day + 0.5day
|
2021-04-03 10:06:13 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2021-04-04 20:19:33 +02:00
|
|
|
assert_eq!(actual.out, "6day");
|
2021-04-03 10:06:13 +02:00
|
|
|
}
|
|
|
|
|
2020-07-10 19:48:11 +02:00
|
|
|
#[test]
|
|
|
|
fn duration_math_with_nanoseconds() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-07-10 19:48:11 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1wk + 10ns
|
2020-07-10 19:48:11 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-07-26 15:05:37 +02:00
|
|
|
assert_eq!(actual.out, "1wk 10ns");
|
2020-07-10 19:48:11 +02:00
|
|
|
}
|
|
|
|
|
2021-04-03 10:06:13 +02:00
|
|
|
#[test]
|
|
|
|
fn duration_decimal_math_with_nanoseconds() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2021-04-03 10:06:13 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1.5wk + 10ns
|
2021-04-03 10:06:13 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-07-26 15:05:37 +02:00
|
|
|
assert_eq!(actual.out, "1wk 3day 10ns");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn duration_decimal_math_with_all_units() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-07-26 15:05:37 +02:00
|
|
|
r#"
|
2022-09-25 22:55:13 +02:00
|
|
|
1wk + 3day + 8hr + 10min + 16sec + 121ms + 11us + 12ns
|
2022-07-26 15:05:37 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-09-25 22:55:13 +02:00
|
|
|
assert_eq!(actual.out, "1wk 3day 8hr 10min 16sec 121ms 11µs 12ns");
|
2021-04-03 10:06:13 +02:00
|
|
|
}
|
|
|
|
|
2022-09-29 20:24:17 +02:00
|
|
|
#[test]
|
|
|
|
fn duration_decimal_dans_test() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-09-29 20:24:17 +02:00
|
|
|
r#"
|
|
|
|
3.14sec
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "3sec 140ms");
|
|
|
|
}
|
|
|
|
|
2020-07-10 19:48:11 +02:00
|
|
|
#[test]
|
|
|
|
fn duration_math_with_negative() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-07-10 19:48:11 +02:00
|
|
|
r#"
|
2021-05-12 03:01:48 +02:00
|
|
|
1day - 1wk
|
2020-07-10 19:48:11 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-08-15 21:03:28 +02:00
|
|
|
assert_eq!(actual.out, "-6day");
|
2020-05-11 03:44:49 +02:00
|
|
|
}
|
|
|
|
|
2021-06-23 05:44:14 +02:00
|
|
|
#[test]
|
2020-04-18 03:50:58 +02:00
|
|
|
fn compound_comparison() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2022-12-08 00:02:11 +01:00
|
|
|
4 > 3 and 2 > 1
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "true");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compound_comparison2() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2022-12-08 00:02:11 +01:00
|
|
|
4 < 3 or 2 > 1
|
2020-04-18 03:50:58 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "true");
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compound_where() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 03:50:58 +02:00
|
|
|
r#"
|
2022-12-08 00:02:11 +01:00
|
|
|
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where a == 2 and b == 1 | to json -r
|
2022-02-04 03:01:45 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-02-04 22:42:18 +01:00
|
|
|
assert_eq!(actual.out, r#"[{"a": 2,"b": 1}]"#);
|
2020-04-18 03:50:58 +02:00
|
|
|
}
|
2020-04-18 20:39:06 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compound_where_paren() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-04-18 20:39:06 +02:00
|
|
|
r#"
|
2022-12-08 00:02:11 +01:00
|
|
|
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where ($it.a == 2 and $it.b == 1) or $it.b == 2 | to json -r
|
2022-02-04 03:01:45 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-02-04 22:42:18 +01:00
|
|
|
assert_eq!(actual.out, r#"[{"a": 2,"b": 1},{"a": 2,"b": 2}]"#);
|
2020-04-18 20:39:06 +02:00
|
|
|
}
|
2022-10-20 12:28:18 +02:00
|
|
|
|
2023-02-09 19:52:10 +01:00
|
|
|
// TODO: these ++ tests are not really testing *math* functionality, maybe find another place for them
|
|
|
|
|
2022-10-20 12:28:18 +02:00
|
|
|
#[test]
|
|
|
|
fn adding_lists() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-10-20 12:28:18 +02:00
|
|
|
r#"
|
|
|
|
[1 3] ++ [5 6] | to nuon
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[1, 3, 5, 6]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn adding_list_and_value() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-10-20 12:28:18 +02:00
|
|
|
r#"
|
|
|
|
[1 3] ++ 5 | to nuon
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[1, 3, 5]");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn adding_value_and_list() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-10-20 12:28:18 +02:00
|
|
|
r#"
|
|
|
|
1 ++ [3 5] | to nuon
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[1, 3, 5]");
|
|
|
|
}
|
2022-12-01 00:21:59 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn adding_tables() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2022-12-01 00:21:59 +01:00
|
|
|
r#"
|
2022-12-01 00:48:02 +01:00
|
|
|
[[a b]; [1 2]] ++ [[c d]; [10 11]] | to nuon
|
2022-12-01 00:21:59 +01:00
|
|
|
"#
|
|
|
|
));
|
2022-12-01 00:48:02 +01:00
|
|
|
assert_eq!(actual.out, "[{a: 1, b: 2}, {c: 10, d: 11}]");
|
2022-12-01 00:21:59 +01:00
|
|
|
}
|
2023-02-09 19:52:10 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn append_strings() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2023-02-09 19:52:10 +01:00
|
|
|
r#"
|
|
|
|
"foo" ++ "bar"
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
assert_eq!(actual.out, "foobar");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn append_binary_values() {
|
2023-07-17 18:43:51 +02:00
|
|
|
let actual = nu!(pipeline(
|
2023-02-09 19:52:10 +01:00
|
|
|
r#"
|
|
|
|
0x[01 02] ++ 0x[03 04] | to nuon
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
assert_eq!(actual.out, "0x[01020304]");
|
|
|
|
}
|