nushell/crates/nu-command/tests/commands/slice.rs
Stefan Holderbach 4dcaf2a201
Rename/deprecate range to slice (#14825)
# Description
As the `range` command has an ambiguous name (does it construct a range
type?, does it iterate a range like `seq`) replace it with a more
descriptive verb of what it does: `slice`

Closes #14130
# User-Facing Changes
`range` is now deprecated and replaced in whole by `slice` with the same
behavior.
`range` will be removed in `0.103.0`

# Tests + Formatting
Tests have been updated to use `slice`

# After submitting

- [ ] prepare PR for `nu_scripts` (several usages of `range` to be
fixed)
- [ ] update documentation usages of `range` after release
2025-01-17 06:21:32 -06:00

69 lines
1.5 KiB
Rust

use nu_test_support::fs::Stub::EmptyFile;
use nu_test_support::playground::Playground;
use nu_test_support::{nu, pipeline};
#[test]
fn selects_a_row() {
Playground::setup("slice_test_1", |dirs, sandbox| {
sandbox.with_files(&[EmptyFile("notes.txt"), EmptyFile("tests.txt")]);
let actual = nu!(
cwd: dirs.test(), pipeline(
"
ls
| sort-by name
| slice 0..0
| get name.0
"
));
assert_eq!(actual.out, "notes.txt");
});
}
#[test]
fn selects_some_rows() {
Playground::setup("slice_test_2", |dirs, sandbox| {
sandbox.with_files(&[
EmptyFile("notes.txt"),
EmptyFile("tests.txt"),
EmptyFile("persons.txt"),
]);
let actual = nu!(
cwd: dirs.test(), pipeline(
"
ls
| get name
| slice 1..2
| length
"
));
assert_eq!(actual.out, "2");
});
}
#[test]
fn negative_indices() {
Playground::setup("slice_test_negative_indices", |dirs, sandbox| {
sandbox.with_files(&[
EmptyFile("notes.txt"),
EmptyFile("tests.txt"),
EmptyFile("persons.txt"),
]);
let actual = nu!(
cwd: dirs.test(), pipeline(
"
ls
| get name
| slice (-1..)
| length
"
));
assert_eq!(actual.out, "1");
});
}