Remove default
list-diving behaviour
Why was that bad? Because it didn't allow to process, e.g. `null|list<null|string>` input and receive `list<null|string>`.
This commit is contained in:
parent
3d1145e759
commit
92e45768b2
|
@ -51,11 +51,11 @@ impl Command for Default {
|
|||
description:
|
||||
"Get the env value of `MY_ENV` with a default value 'abc' if not present",
|
||||
example: "$env | get --ignore-errors MY_ENV | default 'abc'",
|
||||
result: None, // Some(Value::test_string("abc")),
|
||||
result: Some(Value::test_string("abc")),
|
||||
},
|
||||
Example {
|
||||
description: "Replace the `null` value in a list",
|
||||
example: "[1, 2, null, 4] | default 3",
|
||||
example: "[1, 2, null, 4] | each { default 3 }",
|
||||
result: Some(Value::list(
|
||||
vec![
|
||||
Value::test_int(1),
|
||||
|
@ -113,15 +113,7 @@ fn default(
|
|||
} else if input.is_nothing() {
|
||||
Ok(value.into_pipeline_data())
|
||||
} else {
|
||||
input
|
||||
.map(
|
||||
move |item| match item {
|
||||
Value::Nothing { .. } => value.clone(),
|
||||
x => x,
|
||||
},
|
||||
engine_state.signals(),
|
||||
)
|
||||
.map(|x| x.set_metadata(metadata))
|
||||
Ok(input)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,3 +32,15 @@ fn default_after_empty_filter() {
|
|||
|
||||
assert_eq!(actual.out, "d");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn keeps_nulls_in_lists() {
|
||||
let actual = nu!(r#"[null, 2, 3] | default [] | to json -r"#);
|
||||
assert_eq!(actual.out, "[null,2,3]");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn replaces_null() {
|
||||
let actual = nu!(r#"null | default 1"#);
|
||||
assert_eq!(actual.out, "1");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user