mirror of
https://github.com/nushell/nushell.git
synced 2025-08-19 09:02:25 +02:00
Allow parse-time evaluation of calls, pipelines and subexpressions (#9499)
Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
This commit is contained in:
@@ -108,12 +108,30 @@ fn const_nothing() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn const_unsupported() {
|
||||
let inp = &["const x = ('abc' | str length)"];
|
||||
fn const_subexpression_supported() {
|
||||
let inp = &["const x = ('spam')", "$x"];
|
||||
|
||||
let actual = nu!(&inp.join("; "));
|
||||
|
||||
assert!(actual.err.contains("not_a_constant"));
|
||||
assert_eq!(actual.out, "spam");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn const_command_supported() {
|
||||
let inp = &["const x = ('spam' | str length)", "$x"];
|
||||
|
||||
let actual = nu!(&inp.join("; "));
|
||||
|
||||
assert_eq!(actual.out, "4");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn const_command_unsupported() {
|
||||
let inp = &["const x = (loop { break })"];
|
||||
|
||||
let actual = nu!(&inp.join("; "));
|
||||
|
||||
assert!(actual.err.contains("not_a_const_command"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -125,6 +143,12 @@ fn const_in_scope() {
|
||||
assert_eq!(actual.out, "x");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn not_a_const_help() {
|
||||
let actual = nu!("const x = ('abc' | str length -h)");
|
||||
assert!(actual.err.contains("not_a_const_help"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn complex_const_export() {
|
||||
let inp = &[MODULE_SETUP, "use spam", "$spam.X"];
|
||||
@@ -250,3 +274,22 @@ fn complex_const_overlay_use_hide() {
|
||||
let actual = nu!(&inp.join("; "));
|
||||
assert!(actual.err.contains("nu::parser::variable_not_found"));
|
||||
}
|
||||
|
||||
// const implementations of commands without dedicated tests
|
||||
#[test]
|
||||
fn describe_const() {
|
||||
let actual = nu!("const x = ('abc' | describe); $x");
|
||||
assert_eq!(actual.out, "string");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ignore_const() {
|
||||
let actual = nu!("const x = (echo spam | ignore); $x == null");
|
||||
assert_eq!(actual.out, "true");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn version_const() {
|
||||
let actual = nu!("const x = (version); $x");
|
||||
assert!(actual.err.is_empty());
|
||||
}
|
||||
|
Reference in New Issue
Block a user