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() {
Playground::setup("ls_test_1", |dirs, sandbox| {
sandbox.with_files(vec![
EmptyFile("yehuda.10.txt"),
EmptyFile("jonathan.10.txt"),
EmptyFile("andres.10.txt"),
EmptyFile("yehuda.txt"),
EmptyFile("jonathan.txt"),
EmptyFile("andres.txt"),
]);
let actual = nu!(
cwd: dirs.test(), h::pipeline(
r#"
ls
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| count
| 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() {
Playground::setup("ls_test_2", |dirs, sandbox| {
sandbox.with_files(vec![
EmptyFile("los.1.txt"),
EmptyFile("tres.1.txt"),
EmptyFile("amigos.1.txt"),
EmptyFile("arepas.1.clu"),
EmptyFile("los.txt"),
EmptyFile("tres.txt"),
EmptyFile("amigos.txt"),
EmptyFile("arepas.clu"),
]);
let actual = nu!(
cwd: dirs.test(), h::pipeline(
r#"
ls *.txt
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| count
| echo $it
"#
));
@ -72,16 +62,11 @@ fn ls_lists_regular_files_using_question_mark_wildcard() {
cwd: dirs.test(), h::pipeline(
r#"
ls *.??.txt
| get name
| lines
| split-column "."
| get Column2
| str --to-int
| sum
| count
| 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() {
Playground::setup("first_test_1", |dirs, sandbox| {
sandbox.with_files(vec![
EmptyFile("los.1.txt"),
EmptyFile("tres.1.txt"),
EmptyFile("amigos.1.txt"),
EmptyFile("arepas.1.clu"),
EmptyFile("los.txt"),
EmptyFile("tres.txt"),
EmptyFile("amigos.txt"),
EmptyFile("arepas.clu"),
]);
let actual = nu!(
cwd: dirs.test(), h::pipeline(
r#"
ls
| get name
| first 2
| split-column "."
| get Column2
| str --to-int
| sum
| first 3
| count
| echo $it
"#
));
assert_eq!(actual, "2");
assert_eq!(actual, "3");
})
}
#[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| {
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!(
cwd: dirs.test(), h::pipeline(
r#"
ls
| get name
| first
| split-column "."
| get Column2
| first 99
| count
| 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");
})
}