nushell/crates/nu-command/tests/commands/drop.rs

96 lines
1.8 KiB
Rust
Raw Normal View History

use nu_test_support::{nu, pipeline};
#[test]
fn columns() {
let actual = nu!(pipeline(
"
echo [
[arepas, color];
[3, white]
[8, yellow]
[4, white]
2022-02-16 02:48:32 +01:00
] | drop column | columns | length
"
));
assert_eq!(actual.out, "1");
}
#[test]
fn drop_columns_positive_value() {
let actual = nu!("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!(pipeline(
"
echo [
[arepas, color];
[3, white]
[8, yellow]
[4, white]
] | drop column 3 | columns | is-empty
"
));
assert_eq!(actual.out, "true");
}
#[test]
fn rows() {
let actual = nu!(pipeline(
"
echo [
[arepas];
[3]
[8]
[4]
]
| drop 2
| get arepas
| math sum
"
));
assert_eq!(actual.out, "3");
}
#[test]
fn more_rows_than_table_has() {
let actual = nu!("[date] | drop 50 | length");
assert_eq!(actual.out, "0");
}
#[test]
fn nth_range_inclusive() {
let actual = nu!("echo 10..15 | drop nth (2..3) | to json --raw");
assert_eq!(actual.out, "[10,11,14,15]");
}
#[test]
fn nth_range_exclusive() {
let actual = nu!("echo 10..15 | drop nth (1..<3) | to json --raw");
assert_eq!(actual.out, "[10,13,14,15]");
}
#[test]
fn nth_missing_first_argument() {
let actual = nu!("echo 10..15 | drop nth \"\"");
2022-02-07 20:54:06 +01:00
assert!(actual.err.contains("int or range"));
}
#[test]
fn fail_on_non_iterator() {
let actual = nu!("1 | drop 50");
Input output checking (#9680) # Description This PR tights input/output type-checking a bit more. There are a lot of commands that don't have correct input/output types, so part of the effort is updating them. This PR now contains updates to commands that had wrong input/output signatures. It doesn't add examples for these new signatures, but that can be follow-up work. # User-Facing Changes BREAKING CHANGE BREAKING CHANGE This work enforces many more checks on pipeline type correctness than previous nushell versions. This strictness may uncover incompatibilities in existing scripts or shortcomings in the type information for internal commands. # Tests + Formatting <!-- Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect -A clippy::result_large_err` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass - `cargo run -- -c "use std testing; testing run-tests --path crates/nu-std"` to run the tests for the standard library > **Note** > from `nushell` you can also use the `toolkit` as follows > ```bash > use toolkit.nu # or use an `env_change` hook to activate it automatically > toolkit check pr > ``` --> # After Submitting <!-- If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date. -->
2023-07-14 05:20:35 +02:00
assert!(actual.err.contains("command doesn't support"));
}