@@ -40,16 +40,17 @@ func TestCompareDomainName(t *testing.T) {
40
40
41
41
func TestSplit (t * testing.T ) {
42
42
splitter := map [string ]int {
43
- "www.miek.nl." : 3 ,
44
- "www.miek.nl" : 3 ,
45
- "www..miek.nl" : 4 ,
46
- `www\.miek.nl.` : 2 ,
47
- `www\\.miek.nl.` : 3 ,
48
- "." : 0 ,
49
- "nl." : 1 ,
50
- "nl" : 1 ,
51
- "com." : 1 ,
52
- ".com." : 2 ,
43
+ "www.miek.nl." : 3 ,
44
+ "www.miek.nl" : 3 ,
45
+ "www..miek.nl" : 4 ,
46
+ `www\.miek.nl.` : 2 ,
47
+ `www\\.miek.nl.` : 3 ,
48
+ `www\\\.miek.nl.` : 2 ,
49
+ "." : 0 ,
50
+ "nl." : 1 ,
51
+ "nl" : 1 ,
52
+ "com." : 1 ,
53
+ ".com." : 2 ,
53
54
}
54
55
for s , i := range splitter {
55
56
if x := len (Split (s )); x != i {
@@ -79,12 +80,32 @@ func TestSplit2(t *testing.T) {
79
80
}
80
81
}
81
82
83
+ func TestNextLabel (t * testing.T ) {
84
+ type next struct {
85
+ string
86
+ int
87
+ }
88
+ nexts := map [next ]int {
89
+ {"" , 1 }: 0 ,
90
+ {"www.miek.nl." , 0 }: 4 ,
91
+ {"www.miek.nl." , 4 }: 9 ,
92
+ {"www.miek.nl." , 9 }: 12 ,
93
+ }
94
+ for s , i := range nexts {
95
+ x , ok := NextLabel (s .string , s .int )
96
+ if i != x {
97
+ t .Errorf ("label should be %d, got %d, %t: nexting %d, %s" , i , x , ok , s .int , s .string )
98
+ }
99
+ }
100
+ }
101
+
82
102
func TestPrevLabel (t * testing.T ) {
83
103
type prev struct {
84
104
string
85
105
int
86
106
}
87
107
prever := map [prev ]int {
108
+ {"" , 1 }: 0 ,
88
109
{"www.miek.nl." , 0 }: 12 ,
89
110
{"www.miek.nl." , 1 }: 9 ,
90
111
{"www.miek.nl." , 2 }: 4 ,
@@ -237,3 +258,63 @@ func BenchmarkIsSubDomain(b *testing.B) {
237
258
IsSubDomain ("miek.nl." , "aa.example.com." )
238
259
}
239
260
}
261
+
262
+ func BenchmarkNextLabelSimple (b * testing.B ) {
263
+ b .ReportAllocs ()
264
+ for i := 0 ; i < b .N ; i ++ {
265
+ NextLabel ("www.example.com" , 0 )
266
+ NextLabel ("www.example.com" , 5 )
267
+ NextLabel ("www.example.com" , 12 )
268
+ }
269
+ }
270
+
271
+ func BenchmarkPrevLabelSimple (b * testing.B ) {
272
+ b .ReportAllocs ()
273
+ for i := 0 ; i < b .N ; i ++ {
274
+ PrevLabel ("www.example.com" , 0 )
275
+ PrevLabel ("www.example.com" , 5 )
276
+ PrevLabel ("www.example.com" , 12 )
277
+ }
278
+ }
279
+
280
+ func BenchmarkNextLabelComplex (b * testing.B ) {
281
+ b .ReportAllocs ()
282
+ for i := 0 ; i < b .N ; i ++ {
283
+ NextLabel (`www\.example.com` , 0 )
284
+ NextLabel (`www\\.example.com` , 0 )
285
+ NextLabel (`www\\\.example.com` , 0 )
286
+ }
287
+ }
288
+
289
+ func BenchmarkPrevLabelComplex (b * testing.B ) {
290
+ b .ReportAllocs ()
291
+ for i := 0 ; i < b .N ; i ++ {
292
+ PrevLabel (`www\.example.com` , 10 )
293
+ PrevLabel (`www\\.example.com` , 10 )
294
+ PrevLabel (`www\\\.example.com` , 10 )
295
+ }
296
+ }
297
+
298
+ func BenchmarkNextLabelMixed (b * testing.B ) {
299
+ b .ReportAllocs ()
300
+ for i := 0 ; i < b .N ; i ++ {
301
+ NextLabel ("www.example.com" , 0 )
302
+ NextLabel (`www\.example.com` , 0 )
303
+ NextLabel ("www.example.com" , 5 )
304
+ NextLabel (`www\\.example.com` , 0 )
305
+ NextLabel ("www.example.com" , 12 )
306
+ NextLabel (`www\\\.example.com` , 0 )
307
+ }
308
+ }
309
+
310
+ func BenchmarkPrevLabelMixed (b * testing.B ) {
311
+ b .ReportAllocs ()
312
+ for i := 0 ; i < b .N ; i ++ {
313
+ PrevLabel ("www.example.com" , 0 )
314
+ PrevLabel (`www\.example.com` , 10 )
315
+ PrevLabel ("www.example.com" , 5 )
316
+ PrevLabel (`www\\.example.com` , 10 )
317
+ PrevLabel ("www.example.com" , 12 )
318
+ PrevLabel (`www\\\.example.com` , 10 )
319
+ }
320
+ }
0 commit comments