-
-
Notifications
You must be signed in to change notification settings - Fork 335
#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) { | ||
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. Actually, since the result of func TestSliceGivenEmptySliceProducesEmptyPipe 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. And we could probably use an extra test here for the non-empty slice behaviour, couldn't we? (The fact that we don't have one is entirely on me, but this is a good chance to add it.) 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. Doesn't this test cover non-empty slice behaviour ? func TestSliceProducesElementsOfSpecifiedSliceOnePerLine(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)
}
if !cmp.Equal(want, got) {
t.Error(cmp.Diff(want, got))
}
} |
||
t.Parallel() | ||
|
||
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. This is great, but it's house style with this project to use no blank lines within functions. To my mind, they just make the function longer without providing any benefit. 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. This is a thing I have built into muscle memory from my typescript work.. I noticed some Go devs prefer not to have a bunch of blank lines |
||
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
s
has zero elements, there's no need to callstrings.Join
in 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!