Skip to content
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

Merged
merged 4 commits into from
Oct 20, 2024

Conversation

mahadzaryab1
Copy link
Contributor

@mahadzaryab1 mahadzaryab1 commented Oct 19, 2024

This PR fixes #110 by handling an empty input into the Slice function.

Added a new unit test

✔ Slice produces elements of specified slice one per line (0.00s)

Copy link
Owner

@bitfield bitfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job! Not to minimise your work in the least, which is very welcome, but it's a little surprising that a fix like this has taken this long, isn't it?

script_test.go Outdated
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!

@mahadzaryab1 mahadzaryab1 requested a review from bitfield October 19, 2024 18:41
script.go Outdated
@@ -182,6 +182,9 @@ func Post(url string) *Pipe {

// Slice creates a pipe containing each element of s, one per line.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Slice creates a pipe containing each element of s, one per line.
// Slice creates a pipe containing each element of s, one per line. If s is
// empty or nil, then the pipe is empty.

@mahadzaryab1 mahadzaryab1 requested a review from bitfield October 20, 2024 13:11
Copy link
Owner

@bitfield bitfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks a lot!

@bitfield bitfield merged commit dd8d444 into bitfield:master Oct 20, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ListFiles() Produces an Unwanted Newline Character When Zero Files Are Matched
2 participants