From 062a55f0484b27c09c37e62994563790982f842a Mon Sep 17 00:00:00 2001 From: figurantpp Date: Sat, 11 Nov 2023 10:37:50 -0300 Subject: [PATCH 01/16] Update uniq tests to avoid file usage --- crates/nu-command/tests/commands/uniq.rs | 97 +++++++----------------- 1 file changed, 29 insertions(+), 68 deletions(-) diff --git a/crates/nu-command/tests/commands/uniq.rs b/crates/nu-command/tests/commands/uniq.rs index d99c8568d141..434e8390b4b4 100644 --- a/crates/nu-command/tests/commands/uniq.rs +++ b/crates/nu-command/tests/commands/uniq.rs @@ -1,62 +1,31 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; +const SAMPLE_CSV_CONTENT: &'static str = r#" + [[first_name, last_name, rusty_at, type]; + [Andrés, Robalino, "10/11/2013", A], + [JT, Turner, "10/12/2013", B], + [Yehuda, Katz, "10/11/2013", A], + [JT, Turner, "10/12/2013", B], + [Yehuda, Katz, "10/11/2013", A]] + "#; #[test] fn removes_duplicate_rows() { - Playground::setup("uniq_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at,type - Andrés,Robalino,10/11/2013,A - JT,Turner,10/12/2013,B - Yehuda,Katz,10/11/2013,A - JT,Turner,10/12/2013,B - Yehuda,Katz,10/11/2013,A - "#, - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_tres_caballeros.csv - | uniq - | length - " - )); - - assert_eq!(actual.out, "3"); - }) + let actual = nu!(pipeline(&format!( + "{} | uniq | length ", + SAMPLE_CSV_CONTENT + ))); + + assert_eq!(actual.out, "3"); } #[test] fn uniq_values() { - Playground::setup("uniq_test_2", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at,type - Andrés,Robalino,10/11/2013,A - JT,Turner,10/12/2013,B - Yehuda,Katz,10/11/2013,A - JT,Turner,10/12/2013,B - Yehuda,Katz,10/11/2013,A - "#, - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_tres_caballeros.csv - | select type - | uniq - | length - " - )); - - assert_eq!(actual.out, "2"); - }) + let actual = nu!(pipeline(&format!( + "{} | select type | uniq | length ", + SAMPLE_CSV_CONTENT + ))); + + assert_eq!(actual.out, "2"); } #[test] @@ -68,10 +37,7 @@ fn uniq_empty() { #[test] fn nested_json_structures() { - Playground::setup("uniq_test_3", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "nested_json_structures.json", - r#" + let sample = r#" [ { "name": "this is duplicated", @@ -114,19 +80,14 @@ fn nested_json_structures() { } } ] - "#, - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open nested_json_structures.json - | uniq - | length - " - )); - assert_eq!(actual.out, "3"); - }) + "#; + + let actual = nu!(pipeline(&format!( + "'{}' | from json | uniq | length", + sample + ))); + + assert_eq!(actual.out, "3"); } #[test] From d4c89f6c1f1a3280e3a6900c920d4fcc7f40b1c6 Mon Sep 17 00:00:00 2001 From: figurantpp Date: Sat, 11 Nov 2023 12:06:59 -0300 Subject: [PATCH 02/16] Remove file I/O from merge tests --- crates/nu-command/tests/commands/merge.rs | 54 ++++++++--------------- 1 file changed, 19 insertions(+), 35 deletions(-) diff --git a/crates/nu-command/tests/commands/merge.rs b/crates/nu-command/tests/commands/merge.rs index 24947be97926..073e9e095e93 100644 --- a/crates/nu-command/tests/commands/merge.rs +++ b/crates/nu-command/tests/commands/merge.rs @@ -1,44 +1,28 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn row() { - Playground::setup("merge_test_1", |dirs, sandbox| { - sandbox.with_files(vec![ - FileWithContentToBeTrimmed( - "caballeros.csv", - r#" - name,country,luck - Andrés,Ecuador,0 - JT,USA,0 - Jason,Canada,0 - Yehuda,USA,0 - "#, - ), - FileWithContentToBeTrimmed( - "new_caballeros.csv", - r#" - name,country,luck - Andrés Robalino,Guayaquil Ecuador,1 - JT Turner,New Zealand,1 - "#, - ), - ]); + let left_sample = r#"[[name, country, luck]; + [Andrés, Ecuador, 0], + [JT, USA, 0], + [Jason, Canada, 0], + [Yehuda, USA, 0]]"#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open caballeros.csv - | merge (open new_caballeros.csv) - | where country in ["Guayaquil Ecuador" "New Zealand"] - | get luck - | math sum - "# - )); + let right_sample = r#"[[name, country, luck]; + ["Andrés Robalino", "Guayaquil Ecuador", 1], + ["JT Turner", "New Zealand", 1]]"#; - assert_eq!(actual.out, "2"); - }); + let actual = nu!(pipeline(&format!( + r#" ({}) + | merge ({}) + | where country in ["Guayaquil Ecuador" "New Zealand"] + | get luck + | math sum + "#, + left_sample, right_sample + ))); + + assert_eq!(actual.out, "2"); } #[test] From ccae8272b2787e6b6d617986d80278f24d7367c1 Mon Sep 17 00:00:00 2001 From: figurantpp Date: Sat, 11 Nov 2023 14:12:05 -0300 Subject: [PATCH 03/16] Remove file I/O from compact command tests --- crates/nu-command/tests/commands/compact.rs | 36 ++++++++------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/crates/nu-command/tests/commands/compact.rs b/crates/nu-command/tests/commands/compact.rs index 2f58535b0701..7fb8ca8472ac 100644 --- a/crates/nu-command/tests/commands/compact.rs +++ b/crates/nu-command/tests/commands/compact.rs @@ -1,13 +1,8 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn discards_rows_where_given_column_is_empty() { - Playground::setup("compact_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_amigos.json", - r#" + let sample_json = r#" { "amigos": [ {"name": "Yehuda", "rusty_luck": 1}, @@ -16,35 +11,30 @@ fn discards_rows_where_given_column_is_empty() { {"name":"GorbyPuff"} ] } - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_tres_amigos.json + let actual = nu!(pipeline(&format!( + " + '{}' | from json | get amigos | compact rusty_luck | length - " - )); + ", + sample_json + ))); - assert_eq!(actual.out, "3"); - }); + assert_eq!(actual.out, "3"); } #[test] fn discards_empty_rows_by_default() { - Playground::setup("compact_test_2", |dirs, _| { - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" + let actual = nu!(pipeline( + r#" echo "[1,2,3,14,null]" | from json | compact | length "# - )); + )); - assert_eq!(actual.out, "4"); - }); + assert_eq!(actual.out, "4"); } From c2a431b4428afe545a06fd46897b6d6762b78f5a Mon Sep 17 00:00:00 2001 From: figurantpp Date: Sat, 11 Nov 2023 14:12:18 -0300 Subject: [PATCH 04/16] Remove file I/O from move command tests --- .../nu-command/tests/commands/move_/column.rs | 146 ++++++++---------- 1 file changed, 61 insertions(+), 85 deletions(-) diff --git a/crates/nu-command/tests/commands/move_/column.rs b/crates/nu-command/tests/commands/move_/column.rs index 3efece2aca5e..2e06a62f6432 100644 --- a/crates/nu-command/tests/commands/move_/column.rs +++ b/crates/nu-command/tests/commands/move_/column.rs @@ -1,130 +1,106 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn moves_a_column_before() { - Playground::setup("move_column_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "sample.csv", - r#" - column1,column2,column3,...,column98,column99,column100 - -------,-------,-------,---,--------, A ,--------- - -------,-------,-------,---,--------, N ,--------- - -------,-------,-------,---,--------, D ,--------- - -------,-------,-------,---,--------, R ,--------- - -------,-------,-------,---,--------, E ,--------- - -------,-------,-------,---,--------, S ,--------- - "#, - )]); + let sample = r#" + [[column1 column2 column3 ... column98 column99 column100]; + [------- ------- ------- --- -------- " A " ---------], + [------- ------- ------- --- -------- " N " ---------], + [------- ------- ------- --- -------- " D " ---------], + [------- ------- ------- --- -------- " R " ---------], + [------- ------- ------- --- -------- " E " ---------], + [------- ------- ------- --- -------- " S " ---------]]"#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open sample.csv + let actual = nu!(pipeline(&format!( + r#" + {} | move column99 --before column1 | rename chars | get chars | str trim | str join - "# - )); + "#, + sample + ))); - assert!(actual.out.contains("ANDRES")); - }) + assert!(actual.out.contains("ANDRES")); } #[test] fn moves_columns_before() { - Playground::setup("move_column_test_2", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "sample.csv", - r#" - column1,column2,column3,...,column98,column99,column100 - -------,-------, A ,---,--------, N ,--------- - -------,-------, D ,---,--------, R ,--------- - -------,-------, E ,---,--------, S ,--------- - -------,-------, : ,---,--------, : ,--------- - -------,-------, J ,---,--------, T ,--------- - "#, - )]); + let sample = r#" + [[column1 column2 column3 ... column98 column99 column100]; + [------- ------- " A " --- -------- " N " ---------] + [------- ------- " D " --- -------- " R " ---------] + [------- ------- " E " --- -------- " S " ---------] + [------- ------- " : " --- -------- " : " ---------] + [------- ------- " J " --- -------- " T " ---------]]"#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open sample.csv + let actual = nu!(pipeline(&format!( + r#" + {} | move column99 column3 --before column2 | rename _ chars_1 chars_2 | select chars_2 chars_1 - | upsert new_col {|f| $f | transpose | get column1 | str trim | str join} + | upsert new_col {{|f| $f | transpose | get column1 | str trim | str join}} | get new_col | str join - "# - )); + "#, + sample + ))); - assert!(actual.out.contains("ANDRES::JT")); - }) + assert!(actual.out.contains("ANDRES::JT")); } #[test] fn moves_a_column_after() { - Playground::setup("move_column_test_3", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "sample.csv", - r#" - column1,column2,letters,...,column98,and_more,column100 - -------,-------, A ,---,--------, N ,--------- - -------,-------, D ,---,--------, R ,--------- - -------,-------, E ,---,--------, S ,--------- - -------,-------, : ,---,--------, : ,--------- - -------,-------, J ,---,--------, T ,--------- - "#, - )]); + let sample = r#" + [[column1 column2 letters ... column98 and_more column100]; + [------- ------- " A " --- -------- " N " ---------] + [------- ------- " D " --- -------- " R " ---------] + [------- ------- " E " --- -------- " S " ---------] + [------- ------- " : " --- -------- " : " ---------] + [------- ------- " J " --- -------- " T " ---------]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open sample.csv + let actual = nu!(pipeline(&format!( + r#" + {} | move letters --after and_more | move letters and_more --before column2 | rename _ chars_1 chars_2 | select chars_1 chars_2 - | upsert new_col {|f| $f | transpose | get column1 | str trim | str join} + | upsert new_col {{|f| $f | transpose | get column1 | str trim | str join}} | get new_col | str join - "# - )); + "#, + sample + ))); - assert!(actual.out.contains("ANDRES::JT")); - }) + assert!(actual.out.contains("ANDRES::JT")); } #[test] fn moves_columns_after() { - Playground::setup("move_column_test_4", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "sample.csv", - r#" - column1,column2,letters,...,column98,and_more,column100 - -------,-------, A ,---,--------, N ,--------- - -------,-------, D ,---,--------, R ,--------- - -------,-------, E ,---,--------, S ,--------- - -------,-------, : ,---,--------, : ,--------- - -------,-------, J ,---,--------, T ,--------- - "#, - )]); + let content = r#" + [[column1 column2 letters ... column98 and_more column100]; + [------- ------- " A " --- -------- " N " ---------] + [------- ------- " D " --- -------- " R " ---------] + [------- ------- " E " --- -------- " S " ---------] + [------- ------- " : " --- -------- " : " ---------] + [------- ------- " J " --- -------- " T " ---------]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open sample.csv + let actual = nu!(pipeline(&format!( + r#" + {} | move letters and_more --after column1 | columns | select 1 2 | str join - "# - )); + "#, + content + ))); - assert!(actual.out.contains("lettersand_more")); - }) + assert!(actual.out.contains("lettersand_more")); } From 99e0133d6d6a375ff22d09c47e27e52c9cfd1a1b Mon Sep 17 00:00:00 2001 From: figurantpp Date: Sat, 11 Nov 2023 14:39:32 -0300 Subject: [PATCH 05/16] Remove file I/O from take while command tests --- .../nu-command/tests/commands/take/while_.rs | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/crates/nu-command/tests/commands/take/while_.rs b/crates/nu-command/tests/commands/take/while_.rs index fcde71e435c4..fcae40893357 100644 --- a/crates/nu-command/tests/commands/take/while_.rs +++ b/crates/nu-command/tests/commands/take/while_.rs @@ -1,53 +1,39 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn condition_is_met() { - Playground::setup("take_while_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "caballeros.txt", - r#" - CHICKEN SUMMARY report date: April 29th, 2020 - -------------------------------------------------------------------- - Chicken Collection,29/04/2020,30/04/2020,31/04/2020 - Yellow Chickens,,, - Andrés,1,1,1 - JT,1,1,1 - Jason,1,1,1 - Yehuda,1,1,1 - Blue Chickens,,, - Andrés,1,1,2 - JT,1,1,2 - Jason,1,1,2 - Yehuda,1,1,2 - Red Chickens,,, - Andrés,1,1,3 - JT,1,1,3 - Jason,1,1,3 - Yehuda,1,1,3 - "#, - )]); + let sample = r#" + [["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"]; + ["Yellow Chickens", "", "", ""], + [Andrés, 1, 1, 1], + [JT, 1, 1, 1], + [Jason, 1, 1, 1], + [Yehuda, 1, 1, 1], + ["Blue Chickens", "", "", ""], + [Andrés, 1, 1, 2], + [JT, 1, 1, 2], + [Jason, 1, 1, 2], + [Yehuda, 1, 1, 2], + ["Red Chickens", "", "", ""], + [Andrés, 1, 1, 3], + [JT, 1, 1, 3], + [Jason, 1, 1, 3], + [Yehuda, 1, 1, 3]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open --raw caballeros.txt - | lines - | skip 2 - | str trim - | str join (char nl) - | from csv + let actual = nu!(pipeline(&format!( + r#" + {} | skip 1 - | take while {|row| $row."Chicken Collection" != "Blue Chickens"} + | take while {{|row| $row."Chicken Collection" != "Blue Chickens"}} | into int "31/04/2020" | get "31/04/2020" | math sum - "# - )); + "#, + sample + ))); - assert_eq!(actual.out, "4"); - }) + assert_eq!(actual.out, "4"); } #[test] From 8e5bccd561b9b37681f1a42940d9e2ce051de8e7 Mon Sep 17 00:00:00 2001 From: figurantpp Date: Sat, 11 Nov 2023 14:49:06 -0300 Subject: [PATCH 06/16] Remove file I/O from histogram command tests --- crates/nu-command/tests/commands/histogram.rs | 99 +++++++------------ 1 file changed, 34 insertions(+), 65 deletions(-) diff --git a/crates/nu-command/tests/commands/histogram.rs b/crates/nu-command/tests/commands/histogram.rs index 738690e1195f..26ee3b73cb3d 100644 --- a/crates/nu-command/tests/commands/histogram.rs +++ b/crates/nu-command/tests/commands/histogram.rs @@ -1,95 +1,64 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; +const SAMPLE_INPUT: &'static str = r#" + [[first_name, last_name, rusty_at]; + [Andrés, Robalino, Ecuador], + [JT, Turner, "Estados Unidos"], + [Yehuda, Katz, "Estados Unidos"]] + "#; + #[test] fn summarizes_by_column_given() { - Playground::setup("histogram_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at - Andrés,Robalino,Ecuador - JT,Turner,Estados Unidos - Yehuda,Katz,Estados Unidos - "#, - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_tres_caballeros.csv + let actual = nu!(pipeline(&format!( + r#" + {} | histogram rusty_at countries --percentage-type relative | where rusty_at == "Ecuador" | get countries | get 0 - "# - )); - - assert_eq!( - actual.out, - "**************************************************" - ); - // 50% - }) + "#, + SAMPLE_INPUT + ))); + + assert_eq!( + actual.out, + "**************************************************" + ); + // 50% } #[test] fn summarizes_by_column_given_with_normalize_percentage() { - Playground::setup("histogram_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at - Andrés,Robalino,Ecuador - JT,Turner,Estados Unidos - Yehuda,Katz,Estados Unidos - "#, - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_tres_caballeros.csv + let actual = nu!(pipeline(&format!( + r#" + {} | histogram rusty_at countries | where rusty_at == "Ecuador" | get countries | get 0 - "# - )); + "#, + SAMPLE_INPUT + ))); - assert_eq!(actual.out, "*********************************"); - // 33% - }) + assert_eq!(actual.out, "*********************************"); + // 33% } #[test] fn summarizes_by_values() { - Playground::setup("histogram_test_2", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at - Andrés,Robalino,Ecuador - JT,Turner,Estados Unidos - Yehuda,Katz,Estados Unidos - "#, - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_tres_caballeros.csv + let actual = nu!(pipeline(&format!( + r#" + {} | get rusty_at | histogram | where value == "Estados Unidos" | get count | get 0 - "# - )); + "#, + SAMPLE_INPUT + ))); - assert_eq!(actual.out, "2"); - }) + assert_eq!(actual.out, "2"); } #[test] From 646aeae6b5678218db66677144d90de7c70b91ac Mon Sep 17 00:00:00 2001 From: figurantpp Date: Sat, 11 Nov 2023 14:52:47 -0300 Subject: [PATCH 07/16] Remove file I/O from take until command tests --- .../nu-command/tests/commands/take/until.rs | 70 ++++++++----------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/crates/nu-command/tests/commands/take/until.rs b/crates/nu-command/tests/commands/take/until.rs index a1a071c3ce6b..0613ad8c38c4 100644 --- a/crates/nu-command/tests/commands/take/until.rs +++ b/crates/nu-command/tests/commands/take/until.rs @@ -1,54 +1,44 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn condition_is_met() { - Playground::setup("take_until_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "caballeros.txt", - r#" - CHICKEN SUMMARY report date: April 29th, 2020 - -------------------------------------------------------------------- - Chicken Collection,29/04/2020,30/04/2020,31/04/2020 - Yellow Chickens,,, - Andrés,1,1,1 - JT,1,1,1 - Jason,1,1,1 - Yehuda,1,1,1 - Blue Chickens,,, - Andrés,1,1,2 - JT,1,1,2 - Jason,1,1,2 - Yehuda,1,1,2 - Red Chickens,,, - Andrés,1,1,3 - JT,1,1,3 - Jason,1,1,3 - Yehuda,1,1,3 - "#, - )]); - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open --raw caballeros.txt - | lines - | skip 2 - | str trim - | str join (char nl) - | from csv - | skip while {|row| $row."Chicken Collection" != "Blue Chickens" } - | take until {|row| $row."Chicken Collection" == "Red Chickens" } + let sample = r#" + [["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"]; + ["Yellow Chickens", "", "", ""], + [Andrés, 1, 1, 1], + [JT, 1, 1, 1], + [Jason, 1, 1, 1], + [Yehuda, 1, 1, 1], + ["Blue Chickens", "", "", ""], + [Andrés, 1, 1, 2], + [JT, 1, 1, 2], + [Jason, 1, 1, 2], + [Yehuda, 1, 1, 2], + ["Red Chickens", "", "", ""], + [Andrés, 1, 1, 3], + [JT, 1, 1, 3], + [Jason, 1, 1, 3], + [Yehuda, 1, 1, 3]] + "#; + + let actual = nu!( + pipeline( + &format!( + r#" + {} + | skip while {{|row| $row."Chicken Collection" != "Blue Chickens" }} + | take until {{|row| $row."Chicken Collection" == "Red Chickens" }} | skip 1 | into int "31/04/2020" | get "31/04/2020" | math sum - "# + "#, + sample + ) )); - assert_eq!(actual.out, "8"); - }) + assert_eq!(actual.out, "8"); } #[test] From b67bf86f71c846f79dac9bc3984b0ec0000576e1 Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:18:41 -0300 Subject: [PATCH 08/16] Remove file I/O from skip while command tests --- .../nu-command/tests/commands/skip/while_.rs | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/crates/nu-command/tests/commands/skip/while_.rs b/crates/nu-command/tests/commands/skip/while_.rs index bd95779a688f..1ff9e371ea8b 100644 --- a/crates/nu-command/tests/commands/skip/while_.rs +++ b/crates/nu-command/tests/commands/skip/while_.rs @@ -1,53 +1,39 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn condition_is_met() { - Playground::setup("skip_while_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "caballeros.txt", - r#" - CHICKEN SUMMARY report date: April 29th, 2020 - -------------------------------------------------------------------- - Chicken Collection,29/04/2020,30/04/2020,31/04/2020 - Yellow Chickens,,, - Andrés,0,0,1 - JT,0,0,1 - Jason,0,0,1 - Yehuda,0,0,1 - Blue Chickens,,, - Andrés,0,0,1 - JT,0,0,1 - Jason,0,0,1 - Yehuda,0,0,2 - Red Chickens,,, - Andrés,0,0,1 - JT,0,0,1 - Jason,0,0,1 - Yehuda,0,0,3 - "#, - )]); + let sample = r#" + [["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"]; + ["Yellow Chickens", "", "", ""], + [Andrés, 0, 0, 1], + [JT, 0, 0, 1], + [Jason, 0, 0, 1], + [Yehuda, 0, 0, 1], + ["Blue Chickens", "", "", ""], + [Andrés, 0, 0, 2], + [JT, 0, 0, 2], + [Jason, 0, 0, 2], + [Yehuda, 0, 0, 2], + ["Red Chickens", "", "", ""], + [Andrés, 0, 0, 1], + [JT, 0, 0, 1], + [Jason, 0, 0, 1], + [Yehuda, 0, 0, 3]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open --raw caballeros.txt - | lines - | skip 2 - | str trim - | str join (char nl) - | from csv - | skip while {|row| $row."Chicken Collection" != "Red Chickens" } + let actual = nu!(pipeline(&format!( + r#" + {} + | skip while {{|row| $row."Chicken Collection" != "Red Chickens" }} | skip 1 | into int "31/04/2020" | get "31/04/2020" | math sum - "# - )); + "#, + &sample + ))); - assert_eq!(actual.out, "6"); - }) + assert_eq!(actual.out, "6"); } #[test] From 5e03adb86bf3065046728896ded0f513af7054e0 Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:22:33 -0300 Subject: [PATCH 09/16] Remove file I/O from skip until command tests --- .../nu-command/tests/commands/skip/until.rs | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/crates/nu-command/tests/commands/skip/until.rs b/crates/nu-command/tests/commands/skip/until.rs index c8f234847d3a..3a2751adf83d 100644 --- a/crates/nu-command/tests/commands/skip/until.rs +++ b/crates/nu-command/tests/commands/skip/until.rs @@ -1,53 +1,39 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn condition_is_met() { - Playground::setup("skip_until_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "caballeros.txt", - r#" - CHICKEN SUMMARY report date: April 29th, 2020 - -------------------------------------------------------------------- - Chicken Collection,29/04/2020,30/04/2020,31/04/2020 - Yellow Chickens,,, - Andrés,0,0,1 - JT,0,0,1 - Jason,0,0,1 - Yehuda,0,0,1 - Blue Chickens,,, - Andrés,0,0,1 - JT,0,0,1 - Jason,0,0,1 - Yehuda,0,0,2 - Red Chickens,,, - Andrés,0,0,1 - JT,0,0,1 - Jason,0,0,1 - Yehuda,0,0,3 - "#, - )]); + let sample = r#" + [["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"]; + ["Yellow Chickens", "", "", ""], + [Andrés, 0, 0, 1], + [JT, 0, 0, 1], + [Jason, 0, 0, 1], + [Yehuda, 0, 0, 1], + ["Blue Chickens", "", "", ""], + [Andrés, 0, 0, 2], + [JT, 0, 0, 2], + [Jason, 0, 0, 2], + [Yehuda, 0, 0, 2], + ["Red Chickens", "", "", ""], + [Andrés, 0, 0, 1], + [JT, 0, 0, 1], + [Jason, 0, 0, 1], + [Yehuda, 0, 0, 3]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open --raw ./caballeros.txt - | lines - | skip 2 - | str trim - | str join (char nl) - | from csv - | skip until {|row| $row."Chicken Collection" == "Red Chickens" } + let actual = nu!(pipeline(&format!( + r#" + {} + | skip until {{|row| $row."Chicken Collection" == "Red Chickens" }} | skip 1 | into int "31/04/2020" | get "31/04/2020" | math sum - "# - )); + "#, + sample + ))); - assert_eq!(actual.out, "6"); - }) + assert_eq!(actual.out, "6"); } #[test] From 502120b2ecb246aa72dd6f5874fa19488901623f Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Sat, 18 Nov 2023 08:27:21 -0300 Subject: [PATCH 10/16] Remove file I/O from take rows tests --- crates/nu-command/tests/commands/take/rows.rs | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/crates/nu-command/tests/commands/take/rows.rs b/crates/nu-command/tests/commands/take/rows.rs index e34b29a7c357..890bf7ee2641 100644 --- a/crates/nu-command/tests/commands/take/rows.rs +++ b/crates/nu-command/tests/commands/take/rows.rs @@ -1,33 +1,25 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn rows() { - Playground::setup("take_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "caballeros.csv", - r#" - name,lucky_code - Andrés,1 - JT,1 - Jason,2 - Yehuda,1 - "#, - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open caballeros.csv + let sample = r#" + [[name, lucky_code]; + [Andrés, 1], + [JT , 1], + [Jason , 2], + [Yehuda, 1]]"#; + + let actual = nu!(pipeline(&format!( + r#" + {} | take 3 | get lucky_code | math sum - "# - )); + "#, + &sample + ))); - assert_eq!(actual.out, "4"); - }) + assert_eq!(actual.out, "4"); } #[test] From af27556dfc4b8dca170be3417e80e50a0c7680df Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Mon, 20 Nov 2023 08:24:17 -0300 Subject: [PATCH 11/16] Remove file I/O from flatten, sum and select tests --- crates/nu-command/tests/commands/flatten.rs | 77 +++++++------------- crates/nu-command/tests/commands/math/sum.rs | 25 +++---- crates/nu-command/tests/commands/select.rs | 25 +++---- 3 files changed, 45 insertions(+), 82 deletions(-) diff --git a/crates/nu-command/tests/commands/flatten.rs b/crates/nu-command/tests/commands/flatten.rs index e9d9611fb8c6..7691ae4c7d8c 100644 --- a/crates/nu-command/tests/commands/flatten.rs +++ b/crates/nu-command/tests/commands/flatten.rs @@ -1,5 +1,3 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] @@ -43,10 +41,7 @@ fn flatten_nested_tables() { #[test] fn flatten_row_column_explicitly() { - Playground::setup("flatten_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "katz.json", - r#" + let sample = r#" [ { "people": { @@ -61,24 +56,19 @@ fn flatten_row_column_explicitly() { } } ] - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), - "open katz.json | flatten people --all | where name == Andres | length" - ); + let actual = nu!(pipeline(&format!( + "{} | flatten people --all | where name == Andres | length", + sample + ))); - assert_eq!(actual.out, "1"); - }) + assert_eq!(actual.out, "1"); } #[test] fn flatten_row_columns_having_same_column_names_flats_separately() { - Playground::setup("flatten_test_2", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "katz.json", - r#" + let sample = r#" [ { "people": { @@ -95,24 +85,19 @@ fn flatten_row_columns_having_same_column_names_flats_separately() { "city": [{"name": "Oregon"}, {"name": "Brooklin"}] } ] - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), - "open katz.json | flatten --all | flatten people city | get city_name | length" - ); + let actual = nu!(pipeline(&format!( + "{} | flatten --all | flatten people city | get city_name | length", + sample + ))); - assert_eq!(actual.out, "4"); - }) + assert_eq!(actual.out, "4"); } #[test] fn flatten_table_columns_explicitly() { - Playground::setup("flatten_test_3", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "katz.json", - r#" + let sample = r#" [ { "people": { @@ -129,24 +114,19 @@ fn flatten_table_columns_explicitly() { "city": ["Oregon", "Brooklin"] } ] - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), - "open katz.json | flatten city --all | where people.name == Katz | length" - ); + let actual = nu!(pipeline(&format!( + "{} | flatten city --all | where people.name == Katz | length", + sample + ))); - assert_eq!(actual.out, "2"); - }) + assert_eq!(actual.out, "2"); } #[test] fn flatten_more_than_one_column_that_are_subtables_not_supported() { - Playground::setup("flatten_test_4", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "katz.json", - r#" + let sample = r#" [ { "people": { @@ -165,15 +145,10 @@ fn flatten_more_than_one_column_that_are_subtables_not_supported() { "city": ["Oregon", "Brooklin"] } ] - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), - "open katz.json | flatten tags city --all" - ); + let actual = nu!(pipeline(&format!("{} | flatten tags city --all", sample))); - assert!(actual.err.contains("tried flattening")); - assert!(actual.err.contains("but is flattened already")); - }) + assert!(actual.err.contains("tried flattening")); + assert!(actual.err.contains("but is flattened already")); } diff --git a/crates/nu-command/tests/commands/math/sum.rs b/crates/nu-command/tests/commands/math/sum.rs index d69cf5507e36..75cfa864d59c 100644 --- a/crates/nu-command/tests/commands/math/sum.rs +++ b/crates/nu-command/tests/commands/math/sum.rs @@ -1,14 +1,9 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; use std::str::FromStr; #[test] fn all() { - Playground::setup("sum_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "meals.json", - r#" + let sample = r#" { meals: [ {description: "1 large egg", calories: 90}, @@ -16,21 +11,19 @@ fn all() { {description: "1 tablespoon fish oil", calories: 108} ] } - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open meals.json + let actual = nu!(pipeline(&format!( + r#" + {} | get meals | get calories | math sum - "# - )); + "#, + sample + ))); - assert_eq!(actual.out, "448"); - }) + assert_eq!(actual.out, "448"); } #[test] diff --git a/crates/nu-command/tests/commands/select.rs b/crates/nu-command/tests/commands/select.rs index 4618a7a4af35..86c65822593f 100644 --- a/crates/nu-command/tests/commands/select.rs +++ b/crates/nu-command/tests/commands/select.rs @@ -1,4 +1,4 @@ -use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed}; +use nu_test_support::fs::Stub::EmptyFile; use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; @@ -24,10 +24,7 @@ fn regular_columns() { #[test] fn complex_nested_columns() { - Playground::setup("select_test_2", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.json", - r#" + let sample = r#" { "nu": { "committers": [ @@ -47,22 +44,20 @@ fn complex_nested_columns() { ] } } - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_tres_caballeros.json + let actual = nu!(pipeline(&format!( + r#" + {} | select nu."0xATYKARNU" nu.committers.name nu.releases.version | get nu_releases_version | where $it > "0.8" | get 0 - "# - )); + "#, + sample + ))); - assert_eq!(actual.out, "0.9999999"); - }) + assert_eq!(actual.out, "0.9999999"); } #[test] From 28a133b3cef004c022d5bc96886020e6b4a3cab2 Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Tue, 28 Nov 2023 22:32:09 -0300 Subject: [PATCH 12/16] Remove unecessary file I/O from multiple tests --- crates/nu-command/tests/commands/default.rs | 25 ++-- crates/nu-command/tests/commands/group_by.rs | 90 +++++-------- crates/nu-command/tests/commands/rename.rs | 131 ++++++++----------- crates/nu-command/tests/commands/split_by.rs | 33 ++--- crates/nu-command/tests/commands/uniq_by.rs | 37 +++--- crates/nu-command/tests/commands/wrap.rs | 66 ++++------ tests/shell/pipeline/commands/internal.rs | 97 ++++++-------- 7 files changed, 190 insertions(+), 289 deletions(-) diff --git a/crates/nu-command/tests/commands/default.rs b/crates/nu-command/tests/commands/default.rs index 131d8077f523..995f0d700898 100644 --- a/crates/nu-command/tests/commands/default.rs +++ b/crates/nu-command/tests/commands/default.rs @@ -1,13 +1,8 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn adds_row_data_if_column_missing() { - Playground::setup("default_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_amigos.json", - r#" + let sample = r#" { "amigos": [ {"name": "Yehuda"}, @@ -16,22 +11,20 @@ fn adds_row_data_if_column_missing() { {"name":"GorbyPuff"} ] } - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_tres_amigos.json + let actual = nu!(pipeline(&format!( + " + {} | get amigos | default 1 rusty_luck | where rusty_luck == 1 | length - " - )); + ", + sample + ))); - assert_eq!(actual.out, "2"); - }); + assert_eq!(actual.out, "2"); } #[test] diff --git a/crates/nu-command/tests/commands/group_by.rs b/crates/nu-command/tests/commands/group_by.rs index caded32914e7..5d370d2d0361 100644 --- a/crates/nu-command/tests/commands/group_by.rs +++ b/crates/nu-command/tests/commands/group_by.rs @@ -1,40 +1,30 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn groups() { - Playground::setup("group_by_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at,type - Andrés,Robalino,10/11/2013,A - JT,Turner,10/12/2013,B - Yehuda,Katz,10/11/2013,A - "#, - )]); + let sample = r#" + [[first_name, last_name, rusty_at, type]; + [Andrés, Robalino, "10/11/2013", A], + [JT, Turner, "10/12/2013", B], + [Yehuda, Katz, "10/11/2013", A]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_tres_caballeros.csv + let actual = nu!(pipeline(&format!( + r#" + {} | group-by rusty_at | get "10/11/2013" | length - "# - )); + "#, + sample + ))); - assert_eq!(actual.out, "2"); - }) + assert_eq!(actual.out, "2"); } #[test] fn errors_if_given_unknown_column_name() { - Playground::setup("group_by_test_2", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.json", - r#" + let sample = r#" { "nu": { "committers": [ @@ -54,46 +44,34 @@ fn errors_if_given_unknown_column_name() { ] } } - "#, - )]); + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_tres_caballeros.json - | group-by {|| get nu.releases.version } - "# - )); + let actual = nu!(pipeline(&format!( + r#" + '{}' + | from json + | group-by {{|| get nu.releases.version }} + "#, + sample + ))); - assert!(actual - .err - .contains("requires a table with one value for grouping")); - }) + assert!(actual + .err + .contains("requires a table with one value for grouping")); } #[test] fn errors_if_column_not_found() { - Playground::setup("group_by_test_3", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at,type - Andrés,Robalino,10/11/2013,A - JT,Turner,10/12/2013,B - Yehuda,Katz,10/11/2013,A - "#, - )]); + let sample = r#" + [[first_name, last_name, rusty_at, type]; + [Andrés, Robalino, "10/11/2013", A], + [JT, Turner, "10/12/2013", B], + [Yehuda, Katz, "10/11/2013", A]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_tres_caballeros.csv - | group-by ttype - " - )); + let actual = nu!(pipeline(&format!("{} | group-by ttype", sample))); - assert!(actual.err.contains("did you mean 'type'"),); - }) + assert!(actual.err.contains("did you mean 'type'"),); } #[test] diff --git a/crates/nu-command/tests/commands/rename.rs b/crates/nu-command/tests/commands/rename.rs index 2cb3b6aedc80..fe77f34feaf2 100644 --- a/crates/nu-command/tests/commands/rename.rs +++ b/crates/nu-command/tests/commands/rename.rs @@ -1,116 +1,89 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn changes_the_column_name() { - Playground::setup("rename_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_cuatro_mosqueteros.txt", - r#" - Andrés N. Robalino - JT Turner - Yehuda Katz - Jason Gedge - "#, - )]); + let sample = r#" + [["Andrés N. Robalino"], + ["JT Turner"], + ["Yehuda Katz"], + ["Jason Gedge"]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_cuatro_mosqueteros.txt - | lines + let actual = nu!(pipeline(&format!( + " {} | wrap name | rename mosqueteros | get mosqueteros | length - " - )); + ", + sample + ))); - assert_eq!(actual.out, "4"); - }) + assert_eq!(actual.out, "4"); } #[test] fn keeps_remaining_original_names_given_less_new_names_than_total_original_names() { - Playground::setup("rename_test_2", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_cuatro_mosqueteros.txt", - r#" - Andrés N. Robalino - JT Turner - Yehuda Katz - Jason Gedge - "#, - )]); + let sample = r#" + [["Andrés N. Robalino"], + ["JT Turner"], + ["Yehuda Katz"], + ["Jason Gedge"]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_cuatro_mosqueteros.txt - | lines + let actual = nu!(pipeline(&format!( + r#" + {} | wrap name | default "arepa!" hit | rename mosqueteros | get hit | length - "# - )); + "#, + sample + ))); - assert_eq!(actual.out, "4"); - }) + assert_eq!(actual.out, "4"); } #[test] fn errors_if_no_columns_present() { - Playground::setup("rename_test_3", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_cuatro_mosqueteros.txt", - r#" - Andrés N. Robalino - JT Turner - Yehuda Katz - Jason Gedge - "#, - )]); + let sample = r#" + [["Andrés N. Robalino"], + ["JT Turner"], + ["Yehuda Katz"], + ["Jason Gedge"]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_cuatro_mosqueteros.txt - | lines + let actual = nu!(pipeline(&format!( + " + {} | rename mosqueteros - " - )); + ", + sample + ))); - assert!(actual.err.contains("command doesn't support")); - }) + assert!(actual.err.contains("command doesn't support")); } #[test] fn errors_if_columns_param_is_empty() { - Playground::setup("rename_test_4", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_cuatro_mosqueteros.txt", - r#" - Andrés N. Robalino - JT Turner - Yehuda Katz - Jason Gedge - "#, - )]); + let sample = r#" + [["Andrés N. Robalino"], + ["JT Turner"], + ["Yehuda Katz"], + ["Jason Gedge"]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_cuatro_mosqueteros.txt - | lines + let actual = nu!(pipeline(&format!( + r#" + {} | wrap name | default "arepa!" hit - | rename --column {} - "# - )); + | rename --column {{}} + "#, + sample + ))); - assert!(actual.err.contains("The column info cannot be empty")); - }) + assert!(actual.err.contains("The column info cannot be empty")); } diff --git a/crates/nu-command/tests/commands/split_by.rs b/crates/nu-command/tests/commands/split_by.rs index 671f1362326e..495094054c64 100644 --- a/crates/nu-command/tests/commands/split_by.rs +++ b/crates/nu-command/tests/commands/split_by.rs @@ -1,33 +1,28 @@ -use nu_test_support::fs::Stub::{EmptyFile, FileWithContentToBeTrimmed}; +use nu_test_support::fs::Stub::EmptyFile; use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn splits() { - Playground::setup("split_by_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at,type - Andrés,Robalino,10/11/2013,A - JT,Turner,10/12/2013,B - Yehuda,Katz,10/11/2013,A - "#, - )]); + let sample = r#" + [[first_name, last_name, rusty_at, type]; + [Andrés, Robalino, "10/11/2013", A], + [JT, Turner, "10/12/2013", B], + [Yehuda, Katz, "10/11/2013", A]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - r#" - open los_tres_caballeros.csv + let actual = nu!(pipeline(&format!( + r#" + {} | group-by rusty_at | split-by type | get A."10/11/2013" | length - "# - )); + "#, + sample + ))); - assert_eq!(actual.out, "2"); - }) + assert_eq!(actual.out, "2"); } #[test] diff --git a/crates/nu-command/tests/commands/uniq_by.rs b/crates/nu-command/tests/commands/uniq_by.rs index dc38c72fc8cd..a56da22349f4 100644 --- a/crates/nu-command/tests/commands/uniq_by.rs +++ b/crates/nu-command/tests/commands/uniq_by.rs @@ -1,32 +1,25 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn removes_duplicate_rows() { - Playground::setup("uniq_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.csv", - r#" - first_name,last_name,rusty_at,type - Andrés,Robalino,10/11/2013,A - Afonso,Turner,10/12/2013,B - Yehuda,Katz,10/11/2013,A - JT,Turner,11/12/2011,O - "#, - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_tres_caballeros.csv + let sample = r#" + [[first_name , last_name, rusty_at, type]; + [Andrés , Robalino, "10/11/2013", A], + [Afonso , Turner, "10/12/2013", B], + [Yehuda , Katz, "10/11/2013", A], + [JT , Turner, "11/12/2011", O]] + "#; + + let actual = nu!(pipeline(&format!( + " + {} | uniq-by last_name | length - " - )); + ", + sample + ))); - assert_eq!(actual.out, "3"); - }) + assert_eq!(actual.out, "3"); } #[test] diff --git a/crates/nu-command/tests/commands/wrap.rs b/crates/nu-command/tests/commands/wrap.rs index 30e28ab9a813..bc2d20d35983 100644 --- a/crates/nu-command/tests/commands/wrap.rs +++ b/crates/nu-command/tests/commands/wrap.rs @@ -1,61 +1,47 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; #[test] fn wrap_rows_into_a_row() { - Playground::setup("wrap_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.txt", - r#" - first_name,last_name - Andrés,Robalino - JT,Turner - Yehuda,Katz - "#, - )]); + let sample = r#" + [[first_name, last_name]; + [Andrés, Robalino], + [JT, Turner], + [Yehuda, Katz]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_tres_caballeros.txt - | from csv + let actual = nu!(pipeline(&format!( + " + {} | wrap caballeros | get caballeros | get 0 | get last_name - " - )); + ", + sample + ))); - assert_eq!(actual.out, "Robalino"); - }) + assert_eq!(actual.out, "Robalino"); } #[test] fn wrap_rows_into_a_table() { - Playground::setup("wrap_test_2", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "los_tres_caballeros.txt", - r#" - first_name,last_name - Andrés,Robalino - JT,Turner - Yehuda,Katz - "#, - )]); + let sample = r#" + [[first_name, last_name]; + [Andrés, Robalino], + [JT, Turner], + [Yehuda, Katz]] + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( - " - open los_tres_caballeros.txt - | from csv + let actual = nu!(pipeline(&format!( + " + {} | get last_name | wrap caballero | get 2 | get caballero - " - )); + ", + sample + ))); - assert_eq!(actual.out, "Katz"); - }) + assert_eq!(actual.out, "Katz"); } diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 16afde8c94cf..45ec98c8b883 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -1,62 +1,50 @@ -use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; -use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; use pretty_assertions::assert_eq; #[test] fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() { - Playground::setup("internal_to_external_pipe_test_1", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "nu_times.csv", - " - name,rusty_luck,origin - Jason,1,Canada - JT,1,New Zealand - Andrés,1,Ecuador - AndKitKatz,1,Estados Unidos - ", - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( + let sample = r#" + [[name, rusty_luck, origin]; + [Jason, 1, Canada], + [JT, 1, "New Zealand"], + [Andrés, 1, Ecuador], + [AndKitKatz, 1, "Estados Unidos"]] + "#; + + let actual = nu!(pipeline(&format!( " - open nu_times.csv + {} | get origin - | each { |it| nu --testbin cococo $it | nu --testbin chop } + | each {{ |it| nu --testbin cococo $it | nu --testbin chop }} | get 2 - " - )); + ", + sample + ))); - // chop will remove the last escaped double quote from \"Estados Unidos\" - assert_eq!(actual.out, "Ecuado"); - }) + // chop will remove the last escaped double quote from \"Estados Unidos\" + assert_eq!(actual.out, "Ecuado"); } #[test] fn treats_dot_dot_as_path_not_range() { - Playground::setup("dot_dot_dir", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "nu_times.csv", - " + let sample = r#" name,rusty_luck,origin Jason,1,Canada - ", - )]); + "#; - let actual = nu!( - cwd: dirs.test(), pipeline( + let actual = nu!(pipeline(&format!( " mkdir temp; cd temp; - print (open ../nu_times.csv).name.0 | table; + print ({}).name.0 | table; cd ..; rmdir temp - " - )); + ", + sample + ))); - // chop will remove the last escaped double quote from \"Estados Unidos\" - assert_eq!(actual.out, "Jason"); - }) + // chop will remove the last escaped double quote from \"Estados Unidos\" + assert_eq!(actual.out, "Jason"); } #[test] @@ -88,30 +76,25 @@ fn for_loop() { #[test] fn subexpression_handles_dot() { - Playground::setup("subexpression_handles_dot", |dirs, sandbox| { - sandbox.with_files(vec![FileWithContentToBeTrimmed( - "nu_times.csv", - " - name,rusty_luck,origin - Jason,1,Canada - JT,1,New Zealand - Andrés,1,Ecuador - AndKitKatz,1,Estados Unidos - ", - )]); - - let actual = nu!( - cwd: dirs.test(), pipeline( + let sample = r#" + [[name, rusty_luck, origin]; + [Jason, 1, Canada], + [JT, 1, "New Zealand"], + [Andrés, 1, Ecuador], + [AndKitKatz, 1, "Estados Unidos"]] + "#; + + let actual = nu!(pipeline(&format!( " - echo (open nu_times.csv) + {} | get name - | each { |it| nu --testbin chop $it } + | each {{ |it| nu --testbin chop $it }} | get 3 - " - )); + ", + sample + ))); - assert_eq!(actual.out, "AndKitKat"); - }) + assert_eq!(actual.out, "AndKitKat"); } #[test] From fa4d87af099c72f89f65a509a298745270ad1b34 Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Tue, 28 Nov 2023 22:56:38 -0300 Subject: [PATCH 13/16] Fix style and test issues --- crates/nu-command/src/filters/find.rs | 5 +++-- crates/nu-command/tests/commands/take/until.rs | 12 ++++-------- tests/shell/pipeline/commands/internal.rs | 6 +++--- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/crates/nu-command/src/filters/find.rs b/crates/nu-command/src/filters/find.rs index 4f26477e0e48..30c728e743e1 100644 --- a/crates/nu-command/src/filters/find.rs +++ b/crates/nu-command/src/filters/find.rs @@ -304,8 +304,9 @@ fn highlight_terms_in_record_with_search_columns( let val_str = val.into_string("", config); let Some(term_str) = term_strs .iter() - .find(|term_str| contains_ignore_case(&val_str, term_str)) else { - continue; + .find(|term_str| contains_ignore_case(&val_str, term_str)) + else { + continue; }; let highlighted_str = diff --git a/crates/nu-command/tests/commands/take/until.rs b/crates/nu-command/tests/commands/take/until.rs index 0613ad8c38c4..385f291b39a6 100644 --- a/crates/nu-command/tests/commands/take/until.rs +++ b/crates/nu-command/tests/commands/take/until.rs @@ -2,7 +2,6 @@ use nu_test_support::{nu, pipeline}; #[test] fn condition_is_met() { - let sample = r#" [["Chicken Collection", "29/04/2020", "30/04/2020", "31/04/2020"]; ["Yellow Chickens", "", "", ""], @@ -22,10 +21,8 @@ fn condition_is_met() { [Yehuda, 1, 1, 3]] "#; - let actual = nu!( - pipeline( - &format!( - r#" + let actual = nu!(pipeline(&format!( + r#" {} | skip while {{|row| $row."Chicken Collection" != "Blue Chickens" }} | take until {{|row| $row."Chicken Collection" == "Red Chickens" }} @@ -34,9 +31,8 @@ fn condition_is_met() { | get "31/04/2020" | math sum "#, - sample - ) - )); + sample + ))); assert_eq!(actual.out, "8"); } diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 45ec98c8b883..6676c0f254f6 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -28,15 +28,15 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() { #[test] fn treats_dot_dot_as_path_not_range() { let sample = r#" - name,rusty_luck,origin - Jason,1,Canada + [[name, rusty_luck, origin]; + [Jason, 1, Canada]] "#; let actual = nu!(pipeline(&format!( " mkdir temp; cd temp; - print ({}).name.0 | table; + print (echo {}).name.0 | table; cd ..; rmdir temp ", From 052d57e536c9fa831928043190192fea23dafe4a Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Wed, 29 Nov 2023 09:21:00 -0300 Subject: [PATCH 14/16] Apply clippy 'static lifetime suggestions --- crates/nu-command/tests/commands/histogram.rs | 2 +- crates/nu-command/tests/commands/uniq.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/nu-command/tests/commands/histogram.rs b/crates/nu-command/tests/commands/histogram.rs index 26ee3b73cb3d..c2bfe48039e1 100644 --- a/crates/nu-command/tests/commands/histogram.rs +++ b/crates/nu-command/tests/commands/histogram.rs @@ -1,6 +1,6 @@ use nu_test_support::{nu, pipeline}; -const SAMPLE_INPUT: &'static str = r#" +const SAMPLE_INPUT: &str = r#" [[first_name, last_name, rusty_at]; [Andrés, Robalino, Ecuador], [JT, Turner, "Estados Unidos"], diff --git a/crates/nu-command/tests/commands/uniq.rs b/crates/nu-command/tests/commands/uniq.rs index 434e8390b4b4..54029e7893e4 100644 --- a/crates/nu-command/tests/commands/uniq.rs +++ b/crates/nu-command/tests/commands/uniq.rs @@ -1,6 +1,6 @@ use nu_test_support::{nu, pipeline}; -const SAMPLE_CSV_CONTENT: &'static str = r#" +const SAMPLE_CSV_CONTENT: &str = r#" [[first_name, last_name, rusty_at, type]; [Andrés, Robalino, "10/11/2013", A], [JT, Turner, "10/12/2013", B], From 2a87c35fa8259d8a48fc2173a5fe3ce26c715ace Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Wed, 29 Nov 2023 10:16:35 -0300 Subject: [PATCH 15/16] Use {variable} formatting in tests --- crates/nu-command/tests/commands/compact.rs | 5 ++--- crates/nu-command/tests/commands/default.rs | 5 ++--- crates/nu-command/tests/commands/flatten.rs | 11 ++++------ crates/nu-command/tests/commands/group_by.rs | 12 +++++------ crates/nu-command/tests/commands/histogram.rs | 15 ++++++-------- crates/nu-command/tests/commands/math/sum.rs | 5 ++--- crates/nu-command/tests/commands/merge.rs | 7 +++---- .../nu-command/tests/commands/move_/column.rs | 20 ++++++++----------- crates/nu-command/tests/commands/rename.rs | 20 ++++++++----------- crates/nu-command/tests/commands/select.rs | 5 ++--- .../nu-command/tests/commands/skip/until.rs | 5 ++--- .../nu-command/tests/commands/skip/while_.rs | 5 ++--- crates/nu-command/tests/commands/split_by.rs | 5 ++--- crates/nu-command/tests/commands/take/rows.rs | 5 ++--- .../nu-command/tests/commands/take/until.rs | 5 ++--- .../nu-command/tests/commands/take/while_.rs | 5 ++--- crates/nu-command/tests/commands/uniq.rs | 13 +++--------- crates/nu-command/tests/commands/uniq_by.rs | 5 ++--- crates/nu-command/tests/commands/wrap.rs | 10 ++++------ tests/shell/pipeline/commands/internal.rs | 15 ++++++-------- 20 files changed, 69 insertions(+), 109 deletions(-) diff --git a/crates/nu-command/tests/commands/compact.rs b/crates/nu-command/tests/commands/compact.rs index 7fb8ca8472ac..40a7abc42a9c 100644 --- a/crates/nu-command/tests/commands/compact.rs +++ b/crates/nu-command/tests/commands/compact.rs @@ -15,12 +15,11 @@ fn discards_rows_where_given_column_is_empty() { let actual = nu!(pipeline(&format!( " - '{}' | from json + {sample_json} | get amigos | compact rusty_luck | length - ", - sample_json + " ))); assert_eq!(actual.out, "3"); diff --git a/crates/nu-command/tests/commands/default.rs b/crates/nu-command/tests/commands/default.rs index 995f0d700898..87426fb1ea89 100644 --- a/crates/nu-command/tests/commands/default.rs +++ b/crates/nu-command/tests/commands/default.rs @@ -15,13 +15,12 @@ fn adds_row_data_if_column_missing() { let actual = nu!(pipeline(&format!( " - {} + {sample} | get amigos | default 1 rusty_luck | where rusty_luck == 1 | length - ", - sample + " ))); assert_eq!(actual.out, "2"); diff --git a/crates/nu-command/tests/commands/flatten.rs b/crates/nu-command/tests/commands/flatten.rs index 7691ae4c7d8c..e39ab61c84f1 100644 --- a/crates/nu-command/tests/commands/flatten.rs +++ b/crates/nu-command/tests/commands/flatten.rs @@ -59,8 +59,7 @@ fn flatten_row_column_explicitly() { "#; let actual = nu!(pipeline(&format!( - "{} | flatten people --all | where name == Andres | length", - sample + "{sample} | flatten people --all | where name == Andres | length" ))); assert_eq!(actual.out, "1"); @@ -88,8 +87,7 @@ fn flatten_row_columns_having_same_column_names_flats_separately() { "#; let actual = nu!(pipeline(&format!( - "{} | flatten --all | flatten people city | get city_name | length", - sample + "{sample} | flatten --all | flatten people city | get city_name | length" ))); assert_eq!(actual.out, "4"); @@ -117,8 +115,7 @@ fn flatten_table_columns_explicitly() { "#; let actual = nu!(pipeline(&format!( - "{} | flatten city --all | where people.name == Katz | length", - sample + "{sample} | flatten city --all | where people.name == Katz | length", ))); assert_eq!(actual.out, "2"); @@ -147,7 +144,7 @@ fn flatten_more_than_one_column_that_are_subtables_not_supported() { ] "#; - let actual = nu!(pipeline(&format!("{} | flatten tags city --all", sample))); + let actual = nu!(pipeline(&format!("{sample} | flatten tags city --all"))); assert!(actual.err.contains("tried flattening")); assert!(actual.err.contains("but is flattened already")); diff --git a/crates/nu-command/tests/commands/group_by.rs b/crates/nu-command/tests/commands/group_by.rs index 5d370d2d0361..e58b32727576 100644 --- a/crates/nu-command/tests/commands/group_by.rs +++ b/crates/nu-command/tests/commands/group_by.rs @@ -11,12 +11,11 @@ fn groups() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | group-by rusty_at | get "10/11/2013" | length - "#, - sample + "# ))); assert_eq!(actual.out, "2"); @@ -48,11 +47,10 @@ fn errors_if_given_unknown_column_name() { let actual = nu!(pipeline(&format!( r#" - '{}' + '{sample}' | from json | group-by {{|| get nu.releases.version }} - "#, - sample + "# ))); assert!(actual @@ -69,7 +67,7 @@ fn errors_if_column_not_found() { [Yehuda, Katz, "10/11/2013", A]] "#; - let actual = nu!(pipeline(&format!("{} | group-by ttype", sample))); + let actual = nu!(pipeline(&format!("{sample} | group-by ttype"))); assert!(actual.err.contains("did you mean 'type'"),); } diff --git a/crates/nu-command/tests/commands/histogram.rs b/crates/nu-command/tests/commands/histogram.rs index c2bfe48039e1..36e3c84109c0 100644 --- a/crates/nu-command/tests/commands/histogram.rs +++ b/crates/nu-command/tests/commands/histogram.rs @@ -11,13 +11,12 @@ const SAMPLE_INPUT: &str = r#" fn summarizes_by_column_given() { let actual = nu!(pipeline(&format!( r#" - {} + {SAMPLE_INPUT} | histogram rusty_at countries --percentage-type relative | where rusty_at == "Ecuador" | get countries | get 0 - "#, - SAMPLE_INPUT + "# ))); assert_eq!( @@ -31,13 +30,12 @@ fn summarizes_by_column_given() { fn summarizes_by_column_given_with_normalize_percentage() { let actual = nu!(pipeline(&format!( r#" - {} + {SAMPLE_INPUT} | histogram rusty_at countries | where rusty_at == "Ecuador" | get countries | get 0 - "#, - SAMPLE_INPUT + "# ))); assert_eq!(actual.out, "*********************************"); @@ -48,14 +46,13 @@ fn summarizes_by_column_given_with_normalize_percentage() { fn summarizes_by_values() { let actual = nu!(pipeline(&format!( r#" - {} + {SAMPLE_INPUT} | get rusty_at | histogram | where value == "Estados Unidos" | get count | get 0 - "#, - SAMPLE_INPUT + "# ))); assert_eq!(actual.out, "2"); diff --git a/crates/nu-command/tests/commands/math/sum.rs b/crates/nu-command/tests/commands/math/sum.rs index 75cfa864d59c..327eadee11bb 100644 --- a/crates/nu-command/tests/commands/math/sum.rs +++ b/crates/nu-command/tests/commands/math/sum.rs @@ -15,12 +15,11 @@ fn all() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | get meals | get calories | math sum - "#, - sample + "# ))); assert_eq!(actual.out, "448"); diff --git a/crates/nu-command/tests/commands/merge.rs b/crates/nu-command/tests/commands/merge.rs index 073e9e095e93..cbece02ee99c 100644 --- a/crates/nu-command/tests/commands/merge.rs +++ b/crates/nu-command/tests/commands/merge.rs @@ -13,13 +13,12 @@ fn row() { ["JT Turner", "New Zealand", 1]]"#; let actual = nu!(pipeline(&format!( - r#" ({}) - | merge ({}) + r#" ({left_sample}) + | merge ({right_sample}) | where country in ["Guayaquil Ecuador" "New Zealand"] | get luck | math sum - "#, - left_sample, right_sample + "# ))); assert_eq!(actual.out, "2"); diff --git a/crates/nu-command/tests/commands/move_/column.rs b/crates/nu-command/tests/commands/move_/column.rs index 2e06a62f6432..25c51d012b61 100644 --- a/crates/nu-command/tests/commands/move_/column.rs +++ b/crates/nu-command/tests/commands/move_/column.rs @@ -13,14 +13,13 @@ fn moves_a_column_before() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | move column99 --before column1 | rename chars | get chars | str trim | str join - "#, - sample + "# ))); assert!(actual.out.contains("ANDRES")); @@ -38,15 +37,14 @@ fn moves_columns_before() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | move column99 column3 --before column2 | rename _ chars_1 chars_2 | select chars_2 chars_1 | upsert new_col {{|f| $f | transpose | get column1 | str trim | str join}} | get new_col | str join - "#, - sample + "# ))); assert!(actual.out.contains("ANDRES::JT")); @@ -65,7 +63,7 @@ fn moves_a_column_after() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | move letters --after and_more | move letters and_more --before column2 | rename _ chars_1 chars_2 @@ -73,8 +71,7 @@ fn moves_a_column_after() { | upsert new_col {{|f| $f | transpose | get column1 | str trim | str join}} | get new_col | str join - "#, - sample + "# ))); assert!(actual.out.contains("ANDRES::JT")); @@ -93,13 +90,12 @@ fn moves_columns_after() { let actual = nu!(pipeline(&format!( r#" - {} + {content} | move letters and_more --after column1 | columns | select 1 2 | str join - "#, - content + "# ))); assert!(actual.out.contains("lettersand_more")); diff --git a/crates/nu-command/tests/commands/rename.rs b/crates/nu-command/tests/commands/rename.rs index fe77f34feaf2..784f4b0369cf 100644 --- a/crates/nu-command/tests/commands/rename.rs +++ b/crates/nu-command/tests/commands/rename.rs @@ -10,13 +10,12 @@ fn changes_the_column_name() { "#; let actual = nu!(pipeline(&format!( - " {} + " {sample} | wrap name | rename mosqueteros | get mosqueteros | length - ", - sample + " ))); assert_eq!(actual.out, "4"); @@ -33,14 +32,13 @@ fn keeps_remaining_original_names_given_less_new_names_than_total_original_names let actual = nu!(pipeline(&format!( r#" - {} + {sample} | wrap name | default "arepa!" hit | rename mosqueteros | get hit | length - "#, - sample + "# ))); assert_eq!(actual.out, "4"); @@ -57,10 +55,9 @@ fn errors_if_no_columns_present() { let actual = nu!(pipeline(&format!( " - {} + {sample} | rename mosqueteros - ", - sample + " ))); assert!(actual.err.contains("command doesn't support")); @@ -77,12 +74,11 @@ fn errors_if_columns_param_is_empty() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | wrap name | default "arepa!" hit | rename --column {{}} - "#, - sample + "# ))); assert!(actual.err.contains("The column info cannot be empty")); diff --git a/crates/nu-command/tests/commands/select.rs b/crates/nu-command/tests/commands/select.rs index 86c65822593f..0663192f702c 100644 --- a/crates/nu-command/tests/commands/select.rs +++ b/crates/nu-command/tests/commands/select.rs @@ -48,13 +48,12 @@ fn complex_nested_columns() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | select nu."0xATYKARNU" nu.committers.name nu.releases.version | get nu_releases_version | where $it > "0.8" | get 0 - "#, - sample + "# ))); assert_eq!(actual.out, "0.9999999"); diff --git a/crates/nu-command/tests/commands/skip/until.rs b/crates/nu-command/tests/commands/skip/until.rs index 3a2751adf83d..529863fcf2a9 100644 --- a/crates/nu-command/tests/commands/skip/until.rs +++ b/crates/nu-command/tests/commands/skip/until.rs @@ -23,14 +23,13 @@ fn condition_is_met() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | skip until {{|row| $row."Chicken Collection" == "Red Chickens" }} | skip 1 | into int "31/04/2020" | get "31/04/2020" | math sum - "#, - sample + "# ))); assert_eq!(actual.out, "6"); diff --git a/crates/nu-command/tests/commands/skip/while_.rs b/crates/nu-command/tests/commands/skip/while_.rs index 1ff9e371ea8b..8814a9e9f808 100644 --- a/crates/nu-command/tests/commands/skip/while_.rs +++ b/crates/nu-command/tests/commands/skip/while_.rs @@ -23,14 +23,13 @@ fn condition_is_met() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | skip while {{|row| $row."Chicken Collection" != "Red Chickens" }} | skip 1 | into int "31/04/2020" | get "31/04/2020" | math sum - "#, - &sample + "# ))); assert_eq!(actual.out, "6"); diff --git a/crates/nu-command/tests/commands/split_by.rs b/crates/nu-command/tests/commands/split_by.rs index 495094054c64..ab4b7d5459d6 100644 --- a/crates/nu-command/tests/commands/split_by.rs +++ b/crates/nu-command/tests/commands/split_by.rs @@ -13,13 +13,12 @@ fn splits() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | group-by rusty_at | split-by type | get A."10/11/2013" | length - "#, - sample + "# ))); assert_eq!(actual.out, "2"); diff --git a/crates/nu-command/tests/commands/take/rows.rs b/crates/nu-command/tests/commands/take/rows.rs index 890bf7ee2641..d5f3d1c601de 100644 --- a/crates/nu-command/tests/commands/take/rows.rs +++ b/crates/nu-command/tests/commands/take/rows.rs @@ -11,12 +11,11 @@ fn rows() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | take 3 | get lucky_code | math sum - "#, - &sample + "# ))); assert_eq!(actual.out, "4"); diff --git a/crates/nu-command/tests/commands/take/until.rs b/crates/nu-command/tests/commands/take/until.rs index 385f291b39a6..a455c0202c58 100644 --- a/crates/nu-command/tests/commands/take/until.rs +++ b/crates/nu-command/tests/commands/take/until.rs @@ -23,15 +23,14 @@ fn condition_is_met() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | skip while {{|row| $row."Chicken Collection" != "Blue Chickens" }} | take until {{|row| $row."Chicken Collection" == "Red Chickens" }} | skip 1 | into int "31/04/2020" | get "31/04/2020" | math sum - "#, - sample + "# ))); assert_eq!(actual.out, "8"); diff --git a/crates/nu-command/tests/commands/take/while_.rs b/crates/nu-command/tests/commands/take/while_.rs index fcae40893357..4514affeee1d 100644 --- a/crates/nu-command/tests/commands/take/while_.rs +++ b/crates/nu-command/tests/commands/take/while_.rs @@ -23,14 +23,13 @@ fn condition_is_met() { let actual = nu!(pipeline(&format!( r#" - {} + {sample} | skip 1 | take while {{|row| $row."Chicken Collection" != "Blue Chickens"}} | into int "31/04/2020" | get "31/04/2020" | math sum - "#, - sample + "# ))); assert_eq!(actual.out, "4"); diff --git a/crates/nu-command/tests/commands/uniq.rs b/crates/nu-command/tests/commands/uniq.rs index 54029e7893e4..f543bda24d34 100644 --- a/crates/nu-command/tests/commands/uniq.rs +++ b/crates/nu-command/tests/commands/uniq.rs @@ -10,10 +10,7 @@ const SAMPLE_CSV_CONTENT: &str = r#" "#; #[test] fn removes_duplicate_rows() { - let actual = nu!(pipeline(&format!( - "{} | uniq | length ", - SAMPLE_CSV_CONTENT - ))); + let actual = nu!(pipeline(&format!("{SAMPLE_CSV_CONTENT} | uniq | length "))); assert_eq!(actual.out, "3"); } @@ -21,8 +18,7 @@ fn removes_duplicate_rows() { #[test] fn uniq_values() { let actual = nu!(pipeline(&format!( - "{} | select type | uniq | length ", - SAMPLE_CSV_CONTENT + "{SAMPLE_CSV_CONTENT} | select type | uniq | length ", ))); assert_eq!(actual.out, "2"); @@ -82,10 +78,7 @@ fn nested_json_structures() { ] "#; - let actual = nu!(pipeline(&format!( - "'{}' | from json | uniq | length", - sample - ))); + let actual = nu!(pipeline(&format!("'{sample}' | from json | uniq | length"))); assert_eq!(actual.out, "3"); } diff --git a/crates/nu-command/tests/commands/uniq_by.rs b/crates/nu-command/tests/commands/uniq_by.rs index a56da22349f4..c791e4e6bd94 100644 --- a/crates/nu-command/tests/commands/uniq_by.rs +++ b/crates/nu-command/tests/commands/uniq_by.rs @@ -12,11 +12,10 @@ fn removes_duplicate_rows() { let actual = nu!(pipeline(&format!( " - {} + {sample} | uniq-by last_name | length - ", - sample + " ))); assert_eq!(actual.out, "3"); diff --git a/crates/nu-command/tests/commands/wrap.rs b/crates/nu-command/tests/commands/wrap.rs index bc2d20d35983..6ca723e2eb5e 100644 --- a/crates/nu-command/tests/commands/wrap.rs +++ b/crates/nu-command/tests/commands/wrap.rs @@ -11,13 +11,12 @@ fn wrap_rows_into_a_row() { let actual = nu!(pipeline(&format!( " - {} + {sample} | wrap caballeros | get caballeros | get 0 | get last_name - ", - sample + " ))); assert_eq!(actual.out, "Robalino"); @@ -34,13 +33,12 @@ fn wrap_rows_into_a_table() { let actual = nu!(pipeline(&format!( " - {} + {sample} | get last_name | wrap caballero | get 2 | get caballero - ", - sample + " ))); assert_eq!(actual.out, "Katz"); diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 6676c0f254f6..3bf25c55b51b 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -13,12 +13,11 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() { let actual = nu!(pipeline(&format!( " - {} + {sample} | get origin | each {{ |it| nu --testbin cococo $it | nu --testbin chop }} | get 2 - ", - sample + " ))); // chop will remove the last escaped double quote from \"Estados Unidos\" @@ -36,11 +35,10 @@ fn treats_dot_dot_as_path_not_range() { " mkdir temp; cd temp; - print (echo {}).name.0 | table; + print (echo {sample}).name.0 | table; cd ..; rmdir temp - ", - sample + " ))); // chop will remove the last escaped double quote from \"Estados Unidos\" @@ -86,12 +84,11 @@ fn subexpression_handles_dot() { let actual = nu!(pipeline(&format!( " - {} + {sample} | get name | each {{ |it| nu --testbin chop $it }} | get 3 - ", - sample + " ))); assert_eq!(actual.out, "AndKitKat"); From 4af1ec06fbcf810981dad76381b3b5a5c2f43d30 Mon Sep 17 00:00:00 2001 From: cosineblast <55855728+cosineblast@users.noreply.github.com> Date: Wed, 29 Nov 2023 17:44:15 -0300 Subject: [PATCH 16/16] Revert some I/O modifications to pipeline tests --- tests/shell/pipeline/commands/internal.rs | 58 ++++++++++++++--------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/tests/shell/pipeline/commands/internal.rs b/tests/shell/pipeline/commands/internal.rs index 3bf25c55b51b..f85f5e41b084 100644 --- a/tests/shell/pipeline/commands/internal.rs +++ b/tests/shell/pipeline/commands/internal.rs @@ -1,3 +1,5 @@ +use nu_test_support::fs::Stub::FileWithContentToBeTrimmed; +use nu_test_support::playground::Playground; use nu_test_support::{nu, pipeline}; use pretty_assertions::assert_eq; @@ -26,23 +28,29 @@ fn takes_rows_of_nu_value_strings_and_pipes_it_to_stdin_of_external() { #[test] fn treats_dot_dot_as_path_not_range() { - let sample = r#" - [[name, rusty_luck, origin]; - [Jason, 1, Canada]] - "#; + Playground::setup("dot_dot_dir", |dirs, sandbox| { + sandbox.with_files(vec![FileWithContentToBeTrimmed( + "nu_times.csv", + " + name,rusty_luck,origin + Jason,1,Canada + ", + )]); - let actual = nu!(pipeline(&format!( + let actual = nu!( + cwd: dirs.test(), pipeline( " mkdir temp; cd temp; - print (echo {sample}).name.0 | table; + print (open ../nu_times.csv).name.0 | table; cd ..; rmdir temp " - ))); + )); - // chop will remove the last escaped double quote from \"Estados Unidos\" - assert_eq!(actual.out, "Jason"); + // chop will remove the last escaped double quote from \"Estados Unidos\" + assert_eq!(actual.out, "Jason"); + }) } #[test] @@ -74,24 +82,30 @@ fn for_loop() { #[test] fn subexpression_handles_dot() { - let sample = r#" - [[name, rusty_luck, origin]; - [Jason, 1, Canada], - [JT, 1, "New Zealand"], - [Andrés, 1, Ecuador], - [AndKitKatz, 1, "Estados Unidos"]] - "#; - - let actual = nu!(pipeline(&format!( + Playground::setup("subexpression_handles_dot", |dirs, sandbox| { + sandbox.with_files(vec![FileWithContentToBeTrimmed( + "nu_times.csv", + " + name,rusty_luck,origin + Jason,1,Canada + JT,1,New Zealand + Andrés,1,Ecuador + AndKitKatz,1,Estados Unidos + ", + )]); + + let actual = nu!( + cwd: dirs.test(), pipeline( " - {sample} + echo (open nu_times.csv) | get name - | each {{ |it| nu --testbin chop $it }} + | each { |it| nu --testbin chop $it } | get 3 " - ))); + )); - assert_eq!(actual.out, "AndKitKat"); + assert_eq!(actual.out, "AndKitKat"); + }); } #[test]