Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Owner

Choose a reason for hiding this comment

The 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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))
}
})
}
}

Expand Down
Loading