-
-
Notifications
You must be signed in to change notification settings - Fork 341
#110 - Fix Slice bug producing a \n when provided with an empty slice #115
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
base: master
Are you sure you want to change the base?
Changes from 8 commits
04c4e92
12bf171
21d3ec1
308cdc6
195bc2f
7c6bf02
ea4b50d
99fc5ae
32cfe70
1786a6d
b3566e4
f6676bd
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 |
|---|---|---|
|
|
@@ -1120,6 +1120,21 @@ func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestSliceProducesNoElementsWhenProvidedWithAnEmptyList(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)) | ||
| } | ||
| } | ||
|
|
||
| func TestStdinReadsFromProgramStandardInput(t *testing.T) { | ||
| t.Parallel() | ||
| // dummy test to prove coverage | ||
|
|
||
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.
It seems unlikely that
len(s)could be less than zero, doesn't it?Clearly the special case here is where the length equals zero, but it seems a shame to duplicate virtually the whole function for this case. Actually, the difference in behaviour is whether or not we add a final newline. It seems slightly neater to me to isolate just that in the special-case branch.
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.
And if
shas zero elements, there's no need to callstrings.Joinin any case: there's nothing to join.Instead, what about:
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.
That's a very good point ! @bitfield thanks!