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