nu-command/filters: drop column check positive value (#6412)

This commit is contained in:
Herlon Aguiar 2022-08-25 18:03:18 +02:00 committed by GitHub
parent 7b502a4c7f
commit 918ec9daa8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -49,6 +49,13 @@ impl Command for DropColumn {
1
};
// Make columns to drop is positive
if columns_to_drop < 0 {
if let Some(expr) = call.positional_nth(0) {
return Err(ShellError::NeedsPositiveValue(expr.span));
}
}
dropcol(engine_state, span, input, columns_to_drop)
}

View File

@ -16,6 +16,17 @@ fn columns() {
assert_eq!(actual.out, "1");
}
#[test]
fn drop_columns_positive_value() {
let actual = nu!(
cwd: ".", pipeline(r#"
echo [[a, b];[1,2]] | drop column -1
"#)
);
assert!(actual.err.contains("use a positive value"));
}
#[test]
fn more_columns_than_table_has() {
let actual = nu!(