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 strings_test | 5 package strings_test |
6 | 6 |
7 import ( | 7 import ( |
8 . "strings" | 8 . "strings" |
9 "testing" | 9 "testing" |
10 "unicode" | 10 "unicode" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 IndexTest{"foo", "f", 0}, | 65 IndexTest{"foo", "f", 0}, |
66 IndexTest{"oofofoofooo", "f", 7}, | 66 IndexTest{"oofofoofooo", "f", 7}, |
67 IndexTest{"oofofoofooo", "foo", 7}, | 67 IndexTest{"oofofoofooo", "foo", 7}, |
68 IndexTest{"barfoobarfoo", "foo", 9}, | 68 IndexTest{"barfoobarfoo", "foo", 9}, |
69 IndexTest{"foo", "", 3}, | 69 IndexTest{"foo", "", 3}, |
70 IndexTest{"foo", "o", 2}, | 70 IndexTest{"foo", "o", 2}, |
71 IndexTest{"abcABCabc", "A", 3}, | 71 IndexTest{"abcABCabc", "A", 3}, |
72 IndexTest{"abcABCabc", "a", 6}, | 72 IndexTest{"abcABCabc", "a", 6}, |
73 } | 73 } |
74 | 74 |
75 var indexOfAnyTests = []IndexTest{ | 75 var indexAnyTests = []IndexTest{ |
76 IndexTest{"", "", -1}, | 76 IndexTest{"", "", -1}, |
77 IndexTest{"", "a", -1}, | 77 IndexTest{"", "a", -1}, |
78 IndexTest{"", "abc", -1}, | 78 IndexTest{"", "abc", -1}, |
79 IndexTest{"a", "", -1}, | 79 IndexTest{"a", "", -1}, |
80 IndexTest{"a", "a", 0}, | 80 IndexTest{"a", "a", 0}, |
81 IndexTest{"aaa", "a", 0}, | 81 IndexTest{"aaa", "a", 0}, |
82 IndexTest{"abc", "xyz", -1}, | 82 IndexTest{"abc", "xyz", -1}, |
83 IndexTest{"abc", "xcz", 2}, | 83 IndexTest{"abc", "xcz", 2}, |
84 IndexTest{"a☺b☻c☹d", "uvw☻xyz", 2 + len("☺")}, | 84 IndexTest{"a☺b☻c☹d", "uvw☻xyz", 2 + len("☺")}, |
85 IndexTest{"aRegExp*", ".(|)*+?^$[]", 7}, | 85 IndexTest{"aRegExp*", ".(|)*+?^$[]", 7}, |
86 IndexTest{dots + dots + dots, " ", -1}, | 86 IndexTest{dots + dots + dots, " ", -1}, |
87 } | 87 } |
88 | 88 |
89 // Execute f on each test case. funcName should be the name of f; it's used | 89 // Execute f on each test case. funcName should be the name of f; it's used |
90 // in failure reports. | 90 // in failure reports. |
91 func runIndexTests(t *testing.T, f func(s, sep string) int, funcName string, tes
tCases []IndexTest) { | 91 func runIndexTests(t *testing.T, f func(s, sep string) int, funcName string, tes
tCases []IndexTest) { |
92 for _, test := range testCases { | 92 for _, test := range testCases { |
93 actual := f(test.s, test.sep) | 93 actual := f(test.s, test.sep) |
94 if actual != test.out { | 94 if actual != test.out { |
95 t.Errorf("%s(%q,%q) = %v; want %v", funcName, test.s, te
st.sep, actual, test.out) | 95 t.Errorf("%s(%q,%q) = %v; want %v", funcName, test.s, te
st.sep, actual, test.out) |
96 } | 96 } |
97 } | 97 } |
98 } | 98 } |
99 | 99 |
100 func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests)
} | 100 func TestIndex(t *testing.T) { runIndexTests(t, Index, "Index", indexTests)
} |
101 func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", las
tIndexTests) } | 101 func TestLastIndex(t *testing.T) { runIndexTests(t, LastIndex, "LastIndex", last
IndexTests) } |
102 func TestIndexOfAny(t *testing.T) { runIndexTests(t, IndexOfAny, "IndexOfAny", i
ndexOfAnyTests) } | 102 func TestIndexAny(t *testing.T) { runIndexTests(t, IndexAny, "IndexAny", indexA
nyTests) } |
103 | 103 |
104 type ExplodeTest struct { | 104 type ExplodeTest struct { |
105 s string | 105 s string |
106 n int | 106 n int |
107 a []string | 107 a []string |
108 } | 108 } |
109 | 109 |
110 var explodetests = []ExplodeTest{ | 110 var explodetests = []ExplodeTest{ |
111 ExplodeTest{abcd, 4, []string{"a", "b", "c", "d"}}, | 111 ExplodeTest{abcd, 4, []string{"a", "b", "c", "d"}}, |
112 ExplodeTest{faces, 3, []string{"☺", "☻", "☹"}}, | 112 ExplodeTest{faces, 3, []string{"☺", "☻", "☹"}}, |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 } | 464 } |
465 if !tt.lossy { | 465 if !tt.lossy { |
466 // can only test reassembly if we didn't lose informatio
n | 466 // can only test reassembly if we didn't lose informatio
n |
467 s := string(a) | 467 s := string(a) |
468 if s != tt.in { | 468 if s != tt.in { |
469 t.Errorf("string([]int(%q)) = %x; want %x", tt.i
n, s, tt.in) | 469 t.Errorf("string([]int(%q)) = %x; want %x", tt.i
n, s, tt.in) |
470 } | 470 } |
471 } | 471 } |
472 } | 472 } |
473 } | 473 } |
LEFT | RIGHT |