Fix default duplicates column (#4452)

* Add test to ensure default not adding dup. columns

* Fix for default adding duplicate columns
This commit is contained in:
Andrew Barnes 2022-02-13 21:38:46 +11:00 committed by GitHub
parent e82ffc4dee
commit 77eb4c4188
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -67,9 +67,11 @@ fn default(
let mut found = false;
while idx < cols.len() {
if cols[idx] == column.item && matches!(vals[idx], Value::Nothing { .. }) {
vals[idx] = value.clone();
if cols[idx] == column.item {
found = true;
if matches!(vals[idx], Value::Nothing { .. }) {
vals[idx] = value.clone();
}
}
idx += 1;
}

View file

@ -232,6 +232,14 @@ fn length_for_rows() -> TestResult {
run_test(r#"[[name,age,grade]; [bill,20,a] [a b c]] | length"#, "2")
}
#[test]
fn length_defaulted_columns() -> TestResult {
run_test(
r#"echo [[name, age]; [test, 10]] | default age 11 | get 0 | columns | length"#,
"2",
)
}
#[test]
fn get_fuzzy() -> TestResult {
run_test("(ls | get -i foo) == $nothing", "true")