Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(442)

Side by Side Diff: src/pkg/net/dnsname_test.go

Issue 12662043: code review 12662043: net: avoid string operation and make valid domain names... (Closed)
Patch Set: diff -r 2a74ed09bf00 https://code.google.com/p/go/ Created 10 years, 7 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pkg/net/dnsclient.go ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
OLDNEW
« no previous file with comments | « src/pkg/net/dnsclient.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b