-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathparse_test.go
97 lines (85 loc) · 2.54 KB
/
parse_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
package hashuri
import (
"testing"
)
func TestParse(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 := Parse(&actualType, 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
}
}
}