Skip to content

Commit

Permalink
add stringmap test
Browse files Browse the repository at this point in the history
  • Loading branch information
cesartw committed Nov 12, 2021
1 parent 102230e commit 7922df9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions sliceutil/sliceutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ func TestFilterInt(t *testing.T) {
})
}
}

func TestChooseString(t *testing.T) {
tests := []struct {
in []string
Expand Down Expand Up @@ -500,3 +501,30 @@ func TestRemoveString(t *testing.T) {
})
}
}

func TestStringMap(t *testing.T) {
cases := []struct {
in []string
want []string
f func(string) string
}{
{
in: []string{"a", "b", "c"},
want: []string{"", "", ""},
f: func(string) string { return "" },
},
{
in: []string{"a", "b", "c"},
want: []string{"aa", "bb", "cc"},
f: func(c string) string { return c + c },
},
}
for _, tc := range cases {
t.Run("", func(t *testing.T) {
out := StringMap(tc.in, tc.f)
if !reflect.DeepEqual(tc.want, out) {
t.Errorf("\nout: %#v\nwant: %#v\n", out, tc.want)
}
})
}
}

0 comments on commit 7922df9

Please sign in to comment.