forked from mpdroog/hash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
113 lines (108 loc) · 4.35 KB
/
main_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
package main
import (
"testing"
)
// https://github.com/jpmens/diablo/blob/master/lib/hashfeed.c#L148
func TestHash(t *testing.T) {
matches := map[int]uint32{
0: 0x49367f83,
1: 0x1549367f,
2: 0xd5154936,
3: 0xead51549,
4: 0x92ead515,
5: 0xd992ead5,
6: 0x28d992ea,
7: 0xba28d992,
8: 0x1fba28d9,
9: 0x871fba28,
10: 0x9c871fba,
11: 0x559c871f,
12: 0x38559c87,
}
for offset, expect := range matches {
res := hash("<>", offset)
if res != expect {
t.Fatalf("Hash mismatch. expect=%x res=%x", expect, res)
}
}
}
// https://github.com/jpmens/diablo/blob/master/lib/hashfeed.c#L223
func TestMatch(t *testing.T) {
feed := "1-120/360:8"
valid := []string{
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<part80of143.8&[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<part81of143.8&[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
}
invalid := []string{
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<part37of143.3cyACN2UfykYsavFok&[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<part121of143.8&[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<part116of143.8&[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
"<[email protected]>",
}
for _, msgid := range valid {
ok, e := match(msgid, feed)
if e != nil {
t.Fatal(e)
}
if ok != true {
t.Fatalf("Msgid(%s) failed", msgid)
}
}
for _, msgid := range invalid {
ok, e := match(msgid, feed)
if e != nil {
t.Fatal(e)
}
if ok != false {
t.Fatalf("Msgid(%s) should fail but didn't", msgid)
}
}
}