-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtoken_test.go
73 lines (65 loc) · 1.42 KB
/
token_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
package spf
import "testing"
func TestTokenSyntaxValidation(t *testing.T) {
type TokenTestCase struct {
token *token
delimiter rune
expected bool
}
tests := []TokenTestCase{
{nil, rune('='), false},
{
&token{
tInclude, qPlus, "matching.com",
}, rune(':'), true,
},
{
&token{
tInclude, qPlus, "",
}, rune(':'), false,
},
{
&token{
tErr, qErr, "",
}, rune('='), true,
},
{
&token{
tAll, qMinus, "matching.com",
}, rune(':'), true,
},
{
&token{
tAll, qMinus, "matching.com",
}, rune('='), false,
},
}
for _, test := range tests {
token := test.token
delimiter := test.delimiter
expected := test.expected
if checkTokenSyntax(token, delimiter) != expected {
t.Errorf(
"Error: For token %v, delimiter %v got result %v, expected %v\n",
*token, delimiter, !expected, expected)
}
}
}
func TestTokenString(t *testing.T) {
types := []tokenType{tVersion, tAll, tIP4, tIP6, tMX, tPTR, tInclude,
tRedirect, tExists, tExp}
strs := []string{
"v", "all", "ip4", "ip6", "mx", "ptr", "include", "redirect", "exists",
"exp",
}
if len(types) != len(strs) {
t.Errorf("Lengths for types and strs unequal - %d and %d",
len(types), len(strs))
}
for idx := 0; idx < len(types); idx++ {
if types[idx].String() != strs[idx] {
t.Errorf("Error while running token.String. Got %q, expected %q",
types[idx].String(), strs[idx])
}
}
}