Left: | ||
Right: |
OLD | NEW |
---|---|
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package net | 5 package net |
6 | 6 |
7 import ( | 7 import ( |
8 "testing" | 8 "testing" |
9 ) | 9 ) |
10 | 10 |
11 type testCase struct { | 11 type testCase struct { |
12 name string | 12 name string |
13 result bool | 13 result bool |
14 } | 14 } |
15 | 15 |
16 var tests = []testCase{ | 16 var tests = []testCase{ |
17 // RFC2181, section 11. | 17 // RFC2181, section 11. |
18 {"_xmpp-server._tcp.google.com", true}, | 18 {"_xmpp-server._tcp.google.com", true}, |
19 {"_xmpp-server._tcp.google.com", true}, | |
20 {"foo.com", true}, | 19 {"foo.com", true}, |
21 {"1foo.com", true}, | 20 {"1foo.com", true}, |
22 {"26.0.0.73.com", true}, | 21 {"26.0.0.73.com", true}, |
23 {"fo-o.com", true}, | 22 {"fo-o.com", true}, |
24 {"fo1o.com", true}, | 23 {"fo1o.com", true}, |
25 {"foo1.com", true}, | 24 {"foo1.com", true}, |
26 {"a.b..com", false}, | 25 {"a.b..com", false}, |
26 {"a.b-.com", false}, | |
27 {"a.b.com-", false}, | |
28 {"a.b..", false}, | |
29 {"b.com.", true}, | |
27 } | 30 } |
28 | 31 |
29 func getTestCases(ch chan<- testCase) { | 32 func getTestCases(ch chan<- testCase) { |
30 defer close(ch) | 33 defer close(ch) |
31 var char59 = "" | 34 var char59 = "" |
32 var char63 = "" | 35 var char63 = "" |
33 var char64 = "" | 36 var char64 = "" |
34 for i := 0; i < 59; i++ { | 37 for i := 0; i < 59; i++ { |
35 char59 += "a" | 38 char59 += "a" |
36 } | 39 } |
(...skipping 19 matching lines...) Expand all Loading... | |
56 func TestDNSNames(t *testing.T) { | 59 func TestDNSNames(t *testing.T) { |
57 ch := make(chan testCase) | 60 ch := make(chan testCase) |
58 go getTestCases(ch) | 61 go getTestCases(ch) |
59 for tc := range ch { | 62 for tc := range ch { |
60 if isDomainName(tc.name) != tc.result { | 63 if isDomainName(tc.name) != tc.result { |
61 t.Errorf("isDomainName(%v) failed: Should be %v", | 64 t.Errorf("isDomainName(%v) failed: Should be %v", |
62 tc.name, tc.result) | 65 tc.name, tc.result) |
63 } | 66 } |
64 } | 67 } |
65 } | 68 } |
69 | |
70 func BenchmarkDNSNames(b *testing.B) { | |
71 s16 := "0123456789abcdef" | |
bradfitz
2013/08/08 18:03:46
drop all this
volker.dobler
2013/08/08 22:08:08
Done.
| |
72 s65 := s16 + s16 + s16 + s16 | |
73 s64 := s65[:64] | |
74 s63 := s65[:63] | |
75 benchmarks := append(tests, []testCase{ | |
76 {s63, true}, | |
bradfitz
2013/08/08 18:03:46
and just say strings.Repeat("a", 63)
volker.dobler
2013/08/08 22:08:08
Done.
| |
77 {s64, false}, | |
78 }...) | |
79 for n := 0; n < b.N; n++ { | |
80 for i := range benchmarks { | |
bradfitz
2013/08/08 18:03:46
for i, tt := range benchmarks {
volker.dobler
2013/08/08 22:08:08
Done.
| |
81 if isDomainName(benchmarks[i].name) != benchmarks[i].res ult { | |
bradfitz
2013/08/08 18:03:46
tt.name and tt.result
volker.dobler
2013/08/08 22:08:08
Done.
| |
82 b.Fatalf("isDomainName(%q)", benchmarks[i].name) | |
bradfitz
2013/08/08 18:03:46
tt.name
volker.dobler
2013/08/08 22:08:08
Done.
| |
83 } | |
84 } | |
85 } | |
86 } | |
OLD | NEW |