Skip to content

Commit

Permalink
aghstrings: mk cloning correct
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Apr 6, 2021
1 parent 8009ba6 commit b858057
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
16 changes: 8 additions & 8 deletions internal/aghstrings/strings.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import (
"strings"
)

// CloneSlice returns the exact copy of a.
func CloneSlice(a []string) (b []string) {
return append(b, a...)
}

// CloneSliceOrEmpty returns the copy of a or empty strings slice if a is nil.
func CloneSliceOrEmpty(a []string) (b []string) {
if len(a) == 0 {
return []string{}
return append([]string{}, a...)
}

// CloneSlice returns the exact copy of a.
func CloneSlice(a []string) (b []string) {
if a == nil {
return nil
}

return CloneSlice(a)
return CloneSliceOrEmpty(a)
}

// InSlice checks if string is in the slice of strings.
Expand Down
2 changes: 1 addition & 1 deletion internal/aghstrings/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestCloneSlice_family(t *testing.T) {
})

t.Run("cloneslice_empty", func(t *testing.T) {
assert.Nil(t, CloneSlice([]string{}))
assert.Equal(t, []string{}, CloneSlice([]string{}))
})

t.Run("clonesliceorempty_nil", func(t *testing.T) {
Expand Down

0 comments on commit b858057

Please sign in to comment.