1
0
Fork 0
mirror of https://github.com/Luzifer/go_helpers.git synced 2024-12-26 14:01:20 +00:00
go_helpers/str/slice_test.go

45 lines
1 KiB
Go
Raw Normal View History

package str_test
2016-04-15 23:13:39 +00:00
import (
"testing"
2016-04-15 23:13:39 +00:00
. "github.com/Luzifer/go_helpers/v2/str"
"github.com/stretchr/testify/assert"
2016-04-15 23:13:39 +00:00
)
func TestAppendIfMissing(t *testing.T) {
sl := []string{
"test1",
"test2",
"test3",
}
// should not append existing elements
assert.Len(t, AppendIfMissing(sl, "test1"), 3)
assert.Len(t, AppendIfMissing(sl, "test2"), 3)
assert.Len(t, AppendIfMissing(sl, "test3"), 3)
// should append not existing elements
assert.Len(t, AppendIfMissing(sl, "test4"), 4)
assert.Len(t, AppendIfMissing(sl, "test5"), 4)
assert.Len(t, AppendIfMissing(sl, "test6"), 4)
}
func TestStringInSlice(t *testing.T) {
sl := []string{
"test1",
"test2",
"test3",
}
// should find elements of slice
assert.True(t, StringInSlice("test1", sl))
assert.True(t, StringInSlice("test2", sl))
assert.True(t, StringInSlice("test3", sl))
// should not find elements not in slice
assert.False(t, StringInSlice("test4", sl))
assert.False(t, StringInSlice("test5", sl))
assert.False(t, StringInSlice("test6", sl))
}