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

Delta Between Two Patch Sets: src/pkg/net/dnsname_test.go

Issue 12662043: code review 12662043: net: avoid string operation and make valid domain names... (Closed)
Left Patch Set: diff -r 2a74ed09bf00 https://code.google.com/p/go/ Created 10 years, 7 months ago
Right Patch Set: diff -r b0240b16a8e0 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/net/dnsclient.go ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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
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 }
LEFTRIGHT

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