add more tests for new $in behaviour
This commit is contained in:
parent
ba6a214bfa
commit
5272bca240
|
@ -439,3 +439,37 @@ fn no_duplicate_redirection() {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rstest::rstest]
|
||||||
|
#[case("let", "out>")]
|
||||||
|
#[case("let", "err>")]
|
||||||
|
#[case("let", "out+err>")]
|
||||||
|
#[case("mut", "out>")]
|
||||||
|
#[case("mut", "err>")]
|
||||||
|
#[case("mut", "out+err>")]
|
||||||
|
fn file_redirection_in_let_and_mut(#[case] keyword: &str, #[case] redir: &str) {
|
||||||
|
Playground::setup("file redirection in let and mut", |dirs, _| {
|
||||||
|
let actual = nu!(
|
||||||
|
cwd: dirs.test(),
|
||||||
|
format!("$env.BAZ = 'foo'; {keyword} v = nu --testbin echo_env_mixed out-err BAZ BAZ {redir} result.txt")
|
||||||
|
);
|
||||||
|
assert!(actual.status.success());
|
||||||
|
assert!(file_contents(dirs.test().join("result.txt")).contains("foo"));
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[rstest::rstest]
|
||||||
|
#[case("let", "err>|", 3)]
|
||||||
|
#[case("let", "out+err>|", 6)]
|
||||||
|
#[case("mut", "err>|", 3)]
|
||||||
|
#[case("mut", "out+err>|", 6)]
|
||||||
|
fn pipe_redirection_in_let_and_mut(
|
||||||
|
#[case] keyword: &str,
|
||||||
|
#[case] redir: &str,
|
||||||
|
#[case] length: usize,
|
||||||
|
) {
|
||||||
|
let actual = nu!(
|
||||||
|
format!("$env.BAZ = 'foo'; {keyword} v = nu --testbin echo_env_mixed out-err BAZ BAZ {redir} str length; $v")
|
||||||
|
);
|
||||||
|
assert_eq!(actual.out.len(), length);
|
||||||
|
}
|
||||||
|
|
|
@ -52,6 +52,21 @@ fn in_and_if_else() -> TestResult {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_with_closure() -> TestResult {
|
||||||
|
// Can use $in twice
|
||||||
|
run_test(r#"3 | do { let x = $in; let y = $in; $x + $y }"#, "6")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_with_custom_command() -> TestResult {
|
||||||
|
// Can use $in twice
|
||||||
|
run_test(
|
||||||
|
r#"def foo [] { let x = $in; let y = $in; $x + $y }; 3 | foo"#,
|
||||||
|
"6",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn help_works_with_missing_requirements() -> TestResult {
|
fn help_works_with_missing_requirements() -> TestResult {
|
||||||
run_test(r#"each --help | lines | length"#, "72")
|
run_test(r#"each --help | lines | length"#, "72")
|
||||||
|
|
|
@ -129,3 +129,16 @@ fn transpose_into_load_env() -> TestResult {
|
||||||
"10",
|
"10",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_variable_expression_correct_output_type() -> TestResult {
|
||||||
|
run_test(r#"def foo []: nothing -> string { 'foo' | $"($in)" }"#, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn in_variable_expression_wrong_output_type() -> TestResult {
|
||||||
|
fail_test(
|
||||||
|
r#"def foo []: nothing -> int { 'foo' | $"($in)" }"#,
|
||||||
|
"expected int",
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user