Skip to content

Commit

Permalink
aghstrings: fix lil bug
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Apr 6, 2021
1 parent 0dd19f2 commit 8009ba6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions internal/aghstrings/strings.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
// Package aghstrings contains utilities dealing with strings.
package aghstrings

import "strings"
import (
"strings"
)

// CloneSlice returns the exact copy of a.
func CloneSlice(a []string) (b []string) {
Expand All @@ -10,7 +12,7 @@ func CloneSlice(a []string) (b []string) {

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

Expand Down
12 changes: 10 additions & 2 deletions internal/aghstrings/strings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,29 @@ import (
)

func TestCloneSlice_family(t *testing.T) {
a := []string{"1", "2", "3"}

t.Run("cloneslice_simple", func(t *testing.T) {
a := []string{"1", "2", "3"}
assert.Equal(t, a, CloneSlice(a))
})

t.Run("cloneslice_nil", func(t *testing.T) {
assert.Nil(t, CloneSlice(nil))
})

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

t.Run("clonesliceorempty_nil", func(t *testing.T) {
assert.Equal(t, []string{}, CloneSliceOrEmpty(nil))
})

t.Run("clonesliceorempty_empty", func(t *testing.T) {
assert.Equal(t, []string{}, CloneSliceOrEmpty([]string{}))
})

t.Run("clonesliceorempty_sameness", func(t *testing.T) {
a := []string{"1", "2"}
assert.Equal(t, CloneSlice(a), CloneSliceOrEmpty(a))
})
}
Expand Down

0 comments on commit 8009ba6

Please sign in to comment.