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

Delta Between Two Patch Sets: src/pkg/bytes/bytes_test.go

Issue 781041: code review 781041: bytes, strings: IndexOfAny (Closed)
Left Patch Set: code review 781041: bytes, strings: IndexOfAny Created 15 years ago
Right Patch Set: code review 781041: bytes, strings: IndexOfAny Created 15 years 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/bytes/bytes.go ('k') | src/pkg/go/doc/doc.go » ('j') | 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 bytes_test 5 package bytes_test
6 6
7 import ( 7 import (
8 . "bytes" 8 . "bytes"
9 "testing" 9 "testing"
10 "unicode" 10 "unicode"
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 BinOpTest{"foo", "f", 0}, 103 BinOpTest{"foo", "f", 0},
104 BinOpTest{"oofofoofooo", "f", 7}, 104 BinOpTest{"oofofoofooo", "f", 7},
105 BinOpTest{"oofofoofooo", "foo", 7}, 105 BinOpTest{"oofofoofooo", "foo", 7},
106 BinOpTest{"barfoobarfoo", "foo", 9}, 106 BinOpTest{"barfoobarfoo", "foo", 9},
107 BinOpTest{"foo", "", 3}, 107 BinOpTest{"foo", "", 3},
108 BinOpTest{"foo", "o", 2}, 108 BinOpTest{"foo", "o", 2},
109 BinOpTest{"abcABCabc", "A", 3}, 109 BinOpTest{"abcABCabc", "A", 3},
110 BinOpTest{"abcABCabc", "a", 6}, 110 BinOpTest{"abcABCabc", "a", 6},
111 } 111 }
112 112
113 var indexOfAnyTests = []BinOpTest{ 113 var indexAnyTests = []BinOpTest{
114 BinOpTest{"", "", -1}, 114 BinOpTest{"", "", -1},
115 BinOpTest{"", "a", -1}, 115 BinOpTest{"", "a", -1},
116 BinOpTest{"", "abc", -1}, 116 BinOpTest{"", "abc", -1},
117 BinOpTest{"a", "", -1}, 117 BinOpTest{"a", "", -1},
118 BinOpTest{"a", "a", 0}, 118 BinOpTest{"a", "a", 0},
119 BinOpTest{"aaa", "a", 0}, 119 BinOpTest{"aaa", "a", 0},
120 BinOpTest{"abc", "xyz", -1}, 120 BinOpTest{"abc", "xyz", -1},
121 BinOpTest{"abc", "xcz", 2}, 121 BinOpTest{"abc", "xcz", 2},
122 BinOpTest{"aRegExp*", ".(|)*+?^$[]", 7}, 122 BinOpTest{"aRegExp*", ".(|)*+?^$[]", 7},
123 BinOpTest{dots + dots + dots, " ", -1}, 123 BinOpTest{dots + dots + dots, " ", -1},
124 } 124 }
125 125
126 // Execute f on each test case. funcName should be the name of f; it's used 126 // Execute f on each test case. funcName should be the name of f; it's used
127 // in failure reports. 127 // in failure reports.
128 func runIndexTests(t *testing.T, f func(s, sep []byte) int, funcName string, tes tCases []BinOpTest) { 128 func runIndexTests(t *testing.T, f func(s, sep []byte) int, funcName string, tes tCases []BinOpTest) {
129 for _, test := range testCases { 129 for _, test := range testCases {
130 a := []byte(test.a) 130 a := []byte(test.a)
131 b := []byte(test.b) 131 b := []byte(test.b)
132 actual := f(a, b) 132 actual := f(a, b)
133 if actual != test.i { 133 if actual != test.i {
134 t.Errorf("%s(%q,%q) = %v; want %v", funcName, a, b, actu al, test.i) 134 t.Errorf("%s(%q,%q) = %v; want %v", funcName, a, b, actu al, test.i)
135 } 135 }
136 } 136 }
137 } 137 }
138 138
139 func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) } 139 func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests) }
140 func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", las tIndexTests) } 140 func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", last IndexTests) }
141 func TestIndexOfAny(t *testing.T) { runIndexTests(t, IndexOfAny, "IndexOfAny", i ndexOfAnyTests) } 141 func TestIndexAny(t *testing.T) { runIndexTests(t, IndexAny, "IndexAny", indexA nyTests) }
142 142
143 func TestIndexByte(t *testing.T) { 143 func TestIndexByte(t *testing.T) {
144 for _, tt := range indexTests { 144 for _, tt := range indexTests {
145 if len(tt.b) != 1 { 145 if len(tt.b) != 1 {
146 continue 146 continue
147 } 147 }
148 a := []byte(tt.a) 148 a := []byte(tt.a)
149 b := tt.b[0] 149 b := tt.b[0]
150 pos := IndexByte(a, b) 150 pos := IndexByte(a, b)
151 if pos != tt.i { 151 if pos != tt.i {
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 559 }
560 if !tt.lossy { 560 if !tt.lossy {
561 // can only test reassembly if we didn't lose informatio n 561 // can only test reassembly if we didn't lose informatio n
562 s := string(a) 562 s := string(a)
563 if s != tt.in { 563 if s != tt.in {
564 t.Errorf("string(Runes(%q)) = %x; want %x", tin, s, tin) 564 t.Errorf("string(Runes(%q)) = %x; want %x", tin, s, tin)
565 } 565 }
566 } 566 }
567 } 567 }
568 } 568 }
LEFTRIGHT

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