From 04c4e9224f08d74a02fc5892847b849dc24b4aee Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Tue, 3 May 2022 00:35:46 -0400 Subject: [PATCH 01/11] Added if statement that returns no new line if there an empty splice --- script.go | 3 +++ script_test.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/script.go b/script.go index 8703873..ac29364 100644 --- a/script.go +++ b/script.go @@ -291,6 +291,9 @@ func ListFiles(path string) *Pipe { // Slice creates a pipe containing each element of the supplied slice of // strings, one per line. func Slice(s []string) *Pipe { + if len(s) <= 0 { + return Echo(strings.Join(s, "")) + } return Echo(strings.Join(s, "\n") + "\n") } diff --git a/script_test.go b/script_test.go index f87b610..38e96ba 100644 --- a/script_test.go +++ b/script_test.go @@ -1075,6 +1075,10 @@ func TestListFiles_OutputsSingleFileGivenFilePath(t *testing.T) { } } +func TestListFiles_DoesNotOutputNewLineIfProvidedSliceIsEmpty(t *testing.T) { + t.Parallel() +} + func TestListFiles_OutputsAllFilesMatchingSpecifiedGlobExpression(t *testing.T) { t.Parallel() want := filepath.Clean("testdata/multiple_files/1.txt\ntestdata/multiple_files/2.txt\n") From 12bf1718776fe5593c550beebf8666a9cbb2671b Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Tue, 3 May 2022 00:41:59 -0400 Subject: [PATCH 02/11] add todo nnote --- script_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/script_test.go b/script_test.go index 38e96ba..b61f188 100644 --- a/script_test.go +++ b/script_test.go @@ -1076,6 +1076,8 @@ func TestListFiles_OutputsSingleFileGivenFilePath(t *testing.T) { } func TestListFiles_DoesNotOutputNewLineIfProvidedSliceIsEmpty(t *testing.T) { + // TODO: Add unit tests + t.Parallel() } From 21d3ec17f249e2db2097d661181154dd9126e2b1 Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Mon, 9 May 2022 23:28:51 -0400 Subject: [PATCH 03/11] added passing test --- script_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/script_test.go b/script_test.go index b61f188..8d03c90 100644 --- a/script_test.go +++ b/script_test.go @@ -1126,6 +1126,23 @@ func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(t *testing.T) { } } +func TestSliceProducesNoElementsWhenProvidedWithAnEmptyList(t *testing.T) { + t.Parallel() + + // TODO: Properly add tests + want := "" + got, err := script.ListFiles("../example").String() + //got, err := script.Slice([]string{}).String() + + if err != nil { + t.Fatal(err) + } + + if !cmp.Equal(want, got) { + t.Error(cmp.Diff(want, got)) + } +} + func TestStdinReadsFromProgramStandardInput(t *testing.T) { t.Parallel() // dummy test to prove coverage From 308cdc63f25e506229997389fc42466395e7182d Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Mon, 9 May 2022 23:34:58 -0400 Subject: [PATCH 04/11] removed commented out string --- script_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/script_test.go b/script_test.go index 8d03c90..13484c6 100644 --- a/script_test.go +++ b/script_test.go @@ -1132,7 +1132,6 @@ func TestSliceProducesNoElementsWhenProvidedWithAnEmptyList(t *testing.T) { // TODO: Properly add tests want := "" got, err := script.ListFiles("../example").String() - //got, err := script.Slice([]string{}).String() if err != nil { t.Fatal(err) From 195bc2f491ced2d0b786c633f2a3eecdc85afb53 Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Tue, 10 May 2022 19:53:02 -0400 Subject: [PATCH 05/11] removed tests for list files and moved them --- script_test.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/script_test.go b/script_test.go index 13484c6..d43d362 100644 --- a/script_test.go +++ b/script_test.go @@ -1075,12 +1075,6 @@ func TestListFiles_OutputsSingleFileGivenFilePath(t *testing.T) { } } -func TestListFiles_DoesNotOutputNewLineIfProvidedSliceIsEmpty(t *testing.T) { - // TODO: Add unit tests - - t.Parallel() -} - func TestListFiles_OutputsAllFilesMatchingSpecifiedGlobExpression(t *testing.T) { t.Parallel() want := filepath.Clean("testdata/multiple_files/1.txt\ntestdata/multiple_files/2.txt\n") From 7c6bf020a0f42d9f6e95b22a8ebaf0b6e4233d65 Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Tue, 10 May 2022 19:53:55 -0400 Subject: [PATCH 06/11] removed todo --- script_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/script_test.go b/script_test.go index d43d362..0d3b574 100644 --- a/script_test.go +++ b/script_test.go @@ -1123,7 +1123,6 @@ func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(t *testing.T) { func TestSliceProducesNoElementsWhenProvidedWithAnEmptyList(t *testing.T) { t.Parallel() - // TODO: Properly add tests want := "" got, err := script.ListFiles("../example").String() From ea4b50d6a361e8397b65de8f6fcdaff7e6591c46 Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Tue, 10 May 2022 20:00:40 -0400 Subject: [PATCH 07/11] updated test to include an empty list --- script_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/script_test.go b/script_test.go index 0d3b574..75c2221 100644 --- a/script_test.go +++ b/script_test.go @@ -6,6 +6,7 @@ import ( "errors" "fmt" "io" + "log" "os" "os/exec" "path/filepath" @@ -1124,7 +1125,7 @@ func TestSliceProducesNoElementsWhenProvidedWithAnEmptyList(t *testing.T) { t.Parallel() want := "" - got, err := script.ListFiles("../example").String() + got, err := script.Slice([]string{}).String() if err != nil { t.Fatal(err) From 99fc5ae3dcbe505907bfe88032aa2c6dfaf879dc Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Sat, 14 May 2022 00:00:53 -0400 Subject: [PATCH 08/11] removed log package ... --- script_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/script_test.go b/script_test.go index 75c2221..cc95799 100644 --- a/script_test.go +++ b/script_test.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "log" "os" "os/exec" "path/filepath" From 1786a6de04eb429345fbd4af7e09bec98bf8ef8c Mon Sep 17 00:00:00 2001 From: Harun Sheikhali Date: Fri, 26 Aug 2022 17:41:46 -0400 Subject: [PATCH 09/11] added suggestions --- script.go | 11 ++++++----- script_test.go | 5 +---- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/script.go b/script.go index 6715579..791de28 100644 --- a/script.go +++ b/script.go @@ -288,8 +288,8 @@ func ListFiles(path string) *Pipe { // Slice creates a pipe containing each element of the supplied slice of // strings, one per line. func Slice(s []string) *Pipe { - if len(s) <= 0 { - return Echo(strings.Join(s, "")) + if len(s) == 0 { + return NewPipe() } return Echo(strings.Join(s, "\n") + "\n") } @@ -548,9 +548,10 @@ func (p *Pipe) First(n int) *Pipe { // easier to read: // // 10 apple -// 4 banana -// 2 orange -// 1 kumquat +// +// 4 banana +// 2 orange +// 1 kumquat func (p *Pipe) Freq() *Pipe { freq := map[string]int{} type frequency struct { diff --git a/script_test.go b/script_test.go index 8bc0bf0..5f24e6f 100644 --- a/script_test.go +++ b/script_test.go @@ -1126,16 +1126,13 @@ func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(t *testing.T) { } } -func TestSliceProducesNoElementsWhenProvidedWithAnEmptyList(t *testing.T) { +func TestSliceGivenEmptySliceProducesEmptyPipe(t *testing.T) { t.Parallel() - want := "" got, err := script.Slice([]string{}).String() - if err != nil { t.Fatal(err) } - if !cmp.Equal(want, got) { t.Error(cmp.Diff(want, got)) } From b3566e4b5b7013f7b0a4a87361ef85f75d20695d Mon Sep 17 00:00:00 2001 From: Harun Date: Fri, 26 Aug 2022 17:43:32 -0400 Subject: [PATCH 10/11] fixing commit history --- script_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script_test.go b/script_test.go index 5f24e6f..a3c38d6 100644 --- a/script_test.go +++ b/script_test.go @@ -1128,7 +1128,7 @@ func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(t *testing.T) { func TestSliceGivenEmptySliceProducesEmptyPipe(t *testing.T) { t.Parallel() - want := "" + want := "\n" got, err := script.Slice([]string{}).String() if err != nil { t.Fatal(err) From f6676bdff16b872fb6a926f8f44c6b14bd5b9ac4 Mon Sep 17 00:00:00 2001 From: Harun Date: Fri, 26 Aug 2022 17:44:09 -0400 Subject: [PATCH 11/11] fixing commit history --- script_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script_test.go b/script_test.go index a3c38d6..5f24e6f 100644 --- a/script_test.go +++ b/script_test.go @@ -1128,7 +1128,7 @@ func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(t *testing.T) { func TestSliceGivenEmptySliceProducesEmptyPipe(t *testing.T) { t.Parallel() - want := "\n" + want := "" got, err := script.Slice([]string{}).String() if err != nil { t.Fatal(err)