2023-07-13 18:12:20 +02:00
|
|
|
use nu_test_support::nu;
|
2022-06-24 23:55:25 +02:00
|
|
|
|
|
|
|
#[test]
|
2023-04-20 19:44:31 +02:00
|
|
|
fn let_name_builtin_var() {
|
2023-07-12 19:33:25 +02:00
|
|
|
let actual = nu!("let in = 3");
|
2022-06-24 23:55:25 +02:00
|
|
|
|
|
|
|
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() {
|
2023-07-12 19:33:25 +02:00
|
|
|
let actual = nu!("let i = 3; $i = 4");
|
2022-11-11 07:51:08 +01:00
|
|
|
|
|
|
|
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() {
|
2023-07-12 19:33:25 +02:00
|
|
|
let actual = nu!(r#"let x = "hello world" | str length; print $x"#);
|
2023-07-03 07:45:10 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "11");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn let_pipeline_allows_in() {
|
2023-07-12 19:33:25 +02:00
|
|
|
let actual =
|
|
|
|
nu!(r#"def foo [] { let x = $in | str length; print ($x + 10) }; "hello world" | foo"#);
|
2023-07-03 07:45:10 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "21");
|
|
|
|
}
|
|
|
|
|
2023-07-11 20:36:34 +02:00
|
|
|
#[test]
|
|
|
|
fn mut_takes_pipeline() {
|
2023-07-12 19:33:25 +02:00
|
|
|
let actual = nu!(r#"mut x = "hello world" | str length; print $x"#);
|
2023-07-11 20:36:34 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, "11");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn mut_pipeline_allows_in() {
|
2023-07-12 19:33:25 +02:00
|
|
|
let actual =
|
|
|
|
nu!(r#"def foo [] { mut x = $in | str length; print ($x + 10) }; "hello world" | foo"#);
|
2023-07-11 20:36:34 +02:00
|
|
|
|
|
|
|
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-07-12 19:33:25 +02:00
|
|
|
let actual = nu!(r#"let x = nu --testbin outcome_err "aa"; echo fail"#);
|
2023-02-22 18:35:09 +01:00
|
|
|
|
|
|
|
assert!(!actual.out.contains("fail"));
|
|
|
|
}
|