2019-12-17 19:54:39 +01:00
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
2019-12-15 17:15:06 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn selects_a_row() {
|
|
|
|
Playground::setup("range_test_1", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[EmptyFile("notes.txt"), EmptyFile("tests.txt")]);
|
2019-12-15 17:15:06 +01:00
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2019-12-15 17:15:06 +01:00
|
|
|
ls
|
|
|
|
| sort-by name
|
|
|
|
| range 0..0
|
2022-02-09 11:58:54 +01:00
|
|
|
| get name.0
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2019-12-15 17:15:06 +01:00
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "notes.txt");
|
2019-12-15 17:15:06 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn selects_some_rows() {
|
|
|
|
Playground::setup("range_test_2", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[
|
2019-12-15 17:15:06 +01:00
|
|
|
EmptyFile("notes.txt"),
|
|
|
|
EmptyFile("tests.txt"),
|
|
|
|
EmptyFile("persons.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2019-12-15 17:15:06 +01:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| range 1..2
|
2021-03-13 22:46:40 +01:00
|
|
|
| length
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2019-12-15 17:15:06 +01:00
|
|
|
));
|
|
|
|
|
2020-05-07 13:03:43 +02:00
|
|
|
assert_eq!(actual.out, "2");
|
2019-12-15 17:15:06 +01:00
|
|
|
});
|
|
|
|
}
|
2021-05-17 05:08:47 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn negative_indices() {
|
|
|
|
Playground::setup("range_test_negative_indices", |dirs, sandbox| {
|
2024-05-04 02:53:15 +02:00
|
|
|
sandbox.with_files(&[
|
2021-05-17 05:08:47 +02:00
|
|
|
EmptyFile("notes.txt"),
|
|
|
|
EmptyFile("tests.txt"),
|
|
|
|
EmptyFile("persons.txt"),
|
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2021-05-17 05:08:47 +02:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| range (-1..)
|
|
|
|
| length
|
2023-07-21 17:32:37 +02:00
|
|
|
"
|
2021-05-17 05:08:47 +02:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "1");
|
|
|
|
});
|
|
|
|
}
|