-
-
Notifications
You must be signed in to change notification settings - Fork 320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(slice): fix bug in slice that produces new line for empty input slice #216
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1375,15 +1375,34 @@ func TestReadAutoCloser_ReadsAllDataFromSourceAndClosesItAutomatically(t *testin | |
} | ||
} | ||
|
||
func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(t *testing.T) { | ||
func TestSlice_(t *testing.T) { | ||
t.Parallel() | ||
want := "1\n2\n3\n" | ||
got, err := script.Slice([]string{"1", "2", "3"}).String() | ||
if err != nil { | ||
t.Fatal(err) | ||
tests := []struct { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems a shame to have a table test with just two cases, doesn't it? Especially as they're different cases, not two examples of the same behaviour. Wouldn't you rather just structure this as two separate tests? That tends to make each test clearer, more focused, and easier to understand. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done! |
||
name string | ||
input []string | ||
want string | ||
}{ | ||
{ | ||
name: "produces elements of specified slice one per line", | ||
input: []string{"1", "2", "3"}, | ||
want: "1\n2\n3\n", | ||
}, | ||
{ | ||
name: "given empty slice produces empty pipe", | ||
input: []string{}, | ||
want: "", | ||
}, | ||
} | ||
if !cmp.Equal(want, got) { | ||
t.Error(cmp.Diff(want, got)) | ||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
got, err := script.Slice(test.input).String() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if !cmp.Equal(test.want, got) { | ||
t.Error(cmp.Diff(test.want, got)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.