diff --git a/tests/command_ls_tests.rs b/tests/command_ls_tests.rs index f6f5f39f86..a0ae959e12 100644 --- a/tests/command_ls_tests.rs +++ b/tests/command_ls_tests.rs @@ -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"); }) } diff --git a/tests/commands_test.rs b/tests/commands_test.rs index 2a58dd0d13..6544042f66 100644 --- a/tests/commands_test.rs +++ b/tests/commands_test.rs @@ -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"); }) }