mirror of
https://github.com/nushell/nushell.git
synced 2025-08-09 14:45:56 +02:00
@ -86,7 +86,7 @@ fn scope_variable() -> TestResult {
|
||||
#[test]
|
||||
fn earlier_errors() -> TestResult {
|
||||
fail_test(
|
||||
r#"[1, "bob"] | each { $it + 3 } | each { $it / $it } | table"#,
|
||||
r#"[1, "bob"] | each { |it| $it + 3 } | each { |it| $it / $it } | table"#,
|
||||
"int",
|
||||
)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use crate::tests::{run_test, TestResult};
|
||||
#[test]
|
||||
fn better_block_types() -> TestResult {
|
||||
run_test(
|
||||
r#"([1, 2, 3] | each -n { $"($it.index) is ($it.item)" }).1"#,
|
||||
r#"([1, 2, 3] | each -n { |it| $"($it.index) is ($it.item)" }).1"#,
|
||||
"1 is 2",
|
||||
)
|
||||
}
|
||||
@ -11,14 +11,14 @@ fn better_block_types() -> TestResult {
|
||||
#[test]
|
||||
fn row_iteration() -> TestResult {
|
||||
run_test(
|
||||
"[[name, size]; [tj, 100], [rl, 200]] | each { $it.size * 8 } | get 1",
|
||||
"[[name, size]; [tj, 100], [rl, 200]] | each { |it| $it.size * 8 } | get 1",
|
||||
"1600",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn record_iteration() -> TestResult {
|
||||
run_test("([[name, level]; [aa, 100], [bb, 200]] | each { $it | each { |x| if $x.column == \"level\" { $x.value + 100 } else { $x.value } } }).level | get 1", "300")
|
||||
run_test("([[name, level]; [aa, 100], [bb, 200]] | each { |it| $it | each { |x| if $x.column == \"level\" { $x.value + 100 } else { $x.value } } }).level | get 1", "300")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -45,7 +45,7 @@ fn for_loops() -> TestResult {
|
||||
#[test]
|
||||
fn par_each() -> TestResult {
|
||||
run_test(
|
||||
r#"1..10 | par-each --numbered { ([[index, item]; [$it.index, ($it.item > 5)]]).0 } | where index == 4 | get item.0"#,
|
||||
r#"1..10 | par-each --numbered { |it| ([[index, item]; [$it.index, ($it.item > 5)]]).0 } | where index == 4 | get item.0"#,
|
||||
"false",
|
||||
)
|
||||
}
|
||||
|
@ -40,7 +40,7 @@ fn alias_recursion() -> TestResult {
|
||||
|
||||
#[test]
|
||||
fn block_param1() -> TestResult {
|
||||
run_test("[3] | each { $it + 10 } | get 0", "13")
|
||||
run_test("[3] | each { |it| $it + 10 } | get 0", "13")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -50,7 +50,7 @@ fn block_param2() -> TestResult {
|
||||
|
||||
#[test]
|
||||
fn block_param3_list_iteration() -> TestResult {
|
||||
run_test("[1,2,3] | each { $it + 10 } | get 1", "12")
|
||||
run_test("[1,2,3] | each { |it| $it + 10 } | get 1", "12")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -70,7 +70,7 @@ fn range_iteration2() -> TestResult {
|
||||
|
||||
#[test]
|
||||
fn simple_value_iteration() -> TestResult {
|
||||
run_test("4 | each { $it + 10 }", "14")
|
||||
run_test("4 | each { |it| $it + 10 }", "14")
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -116,7 +116,7 @@ fn bad_var_name() -> TestResult {
|
||||
#[test]
|
||||
fn long_flag() -> TestResult {
|
||||
run_test(
|
||||
r#"([a, b, c] | each --numbered { if $it.index == 1 { 100 } else { 0 } }).1"#,
|
||||
r#"([a, b, c] | each --numbered { |it| if $it.index == 1 { 100 } else { 0 } }).1"#,
|
||||
"100",
|
||||
)
|
||||
}
|
||||
@ -314,3 +314,18 @@ fn capture_row_condition() -> TestResult {
|
||||
fn proper_missing_param() -> TestResult {
|
||||
fail_test(r#"def foo [x y z w] { }; foo a b c"#, "missing w")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_arity_check1() -> TestResult {
|
||||
fail_test(r#"ls | each { 1 }"#, "expected 1 block parameter")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_arity_check2() -> TestResult {
|
||||
fail_test(r#"ls | reduce { 1 }"#, "expected 2 block parameters")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn block_arity_check3() -> TestResult {
|
||||
fail_test(r#"ls | each { |x, y| 1}"#, "expected 1 block parameter")
|
||||
}
|
||||
|
@ -7,13 +7,13 @@ fn build_string1() -> TestResult {
|
||||
|
||||
#[test]
|
||||
fn build_string2() -> TestResult {
|
||||
run_test("'nu' | each {build-string $it 'shell'}", "nushell")
|
||||
run_test("'nu' | each { |it| build-string $it 'shell'}", "nushell")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn build_string3() -> TestResult {
|
||||
run_test(
|
||||
"build-string 'nu' 'shell' | each {build-string $it ' rocks'}",
|
||||
"build-string 'nu' 'shell' | each { |it| build-string $it ' rocks'}",
|
||||
"nushell rocks",
|
||||
)
|
||||
}
|
||||
@ -21,7 +21,7 @@ fn build_string3() -> TestResult {
|
||||
#[test]
|
||||
fn build_string4() -> TestResult {
|
||||
run_test(
|
||||
"['sam','rick','pete'] | each { build-string $it ' is studying'} | get 2",
|
||||
"['sam','rick','pete'] | each { |it| build-string $it ' is studying'} | get 2",
|
||||
"pete is studying",
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user