mirror of
https://github.com/nushell/nushell.git
synced 2024-11-26 18:33:50 +01:00
5afbfb5c2c
# Description This PR is just a minor development improvement. While working on another feature, I noticed that the root crate lists the super useful `pretty_assertions` in the root crate but doesn't use it in most tests. With this change `pretty_assertions::assert_eq!` is used instead of `core::assert_eq!` for better diffs when debugging the tests. I thought of adding the dependency to other crates but I decided not to since I didn't want a huge disruptive PR :)
105 lines
2.3 KiB
Rust
105 lines
2.3 KiB
Rust
use nu_test_support::{nu, pipeline};
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn const_bool() {
|
|
let inp = &[r#"const x = false"#, r#"$x"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert_eq!(actual.out, "false");
|
|
}
|
|
|
|
#[test]
|
|
fn const_int() {
|
|
let inp = &[r#"const x = 10"#, r#"$x"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert_eq!(actual.out, "10");
|
|
}
|
|
|
|
#[test]
|
|
fn const_float() {
|
|
let inp = &[r#"const x = 1.234"#, r#"$x"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert_eq!(actual.out, "1.234");
|
|
}
|
|
|
|
#[test]
|
|
fn const_binary() {
|
|
let inp = &[r#"const x = 0x[12]"#, r#"$x"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert!(actual.out.contains("12"));
|
|
}
|
|
|
|
#[test]
|
|
fn const_datetime() {
|
|
let inp = &[r#"const x = 2021-02-27T13:55:40+00:00"#, r#"$x"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert!(actual.out.contains("Sat, 27 Feb 2021 13:55:40"));
|
|
}
|
|
|
|
#[test]
|
|
fn const_list() {
|
|
let inp = &[r#"const x = [ a b c ]"#, r#"$x | describe"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert_eq!(actual.out, "list<string>");
|
|
}
|
|
|
|
#[test]
|
|
fn const_record() {
|
|
let inp = &[r#"const x = { a: 10, b: 20, c: 30 }"#, r#"$x | describe"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert_eq!(actual.out, "record<a: int, b: int, c: int>");
|
|
}
|
|
|
|
#[test]
|
|
fn const_table() {
|
|
let inp = &[
|
|
r#"const x = [[a b c]; [10 20 30] [100 200 300]]"#,
|
|
r#"$x | describe"#,
|
|
];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert_eq!(actual.out, "table<a: int, b: int, c: int>");
|
|
}
|
|
|
|
#[test]
|
|
fn const_string() {
|
|
let inp = &[r#"const x = "abc""#, r#"$x"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert_eq!(actual.out, "abc");
|
|
}
|
|
|
|
#[test]
|
|
fn const_nothing() {
|
|
let inp = &[r#"const x = $nothing"#, r#"$x | describe"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert_eq!(actual.out, "nothing");
|
|
}
|
|
|
|
#[test]
|
|
fn const_unsupported() {
|
|
let inp = &[r#"const x = ('abc' | str length)"#];
|
|
|
|
let actual = nu!(cwd: "tests/const_", pipeline(&inp.join("; ")));
|
|
|
|
assert!(actual.err.contains("not_a_constant"));
|
|
}
|