2020-06-19 23:20:25 +00:00
|
|
|
mod avg;
|
2020-06-18 21:37:18 +00:00
|
|
|
mod median;
|
|
|
|
|
2020-04-18 01:50:58 +00:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn one_arg() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "1");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn add() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1 + 1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "2");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn add_compount() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1 + 2 + 2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "5");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn precedence_of_operators() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1 + 2 * 2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "5");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn precedence_of_operators2() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1 + 2 * 2 + 1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "6");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn division_of_ints() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 4 / 2
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "2");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn division_of_ints2() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1 / 4
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "0.25");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 20:50:43 +00:00
|
|
|
#[test]
|
|
|
|
fn error_zero_division_int_int() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1 / 0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn error_zero_division_decimal_int() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1.0 / 0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn error_zero_division_int_decimal() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1 / 0.0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn error_zero_division_decimal_decimal() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1.0 / 0.0
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("division by zero"));
|
|
|
|
}
|
|
|
|
|
2020-06-11 17:17:08 +00:00
|
|
|
#[test]
|
|
|
|
fn proper_precedence_history() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 2 / 2 / 2 + 1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1.5");
|
|
|
|
}
|
|
|
|
|
2020-04-18 01:50:58 +00:00
|
|
|
#[test]
|
|
|
|
fn parens_precedence() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 4 * (6 - 3)
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "12");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 01:44:49 +00:00
|
|
|
#[test]
|
|
|
|
fn duration_math() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1w + 1d
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-07-10 21:06:52 +00:00
|
|
|
assert_eq!(actual.out, "8d");
|
2020-07-10 17:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn duration_math_with_nanoseconds() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1w + 10ns
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-07-10 21:06:52 +00:00
|
|
|
assert_eq!(actual.out, "7d 10ns");
|
2020-07-10 17:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn duration_math_with_negative() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 1d - 1w
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-07-10 21:06:52 +00:00
|
|
|
assert_eq!(actual.out, "-6d");
|
2020-05-11 01:44:49 +00:00
|
|
|
}
|
|
|
|
|
2020-05-12 03:58:16 +00:00
|
|
|
#[test]
|
|
|
|
fn it_math() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
echo 1020 | = $it + 10
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1030");
|
|
|
|
}
|
|
|
|
|
2020-04-18 01:50:58 +00:00
|
|
|
#[test]
|
|
|
|
fn compound_comparison() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 4 > 3 && 2 > 1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "true");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compound_comparison2() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
|
|
|
= 4 < 3 || 2 > 1
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, "true");
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compound_where() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
2020-05-04 08:44:33 +00:00
|
|
|
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where a == 2 && b == 1 | to json
|
2020-04-18 01:50:58 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, r#"{"a":2,"b":1}"#);
|
2020-04-18 01:50:58 +00:00
|
|
|
}
|
2020-04-18 18:39:06 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn compound_where_paren() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: "tests/fixtures/formats", pipeline(
|
|
|
|
r#"
|
2020-05-04 08:44:33 +00:00
|
|
|
echo '[{"a": 1, "b": 1}, {"a": 2, "b": 1}, {"a": 2, "b": 2}]' | from json | where (a == 2 && b == 1) || b == 2 | to json
|
2020-04-18 18:39:06 +00:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-07 11:03:43 +00:00
|
|
|
assert_eq!(actual.out, r#"[{"a":2,"b":1},{"a":2,"b":2}]"#);
|
2020-04-18 18:39:06 +00:00
|
|
|
}
|