2020-06-16 19:58:41 +00:00
|
|
|
use nu_test_support::fs::Stub::EmptyFile;
|
|
|
|
use nu_test_support::playground::Playground;
|
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn gets_all_rows_by_every_zero() {
|
|
|
|
Playground::setup("every_test_1", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2021-01-03 06:44:21 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
2020-06-16 19:58:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| every 0
|
2022-02-04 02:01:45 +00:00
|
|
|
| to json --raw
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
));
|
|
|
|
|
2021-01-03 06:44:21 +00:00
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
r#"["amigos.txt","arepas.clu","los.txt","tres.txt"]"#
|
|
|
|
);
|
2020-06-16 19:58:41 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn gets_no_rows_by_every_skip_zero() {
|
|
|
|
Playground::setup("every_test_2", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2021-01-03 06:44:21 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
2020-06-16 19:58:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| every 0 --skip
|
2022-02-04 02:01:45 +00:00
|
|
|
| to json --raw
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2022-02-04 02:01:45 +00:00
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "[]");
|
2020-06-16 19:58:41 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn gets_all_rows_by_every_one() {
|
|
|
|
Playground::setup("every_test_3", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2021-01-03 06:44:21 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
2020-06-16 19:58:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| every 1
|
2022-02-04 02:01:45 +00:00
|
|
|
| to json --raw
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
));
|
|
|
|
|
2021-01-03 06:44:21 +00:00
|
|
|
assert_eq!(
|
|
|
|
actual.out,
|
|
|
|
r#"["amigos.txt","arepas.clu","los.txt","tres.txt"]"#
|
|
|
|
);
|
2020-06-16 19:58:41 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn gets_no_rows_by_every_skip_one() {
|
|
|
|
Playground::setup("every_test_4", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2021-01-03 06:44:21 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
2020-06-16 19:58:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| every 1 --skip
|
2022-02-04 02:01:45 +00:00
|
|
|
| to json --raw
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
));
|
|
|
|
|
2022-02-16 12:38:02 +00:00
|
|
|
assert_eq!(actual.out, "[]");
|
2020-06-16 19:58:41 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn gets_first_row_by_every_too_much() {
|
|
|
|
Playground::setup("every_test_5", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2021-01-03 06:44:21 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
2020-06-16 19:58:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| every 999
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
));
|
|
|
|
|
2023-04-07 21:09:55 +00:00
|
|
|
let expected = nu!( cwd: dirs.test(), "echo [ amigos.txt ]");
|
2020-06-16 19:58:41 +00:00
|
|
|
|
|
|
|
assert_eq!(actual.out, expected.out);
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn gets_all_rows_except_first_by_every_skip_too_much() {
|
|
|
|
Playground::setup("every_test_6", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2021-01-03 06:44:21 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
2020-06-16 19:58:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| every 999 --skip
|
2022-02-04 02:01:45 +00:00
|
|
|
| to json --raw
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
));
|
|
|
|
|
2021-01-03 06:44:21 +00:00
|
|
|
assert_eq!(actual.out, r#"["arepas.clu","los.txt","tres.txt"]"#);
|
2020-06-16 19:58:41 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn gets_every_third_row() {
|
|
|
|
Playground::setup("every_test_7", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2021-01-03 06:44:21 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("quatro.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
2020-06-16 19:58:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| every 3
|
2022-02-04 02:01:45 +00:00
|
|
|
| to json --raw
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
));
|
|
|
|
|
2021-01-03 06:44:21 +00:00
|
|
|
assert_eq!(actual.out, r#"["amigos.txt","quatro.txt"]"#);
|
2020-06-16 19:58:41 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn skips_every_third_row() {
|
|
|
|
Playground::setup("every_test_8", |dirs, sandbox| {
|
|
|
|
sandbox.with_files(vec![
|
|
|
|
EmptyFile("amigos.txt"),
|
|
|
|
EmptyFile("arepas.clu"),
|
2021-01-03 06:44:21 +00:00
|
|
|
EmptyFile("los.txt"),
|
|
|
|
EmptyFile("quatro.txt"),
|
|
|
|
EmptyFile("tres.txt"),
|
2020-06-16 19:58:41 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
let actual = nu!(
|
|
|
|
cwd: dirs.test(), pipeline(
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
ls
|
|
|
|
| get name
|
|
|
|
| every 3 --skip
|
2022-02-04 02:01:45 +00:00
|
|
|
| to json --raw
|
2023-04-07 21:09:55 +00:00
|
|
|
"
|
2020-06-16 19:58:41 +00:00
|
|
|
));
|
|
|
|
|
2021-01-03 06:44:21 +00:00
|
|
|
assert_eq!(actual.out, r#"["arepas.clu","los.txt","tres.txt"]"#);
|
2020-06-16 19:58:41 +00:00
|
|
|
})
|
|
|
|
}
|