forked from viamrobotics/goutils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_test.go
65 lines (56 loc) · 1.36 KB
/
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)
// Adding a new value
ss.Add("bar")
_, ok = ss["bar"]
test.That(t, ok, test.ShouldBeTrue)
_, ok = ss["foo"]
test.That(t, ok, test.ShouldBeTrue)
// Removing a value
ss.Remove("bar")
_, ok = ss["bar"]
test.That(t, ok, test.ShouldBeFalse)
_, ok = ss["foo"]
test.That(t, ok, test.ShouldBeTrue)
// Removing a value that doesn't exist
ss.Remove("no-op")
_, 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)
})
}
}