Move off 'sum' to internal command 'count' for tests.

This commit is contained in:
Andrés N. Robalino 2019-10-15 05:16:47 -05:00
parent 96ef478fbc
commit 5ed1ed54a6
2 changed files with 48 additions and 45 deletions

View File

@ -7,26 +7,21 @@ use helpers::{Playground, Stub::*};
fn ls_lists_regular_files() { fn ls_lists_regular_files() {
Playground::setup("ls_test_1", |dirs, sandbox| { Playground::setup("ls_test_1", |dirs, sandbox| {
sandbox.with_files(vec![ sandbox.with_files(vec![
EmptyFile("yehuda.10.txt"), EmptyFile("yehuda.txt"),
EmptyFile("jonathan.10.txt"), EmptyFile("jonathan.txt"),
EmptyFile("andres.10.txt"), EmptyFile("andres.txt"),
]); ]);
let actual = nu!( let actual = nu!(
cwd: dirs.test(), h::pipeline( cwd: dirs.test(), h::pipeline(
r#" r#"
ls ls
| get name | count
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it | echo $it
"# "#
)); ));
assert_eq!(actual, "30"); assert_eq!(actual, "3");
}) })
} }
@ -34,22 +29,17 @@ fn ls_lists_regular_files() {
fn ls_lists_regular_files_using_asterisk_wildcard() { fn ls_lists_regular_files_using_asterisk_wildcard() {
Playground::setup("ls_test_2", |dirs, sandbox| { Playground::setup("ls_test_2", |dirs, sandbox| {
sandbox.with_files(vec![ sandbox.with_files(vec![
EmptyFile("los.1.txt"), EmptyFile("los.txt"),
EmptyFile("tres.1.txt"), EmptyFile("tres.txt"),
EmptyFile("amigos.1.txt"), EmptyFile("amigos.txt"),
EmptyFile("arepas.1.clu"), EmptyFile("arepas.clu"),
]); ]);
let actual = nu!( let actual = nu!(
cwd: dirs.test(), h::pipeline( cwd: dirs.test(), h::pipeline(
r#" r#"
ls *.txt ls *.txt
| get name | count
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it | echo $it
"# "#
)); ));
@ -72,16 +62,11 @@ fn ls_lists_regular_files_using_question_mark_wildcard() {
cwd: dirs.test(), h::pipeline( cwd: dirs.test(), h::pipeline(
r#" r#"
ls *.??.txt ls *.??.txt
| get name | count
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it | echo $it
"# "#
)); ));
assert_eq!(actual, "30"); assert_eq!(actual, "3");
}) })
} }

View File

@ -7,48 +7,66 @@ use helpers::{Playground, Stub::*};
fn first_gets_first_rows_by_amount() { fn first_gets_first_rows_by_amount() {
Playground::setup("first_test_1", |dirs, sandbox| { Playground::setup("first_test_1", |dirs, sandbox| {
sandbox.with_files(vec![ sandbox.with_files(vec![
EmptyFile("los.1.txt"), EmptyFile("los.txt"),
EmptyFile("tres.1.txt"), EmptyFile("tres.txt"),
EmptyFile("amigos.1.txt"), EmptyFile("amigos.txt"),
EmptyFile("arepas.1.clu"), EmptyFile("arepas.clu"),
]); ]);
let actual = nu!( let actual = nu!(
cwd: dirs.test(), h::pipeline( cwd: dirs.test(), h::pipeline(
r#" r#"
ls ls
| get name | first 3
| first 2 | count
| split-column "."
| get Column2
| str --to-int
| sum
| echo $it | echo $it
"# "#
)); ));
assert_eq!(actual, "2"); assert_eq!(actual, "3");
}) })
} }
#[test] #[test]
fn first_gets_first_row_when_no_amount_given() { fn first_gets_all_rows_if_amount_higher_than_all_rows() {
Playground::setup("first_test_2", |dirs, sandbox| { Playground::setup("first_test_2", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("los-tres-amigos.PASSTEST.txt")]); sandbox.with_files(vec![
EmptyFile("los.txt"),
EmptyFile("tres.txt"),
EmptyFile("amigos.txt"),
EmptyFile("arepas.clu"),
]);
let actual = nu!( let actual = nu!(
cwd: dirs.test(), h::pipeline( cwd: dirs.test(), h::pipeline(
r#" r#"
ls ls
| get name | first 99
| first | count
| split-column "."
| get Column2
| echo $it | echo $it
"# "#
)); ));
assert_eq!(actual, "PASSTEST"); assert_eq!(actual, "4");
})
}
#[test]
fn first_gets_first_row_when_no_amount_given() {
Playground::setup("first_test_3", |dirs, sandbox| {
sandbox.with_files(vec![EmptyFile("caballeros.txt"), EmptyFile("arepas.clu")]);
let actual = nu!(
cwd: dirs.test(), h::pipeline(
r#"
ls
| first
| count
| echo $it
"#
));
assert_eq!(actual, "1");
}) })
} }