Improve $in handling (#5137)

* Simplify in logic

* Add tests

* more tests, and fixes
This commit is contained in:
JT
2022-04-09 09:41:05 +12:00
committed by GitHub
parent 0892a16a3d
commit 97eb8492a3
5 changed files with 57 additions and 11 deletions

View File

@@ -340,3 +340,29 @@ fn default_value11() -> TestResult {
fn default_value12() -> TestResult {
fail_test(r#"def foo [--x:int = "a"] { $x }"#, "default value not int")
}
#[test]
fn loose_each() -> TestResult {
run_test(r#"[[1, 2, 3], [4, 5, 6]] | each { $in.1 } | math sum"#, "7")
}
#[test]
fn in_means_input() -> TestResult {
run_test(r#"def shl [] { $in * 2 }; 2 | shl"#, "4")
}
#[test]
fn in_iteration() -> TestResult {
run_test(
r#"[3, 4, 5] | each { echo $"hi ($in)" } | str collect"#,
"hi 3hi 4hi 5",
)
}
#[test]
fn reuseable_in() -> TestResult {
run_test(
r#"[1, 2, 3, 4] | take (($in | length) - 1) | math sum"#,
"6",
)
}