forked from viamrobotics/goutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_test.go
45 lines (40 loc) · 972 Bytes
/
string_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package utils
import (
"fmt"
"testing"
"go.viam.com/test"
)
func TestRandomAlphaString(t *testing.T) {
for _, tc := range []int{-1, 0, 1, 2, 3, 4, 5} {
t.Run(fmt.Sprintf("size %d", tc), func(t *testing.T) {
str := RandomAlphaString(tc)
if tc <= 0 {
test.That(t, str, test.ShouldBeEmpty)
return
}
test.That(t, str, test.ShouldHaveLength, tc)
})
}
}
func TestStringSet(t *testing.T) {
ss := NewStringSet("foo")
_, ok := ss["foo"]
test.That(t, ok, test.ShouldBeTrue)
}
func TestStringSliceRemove(t *testing.T) {
for idx, tc := range []struct {
In []string
At int
Out []string
}{
{[]string{}, 0, []string{}},
{[]string{}, 1, []string{}},
{[]string{"1"}, 1, []string{"1"}},
{[]string{"1", "2"}, 1, []string{"1"}},
{[]string{"1", "2", "3", "4"}, 2, []string{"1", "2", "4"}},
} {
t.Run(fmt.Sprintf("%d", idx), func(t *testing.T) {
test.That(t, StringSliceRemove(tc.In, tc.At), test.ShouldResemble, tc.Out)
})
}
}