-
Notifications
You must be signed in to change notification settings - Fork 3
/
rucksack_test.go
47 lines (40 loc) · 1.06 KB
/
rucksack_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
package rucksack_test
import (
"reflect"
"testing"
. "github.com/bsm/rucksack/v4"
)
func expectTags(t *testing.T, s string, exp []string) {
t.Helper()
if got := Tags(s); !reflect.DeepEqual(exp, got) {
t.Errorf("expected %v, got %v", exp, got)
}
}
func TestTags(t *testing.T) {
t.Run("blank", func(t *testing.T) {
expectTags(t, "", []string{})
})
t.Run("simple", func(t *testing.T) {
expectTags(t, "a,b", []string{"a", "b"})
})
t.Run("spaced", func(t *testing.T) {
expectTags(t, "a , b", []string{"a", "b"})
})
}
func expectFields(t *testing.T, s string, exp map[string]interface{}) {
t.Helper()
if got := Fields(s); !reflect.DeepEqual(exp, got) {
t.Errorf("expected %v, got %v", exp, got)
}
}
func TestFields(t *testing.T) {
t.Run("blank", func(t *testing.T) {
expectFields(t, "", nil)
})
t.Run("simple", func(t *testing.T) {
expectFields(t, "k1:v1,k2:v2", map[string]interface{}{"k1": "v1", "k2": "v2"})
})
t.Run("with spaces", func(t *testing.T) {
expectFields(t, " k1:v1 , k2:v2", map[string]interface{}{"k1": "v1", "k2": "v2"})
})
}