2023-07-12 17:07:20 +00:00
|
|
|
use nu_test_support::nu;
|
2023-04-08 18:52:37 +00:00
|
|
|
use pretty_assertions::assert_eq;
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_bool() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = false", "$x"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "false");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_int() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = 10", "$x"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "10");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_float() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = 1.234", "$x"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "1.234");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_binary() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = 0x[12]", "$x"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert!(actual.out.contains("12"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_datetime() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = 2021-02-27T13:55:40+00:00", "$x"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert!(actual.out.contains("Sat, 27 Feb 2021 13:55:40"));
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_list() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = [ a b c ]", "$x | describe"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "list<string>");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_record() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = { a: 10, b: 20, c: 30 }", "$x | describe"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "record<a: int, b: int, c: int>");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_table() {
|
|
|
|
let inp = &[
|
2023-07-12 17:07:20 +00:00
|
|
|
"const x = [[a b c]; [10 20 30] [100 200 300]]",
|
|
|
|
"$x | describe",
|
2022-12-21 22:21:03 +00:00
|
|
|
];
|
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "table<a: int, b: int, c: int>");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_string() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &[r#"const x = "abc""#, "$x"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "abc");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_nothing() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = $nothing", "$x | describe"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "nothing");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_unsupported() {
|
2023-07-12 17:07:20 +00:00
|
|
|
let inp = &["const x = ('abc' | str length)"];
|
2022-12-21 22:21:03 +00:00
|
|
|
|
2023-07-12 17:07:20 +00:00
|
|
|
let actual = nu!(&inp.join("; "));
|
2022-12-21 22:21:03 +00:00
|
|
|
|
|
|
|
assert!(actual.err.contains("not_a_constant"));
|
|
|
|
}
|
2023-07-13 21:02:05 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn const_in_scope() {
|
|
|
|
let inp = &["do { const x = 'x'; $x }"];
|
|
|
|
|
|
|
|
let actual = nu!(&inp.join("; "));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "x");
|
|
|
|
}
|