OLD | NEW |
---|---|
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 import "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
6 | 6 |
7 // TODO(ngeoffray): test String methods with null arguments. | 7 // TODO(ngeoffray): test String methods with null arguments. |
8 class StringTest { | 8 class StringTest { |
9 | 9 |
10 static testMain() { | 10 static testMain() { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
120 Expect.isTrue("str".startsWith("str")); | 120 Expect.isTrue("str".startsWith("str")); |
121 | 121 |
122 Expect.isFalse("str".startsWith("stri")); | 122 Expect.isFalse("str".startsWith("stri")); |
123 Expect.isFalse("str".startsWith("r")); | 123 Expect.isFalse("str".startsWith("r")); |
124 Expect.isFalse("str".startsWith("tr")); | 124 Expect.isFalse("str".startsWith("tr")); |
125 Expect.isFalse("str".startsWith("t")); | 125 Expect.isFalse("str".startsWith("t")); |
126 | 126 |
127 Expect.isTrue("".startsWith("")); | 127 Expect.isTrue("".startsWith("")); |
128 Expect.isFalse("".startsWith("s")); | 128 Expect.isFalse("".startsWith("s")); |
129 | 129 |
130 Expect.isFalse("strstr".startsWith("s", 1)); | |
131 Expect.isFalse("strstr".startsWith("s", 2)); | |
132 Expect.isTrue("strstr".startsWith("s", 3)); | |
133 Expect.isFalse("strstr".startsWith("s", 4)); | |
134 | |
135 Expect.isFalse("strstr".startsWith("st", 1)); | |
136 Expect.isFalse("strstr".startsWith("st", 2)); | |
137 Expect.isTrue("strstr".startsWith("st", 3)); | |
138 Expect.isFalse("strstr".startsWith("st", 4)); | |
139 | |
140 Expect.isFalse("strstr".startsWith("str", 1)); | |
141 Expect.isFalse("strstr".startsWith("str", 2)); | |
142 Expect.isTrue("strstr".startsWith("str", 3)); | |
143 Expect.isFalse("strstr".startsWith("str", 4)); | |
144 | |
145 Expect.isTrue("str".startsWith("", 0)); | |
146 Expect.isTrue("str".startsWith("", 1)); | |
147 Expect.isTrue("str".startsWith("", 2)); | |
148 Expect.isTrue("str".startsWith("", 3)); | |
149 | |
150 Expect.throws(() => "str".startsWith("", -1)); | |
151 Expect.throws(() => "str".startsWith("", 4)); | |
152 | |
130 var regexp = new RegExp("s(?:tr?)?"); | 153 var regexp = new RegExp("s(?:tr?)?"); |
131 Expect.isTrue("s".startsWith(regexp)); | 154 Expect.isTrue("s".startsWith(regexp)); |
132 Expect.isTrue("st".startsWith(regexp)); | 155 Expect.isTrue("st".startsWith(regexp)); |
133 Expect.isTrue("str".startsWith(regexp)); | 156 Expect.isTrue("str".startsWith(regexp)); |
134 Expect.isTrue("sX".startsWith(regexp)); | 157 Expect.isTrue("sX".startsWith(regexp)); |
135 Expect.isTrue("stX".startsWith(regexp)); | 158 Expect.isTrue("stX".startsWith(regexp)); |
136 Expect.isTrue("strX".startsWith(regexp)); | 159 Expect.isTrue("strX".startsWith(regexp)); |
137 | 160 |
138 Expect.isFalse("".startsWith(regexp)); | 161 Expect.isFalse("".startsWith(regexp)); |
139 Expect.isFalse("astr".startsWith(regexp)); | 162 Expect.isFalse("astr".startsWith(regexp)); |
140 | 163 |
141 Expect.isTrue("".startsWith(new RegExp(""))); | 164 Expect.isTrue("".startsWith(new RegExp(""))); |
142 Expect.isTrue("".startsWith(new RegExp("a?"))); | 165 Expect.isTrue("".startsWith(new RegExp("a?"))); |
166 | |
167 Expect.isFalse("strstr".startsWith(regexp, 1)); | |
168 Expect.isFalse("strstr".startsWith(regexp, 2)); | |
169 Expect.isTrue("strstr".startsWith(regexp, 3)); | |
170 Expect.isFalse("strstr".startsWith(regexp, 4)); | |
171 | |
172 Expect.isTrue("str".startsWith(new RegExp(""), 0)); | |
173 Expect.isTrue("str".startsWith(new RegExp(""), 1)); | |
174 Expect.isTrue("str".startsWith(new RegExp(""), 2)); | |
175 Expect.isTrue("str".startsWith(new RegExp(""), 3)); | |
176 Expect.isTrue("str".startsWith(new RegExp("a?"), 0)); | |
177 Expect.isTrue("str".startsWith(new RegExp("a?"), 1)); | |
178 Expect.isTrue("str".startsWith(new RegExp("a?"), 2)); | |
179 Expect.isTrue("str".startsWith(new RegExp("a?"), 3)); | |
floitsch
2013/06/17 16:07:15
Add test for RegExp with "^".
| |
180 | |
181 Expect.throws(() => "str".startsWith(regexp, -1)); | |
182 Expect.throws(() => "str".startsWith(regexp, 4)); | |
143 } | 183 } |
144 | 184 |
145 static testIndexOf() { | 185 static testIndexOf() { |
146 Expect.equals(0, "str".indexOf("", 0)); | 186 Expect.equals(0, "str".indexOf("", 0)); |
147 Expect.equals(0, "".indexOf("", 0)); | 187 Expect.equals(0, "".indexOf("", 0)); |
148 Expect.equals(-1, "".indexOf("a", 0)); | 188 Expect.equals(-1, "".indexOf("a", 0)); |
149 | 189 |
150 Expect.equals(1, "str".indexOf("t", 0)); | 190 Expect.equals(1, "str".indexOf("t", 0)); |
151 Expect.equals(1, "str".indexOf("tr", 0)); | 191 Expect.equals(1, "str".indexOf("tr", 0)); |
152 Expect.equals(0, "str".indexOf("str", 0)); | 192 Expect.equals(0, "str".indexOf("str", 0)); |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
343 | 383 |
344 void testStringLength(int length, String str) { | 384 void testStringLength(int length, String str) { |
345 Expect.equals(length, str.length); | 385 Expect.equals(length, str.length); |
346 (length == 0 ? Expect.isTrue : Expect.isFalse)(str.isEmpty); | 386 (length == 0 ? Expect.isTrue : Expect.isFalse)(str.isEmpty); |
347 (length != 0 ? Expect.isTrue : Expect.isFalse)(str.isNotEmpty); | 387 (length != 0 ? Expect.isTrue : Expect.isFalse)(str.isNotEmpty); |
348 } | 388 } |
349 | 389 |
350 main() { | 390 main() { |
351 StringTest.testMain(); | 391 StringTest.testMain(); |
352 } | 392 } |
OLD | NEW |