-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
key_test.go
69 lines (57 loc) · 1.2 KB
/
key_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
package httpsfv
import (
"strings"
"testing"
)
func TestKeyMarshalSFV(t *testing.T) {
t.Parallel()
data := []struct {
in string
expected string
valid bool
}{
{"f1oo", "f1oo", true},
{"*foo0", "*foo0", true},
{"", "", false},
{"1foo", "", false},
{"fOo", "", false},
}
var b strings.Builder
for _, d := range data {
b.Reset()
err := marshalKey(&b, d.in)
if d.valid && err != nil {
t.Errorf("error not expected for %v, got %v", d.in, err)
} else if !d.valid && err == nil {
t.Errorf("error expected for %v, got %v", d.in, err)
}
if b.String() != d.expected {
t.Errorf("got %v; want %v", b.String(), d.expected)
}
}
}
func TestParseKey(t *testing.T) {
t.Parallel()
data := []struct {
in string
expected string
err bool
}{
{"t", "t", false},
{"tok", "tok", false},
{"*k-.*", "*k-.*", false},
{"k=", "k", false},
{"", "", true},
{"é", "", true},
}
for _, d := range data {
s := &scanner{data: d.in}
i, err := parseKey(s)
if d.err && err == nil {
t.Errorf("parseKey(%s): error expected", d.in)
}
if !d.err && d.expected != i {
t.Errorf("parseKey(%s) = %v, %v; %v, <nil> expected", d.in, i, err, d.expected)
}
}
}