-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcskv_test.go
87 lines (81 loc) · 2.16 KB
/
cskv_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package cskv
import (
"reflect"
"testing"
)
func TestNew(t *testing.T) {
type args struct {
kv string
}
tests := []struct {
name string
args args
want KV
}{
{"empty string", args{kv: ""}, KV{kv: map[string]string{}}},
{"bad single value string", args{kv: "key"}, KV{kv: map[string]string{}}},
{"key but no value", args{kv: "key:"}, KV{kv: map[string]string{"key": ""}, Str: "key:"}},
{"value but no key", args{kv: ":value"}, KV{kv: map[string]string{"": "value"}, Str: ":value"}},
{"key:value", args{kv: "key:value"}, KV{kv: map[string]string{"key": "value"}, Str: "key:value"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := New(tt.args.kv); !reflect.DeepEqual(got, tt.want) {
t.Errorf("New() = %+v, want %+v", got, tt.want)
}
})
}
}
func TestKV_String(t *testing.T) {
knv := make(map[string]string)
knv["key"] = ""
vnk := make(map[string]string)
vnk[""] = "value"
kv := make(map[string]string)
kv["key"] = "value"
tests := []struct {
name string
kv *KV
want string
}{
{"empty KV", &KV{kv: make(map[string]string)}, ""},
{"key but no value", &KV{kv: knv}, "key:"},
{"no key but value", &KV{kv: vnk}, ":value"},
{"key:value", &KV{kv: kv}, "key:value"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.kv.String(); got != tt.want {
t.Errorf("KV.String() = %v, want %v", got, tt.want)
}
})
}
}
func TestUse(t *testing.T) {
knv := make(map[string]string)
knv["key"] = ""
vnk := make(map[string]string)
vnk[""] = "value"
kv := make(map[string]string)
kv["key"] = "value"
type args struct {
kvmap map[string]string
}
tests := []struct {
name string
args args
want KV
}{
{"empty map", args{kvmap: make(map[string]string)}, KV{kv: make(map[string]string)}},
{"key no value", args{kvmap: knv}, KV{kv: knv, Str: "key:"}},
{"value no key", args{kvmap: vnk}, KV{kv: vnk, Str: ":value"}},
{"key:value", args{kvmap: kv}, KV{kv: kv, Str: "key:value"}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := Use(tt.args.kvmap); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Use() = %+v, want %+v", got, tt.want)
}
})
}
}