LEFT | RIGHT |
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 "strings" |
8 "testing" | 9 "testing" |
9 ) | 10 ) |
10 | 11 |
11 type testCase struct { | 12 type testCase struct { |
12 name string | 13 name string |
13 result bool | 14 result bool |
14 } | 15 } |
15 | 16 |
16 var tests = []testCase{ | 17 var tests = []testCase{ |
17 // RFC2181, section 11. | 18 // RFC2181, section 11. |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 go getTestCases(ch) | 62 go getTestCases(ch) |
62 for tc := range ch { | 63 for tc := range ch { |
63 if isDomainName(tc.name) != tc.result { | 64 if isDomainName(tc.name) != tc.result { |
64 t.Errorf("isDomainName(%v) failed: Should be %v", | 65 t.Errorf("isDomainName(%v) failed: Should be %v", |
65 tc.name, tc.result) | 66 tc.name, tc.result) |
66 } | 67 } |
67 } | 68 } |
68 } | 69 } |
69 | 70 |
70 func BenchmarkDNSNames(b *testing.B) { | 71 func BenchmarkDNSNames(b *testing.B) { |
71 s16 := "0123456789abcdef" | |
72 s65 := s16 + s16 + s16 + s16 | |
73 s64 := s65[:64] | |
74 s63 := s65[:63] | |
75 benchmarks := append(tests, []testCase{ | 72 benchmarks := append(tests, []testCase{ |
76 » » {s63, true}, | 73 » » {strings.Repeat("a", 63), true}, |
77 » » {s64, false}, | 74 » » {strings.Repeat("a", 64), false}, |
78 }...) | 75 }...) |
79 for n := 0; n < b.N; n++ { | 76 for n := 0; n < b.N; n++ { |
80 » » for i := range benchmarks { | 77 » » for _, tc := range benchmarks { |
81 » » » if isDomainName(benchmarks[i].name) != benchmarks[i].res
ult { | 78 » » » if isDomainName(tc.name) != tc.result { |
82 » » » » b.Fatalf("isDomainName(%q)", benchmarks[i].name) | 79 » » » » b.Errorf("isDomainName(%q) = %v; want %v", tc.na
me, !tc.result, tc.result) |
83 } | 80 } |
84 } | 81 } |
85 } | 82 } |
86 } | 83 } |
LEFT | RIGHT |