2022-06-24 23:55:25 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
2023-04-20 19:44:31 +02:00
|
|
|
fn let_name_builtin_var() {
|
2022-06-24 23:55:25 +02:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
let in = 3
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual
|
|
|
|
.err
|
|
|
|
.contains("'in' is the name of a builtin Nushell variable"));
|
|
|
|
}
|
2022-11-11 07:51:08 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn let_doesnt_mutate() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
let i = 3; $i = 4
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.err.contains("immutable"));
|
|
|
|
}
|
2023-02-22 18:35:09 +01:00
|
|
|
|
2023-07-03 07:45:10 +02:00
|
|
|
#[test]
|
|
|
|
fn let_takes_pipeline() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
let x = "hello world" | str length; print $x
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "11");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn let_pipeline_allows_in() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
def foo [] { let x = $in | str length; print ($x + 10) }; "hello world" | foo
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "21");
|
|
|
|
}
|
|
|
|
|
2023-07-11 20:36:34 +02:00
|
|
|
#[test]
|
|
|
|
fn mut_takes_pipeline() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
mut x = "hello world" | str length; print $x
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "11");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mut_pipeline_allows_in() {
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".", pipeline(
|
|
|
|
r#"
|
|
|
|
def foo [] { mut x = $in | str length; print ($x + 10) }; "hello world" | foo
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "21");
|
|
|
|
}
|
|
|
|
|
2023-07-03 07:45:10 +02:00
|
|
|
#[ignore]
|
2023-02-22 18:35:09 +01:00
|
|
|
#[test]
|
|
|
|
fn let_with_external_failed() {
|
2023-07-03 07:45:10 +02:00
|
|
|
// FIXME: this test hasn't run successfully for a long time. We should
|
|
|
|
// bring it back to life at some point.
|
2023-02-22 18:35:09 +01:00
|
|
|
let actual = nu!(
|
|
|
|
cwd: ".",
|
|
|
|
pipeline(r#"let x = nu --testbin outcome_err "aa"; echo fail"#)
|
|
|
|
);
|
|
|
|
|
|
|
|
assert!(!actual.out.contains("fail"));
|
|
|
|
}
|