mirror of
https://github.com/nushell/nushell.git
synced 2024-12-22 23:23:12 +01:00
Default the values of named params (#695)
This commit is contained in:
parent
eab6b322bb
commit
3478f35330
@ -111,14 +111,18 @@ fn eval_call(
|
||||
}
|
||||
}
|
||||
|
||||
if !found && named.arg.is_none() {
|
||||
callee_stack.add_var(
|
||||
var_id,
|
||||
Value::Bool {
|
||||
val: false,
|
||||
span: call.head,
|
||||
},
|
||||
)
|
||||
if !found {
|
||||
if named.arg.is_none() {
|
||||
callee_stack.add_var(
|
||||
var_id,
|
||||
Value::Bool {
|
||||
val: false,
|
||||
span: call.head,
|
||||
},
|
||||
)
|
||||
} else {
|
||||
callee_stack.add_var(var_id, Value::Nothing { span: call.head })
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,3 +87,35 @@ fn earlier_errors() -> TestResult {
|
||||
"int",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_flags_are_nothing() -> TestResult {
|
||||
run_test(
|
||||
r#"def foo [--aaa(-a): int, --bbb(-b): int] { (if $aaa == $nothing { 10 } else { $aaa }) + (if $bbb == $nothing { 100 } else { $bbb }) }; foo"#,
|
||||
"110",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_flags_are_nothing2() -> TestResult {
|
||||
run_test(
|
||||
r#"def foo [--aaa(-a): int, --bbb(-b): int] { (if $aaa == $nothing { 10 } else { $aaa }) + (if $bbb == $nothing { 100 } else { $bbb }) }; foo -a 90"#,
|
||||
"190",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_flags_are_nothing3() -> TestResult {
|
||||
run_test(
|
||||
r#"def foo [--aaa(-a): int, --bbb(-b): int] { (if $aaa == $nothing { 10 } else { $aaa }) + (if $bbb == $nothing { 100 } else { $bbb }) }; foo -b 45"#,
|
||||
"55",
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn missing_flags_are_nothing4() -> TestResult {
|
||||
run_test(
|
||||
r#"def foo [--aaa(-a): int, --bbb(-b): int] { (if $aaa == $nothing { 10 } else { $aaa }) + (if $bbb == $nothing { 100 } else { $bbb }) }; foo -a 3 -b 10000"#,
|
||||
"10003",
|
||||
)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user