-
Notifications
You must be signed in to change notification settings - Fork 5
/
type_scan_test.go
148 lines (128 loc) · 4.26 KB
/
type_scan_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
package hashuri
import (
"testing"
)
func TestTypeScan(t *testing.T) {
tests := []struct{
Value string
Expected Type
}{
{
Value: "hash://crunch/fedcba9876543210",
Expected: Type{
Algorithm: "crunch",
Hash: "fedcba9876543210",
RawQuery: "",
Fragment: "",
},
},
{
Value: "hash://crunch/fedcba9876543210?apple=one&banana=۲&cherry=3",
Expected: Type{
Algorithm: "crunch",
Hash: "fedcba9876543210",
RawQuery: "apple=one&banana=۲&cherry=3",
Fragment: "",
},
},
{
Value: "hash://crunch/fedcba9876543210#over-there",
Expected: Type{
Algorithm: "crunch",
Hash: "fedcba9876543210",
RawQuery: "",
Fragment: "over-there",
},
},
{
Value: "hash://crunch/fedcba9876543210?apple=one&banana=۲&cherry=3#over-there",
Expected: Type{
Algorithm: "crunch",
Hash: "fedcba9876543210",
RawQuery: "apple=one&banana=۲&cherry=3",
Fragment: "over-there",
},
},
{
Value: "hash://کوچک شدن/fedcba9876543210?apple=one&banana=۲&cherry=3#آنجا",
Expected: Type{
Algorithm: "کوچک شدن",
Hash: "fedcba9876543210",
RawQuery: "apple=one&banana=۲&cherry=3",
Fragment: "آنجا",
},
},
}
for testNumber, test := range tests {
{
var actualType Type
actualType.Algorithm = "ERROR-Algorithm"
actualType.Hash = "ERROR-Hash"
actualType.RawQuery = "ERROR-RawQuery"
actualType.Fragment = "ERROR-Fragment"
if err := actualType.Scan(test.Value); nil != err {
t.Errorf("For test #%d, did not expect an error, but actually got one: (%T) %q", testNumber, err, err)
t.Errorf("\tvalue: %q", test.Value)
t.Errorf("\tactual: %q", actualType.String())
continue
}
if expected, actual := test.Expected.Algorithm, actualType.Algorithm; expected != actual {
t.Errorf("For test #%d, algorithm expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
if expected, actual := test.Expected.Hash, actualType.Hash; expected != actual {
t.Errorf("For test #%d, hash expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
if expected, actual := test.Expected.RawQuery, actualType.RawQuery; expected != actual {
t.Errorf("For test #%d, raw query expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
if expected, actual := test.Expected.Fragment, actualType.Fragment; expected != actual {
t.Errorf("For test #%d, fragment expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
}
{
var actualType Type
actualType.Algorithm = "ERROR-Algorithm"
actualType.Hash = "ERROR-Hash"
actualType.RawQuery = "ERROR-RawQuery"
actualType.Fragment = "ERROR-Fragment"
var bytes []byte = []byte(test.Value)
if err := actualType.Scan(bytes); nil != err {
t.Errorf("For test #%d, did not expect an error, but actually got one: (%T) %q", testNumber, err, err)
t.Errorf("\tvalue: %q", test.Value)
t.Errorf("\tactual: %q", actualType.String())
continue
}
if expected, actual := test.Expected.Algorithm, actualType.Algorithm; expected != actual {
t.Errorf("For test #%d, algorithm expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
if expected, actual := test.Expected.Hash, actualType.Hash; expected != actual {
t.Errorf("For test #%d, hash expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
if expected, actual := test.Expected.RawQuery, actualType.RawQuery; expected != actual {
t.Errorf("For test #%d, raw query expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
if expected, actual := test.Expected.Fragment, actualType.Fragment; expected != actual {
t.Errorf("For test #%d, fragment expected %q, but actually got %q.", testNumber, expected, actual)
continue
}
}
{
var actualType Type
actualType.Algorithm = "ERROR-Algorithm"
actualType.Hash = "ERROR-Hash"
actualType.RawQuery = "ERROR-RawQuery"
actualType.Fragment = "ERROR-Fragment"
if err := actualType.Scan(5); nil == err {
t.Errorf("For test #%d, expected an error, but did not actually get one: (%T) %q", testNumber, err, err)
continue
}
}
}
}