Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: packages/quiver/test/strings_test.dart

Issue 2989763002: Update charted to 0.4.8 and roll (Closed)
Patch Set: Removed Cutch from list of reviewers Created 3 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 Google Inc. All Rights Reserved. 1 // Copyright 2013 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 library quiver.strings; 15 library quiver.strings;
16 16
17 import 'package:quiver/strings.dart'; 17 import 'package:quiver/strings.dart';
18 import 'package:test/test.dart' hide isEmpty; 18 import 'package:test/test.dart' hide isEmpty, isNotEmpty;
19 19
20 main() { 20 main() {
21 group('isBlank', () { 21 group('isBlank', () {
22 test('should consider null a blank', () { 22 test('should consider null a blank', () {
23 expect(isBlank(null), isTrue); 23 expect(isBlank(null), isTrue);
24 }); 24 });
25 test('should consider empty string a blank', () { 25 test('should consider empty string a blank', () {
26 expect(isBlank(''), isTrue); 26 expect(isBlank(''), isTrue);
27 }); 27 });
28 test('should consider white-space-only string a blank', () { 28 test('should consider white-space-only string a blank', () {
(...skipping 12 matching lines...) Expand all
41 expect(isEmpty(''), isTrue); 41 expect(isEmpty(''), isTrue);
42 }); 42 });
43 test('should consider whitespace string to be not empty', () { 43 test('should consider whitespace string to be not empty', () {
44 expect(isEmpty(' '), isFalse); 44 expect(isEmpty(' '), isFalse);
45 }); 45 });
46 test('should consider non-whitespace string to be not empty', () { 46 test('should consider non-whitespace string to be not empty', () {
47 expect(isEmpty('hello'), isFalse); 47 expect(isEmpty('hello'), isFalse);
48 }); 48 });
49 }); 49 });
50 50
51 group('flip', () { 51 group('isNotEmpty', () {
52 test('should flip characters in a string', () { 52 test('should consider null to be empty', () {
53 expect(flip('ab'), 'ba'); 53 expect(isNotEmpty(null), isFalse);
54 }); 54 });
55 test('should return null as null', () { 55 test('should consider the empty string to be empty', () {
56 expect(flip(null), null); 56 expect(isNotEmpty(''), isFalse);
57 }); 57 });
58 test('should return empty string as empty string', () { 58 test('should consider whitespace string to be not empty', () {
59 expect(flip(''), ''); 59 expect(isNotEmpty(' '), isTrue);
60 });
61 test('should consider non-whitespace string to be not empty', () {
62 expect(isNotEmpty('hello'), isTrue);
60 }); 63 });
61 }); 64 });
62 65
63 group('nullToEmpty', () { 66 group('isDigit', () {
64 test('should turn null to empty string', () { 67 test('should return true for standard digits', () {
65 expect(nullToEmpty(null), ''); 68 for (var i = 0; i <= 9; i++) {
69 expect(isDigit('$i'.codeUnitAt(0)), isTrue);
70 }
66 }); 71 });
67 test('should leave non-null string unchanged', () { 72 test('should return false for non-digits', () {
68 expect(nullToEmpty('hi!'), 'hi!'); 73 expect(isDigit('a'.codeUnitAt(0)), isFalse);
69 }); 74 expect(isDigit(' '.codeUnitAt(0)), isFalse);
70 test('should leave empty string unchanged', () { 75 expect(isDigit('%'.codeUnitAt(0)), isFalse);
71 expect(nullToEmpty(''), '');
72 }); 76 });
73 }); 77 });
74 78
75 group('emptyToNull', () { 79 group('reverse', () {
76 test('should turn empty string to null', () { 80 test('should reverse characters in a string', () {
77 expect(emptyToNull(''), null); 81 expect(reverse('ab'), 'ba');
78 }); 82 });
79 test('should leave non-null string unchanged', () { 83 test('should return null as null', () {
80 expect(emptyToNull('hi!'), 'hi!'); 84 expect(reverse(null), null);
81 }); 85 });
82 test('should leave null as null', () { 86 test('should return empty string as empty string', () {
83 expect(emptyToNull(null), null); 87 expect(reverse(''), '');
84 }); 88 });
85 }); 89 });
86 90
87 group('repeat', () { 91 group('repeat', () {
88 test('should repeat a non-empty string', () { 92 test('should repeat a non-empty string', () {
89 expect(repeat('ab', 3), 'ababab'); 93 expect(repeat('ab', 3), 'ababab');
90 }); 94 });
91 test('should repeat flipped non-empty string ' 95 test(
96 'should repeat flipped non-empty string '
92 'on negative number of times', () { 97 'on negative number of times', () {
93 expect(repeat('ab', -3), 'bababa'); 98 expect(repeat('ab', -3), 'bababa');
94 }); 99 });
95 test('should return null on null', () { 100 test('should return null on null', () {
96 expect(repeat(null, 6), null); 101 expect(repeat(null, 6), null);
97 expect(repeat(null, -6), null); 102 expect(repeat(null, -6), null);
98 }); 103 });
99 test('should return empty string on empty string', () { 104 test('should return empty string on empty string', () {
100 expect(repeat('', 6), ''); 105 expect(repeat('', 6), '');
101 expect(repeat('', -6), ''); 106 expect(repeat('', -6), '');
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 159
155 // Corner cases 160 // Corner cases
156 test('should throw on null', () { 161 test('should throw on null', () {
157 expect(() => loop(null, 6, 8), throws); 162 expect(() => loop(null, 6, 8), throws);
158 }); 163 });
159 test('should throw on empty', () { 164 test('should throw on empty', () {
160 expect(() => loop('', 6, 8), throws); 165 expect(() => loop('', 6, 8), throws);
161 }); 166 });
162 }); 167 });
163 168
164 group('padLeft', () {
165 test('should return the input if length greater than width', () {
166 expect(padLeft('abc', 2, '0'), 'abc');
167 expect(padLeft('abc', 3, '0'), 'abc');
168 });
169
170 test('should pad on the left if length less than width', () {
171 expect(padLeft('abc', 4, '0'), '0abc');
172 expect(padLeft('abc', 6, '0'), '000abc');
173 });
174
175 test('should use multi-character fills', () {
176 expect(padLeft('abc', 4, '012345'), '0abc');
177 expect(padLeft('abc', 6, '012345'), '012abc');
178 expect(padLeft('abc', 8, '012'), '01201abc');
179 });
180
181 test('should handle null and empty inputs', () {
182 expect(padLeft(null, 4, '012345'), '0123');
183 expect(padLeft('', 4, '012345'), '0123');
184 expect(padLeft(null, 4, '012'), '0120');
185 expect(padLeft('', 4, '012'), '0120');
186 });
187 });
188
189 group('padRight', () {
190 test('should return the input if length greater than width', () {
191 expect(padRight('abc', 2, '0'), 'abc');
192 expect(padRight('abc', 3, '0'), 'abc');
193 });
194
195 test('should pad on the right if length less than width', () {
196 expect(padRight('abc', 4, '0'), 'abc0');
197 expect(padRight('abc', 6, '0'), 'abc000');
198 });
199
200 test('should use multi-character fills', () {
201 expect(padRight('abc', 4, '012345'), 'abc5');
202 expect(padRight('abc', 6, '012345'), 'abc345');
203 expect(padRight('abc', 8, '012'), 'abc12012');
204 });
205
206 test('should handle null and empty inputs', () {
207 expect(padRight(null, 4, '012345'), '2345');
208 expect(padRight('', 4, '012345'), '2345');
209 expect(padRight(null, 4, '012'), '2012');
210 expect(padRight('', 4, '012'), '2012');
211 });
212 });
213
214 group('trimLeft', () {
215 test('should trim whitespace from the left', () {
216 expect(trimLeft(''), '');
217 expect(trimLeft(' '), '');
218 expect(trimLeft(' abc '), 'abc ');
219 expect(trimLeft(' abc def '), 'abc def ');
220 expect(trimLeft('\t\vabc '), 'abc ');
221 // these are some of the whitespace chars not defined for RexExps
222 expect(trimLeft('\u000Aabc '), 'abc ');
223 expect(trimLeft('\u000Dabc '), 'abc ');
224 expect(trimLeft('\u0085abc '), 'abc ');
225 expect(trimLeft('\u1680abc '), 'abc ');
226 });
227
228 test('should throw on null', () {
229 expect(() => trimLeft(null), throws);
230 });
231 });
232
233 group('trimRight', () {
234 test('should trim whitespace from the right', () {
235 expect(trimRight(''), '');
236 expect(trimRight(' '), '');
237 expect(trimRight(' abc '), ' abc');
238 expect(trimRight(' abc def '), ' abc def');
239 expect(trimRight(' abc\t\v'), ' abc');
240 // these are some of the whitespace chars not defined for RexExps
241 expect(trimRight(' abc\u000A'), ' abc');
242 expect(trimRight(' abc\u000D'), ' abc');
243 expect(trimRight(' abc\u0085'), ' abc');
244 expect(trimRight(' abc\u1680'), ' abc');
245 });
246
247 test('should throw on null', () {
248 expect(() => trimRight(null), throws);
249 });
250 });
251
252 group('center', () { 169 group('center', () {
253 test('should return the input if length greater than width', () { 170 test('should return the input if length greater than width', () {
254 expect(center('abc', 2, '0'), 'abc'); 171 expect(center('abc', 2, '0'), 'abc');
255 expect(center('abc', 3, '0'), 'abc'); 172 expect(center('abc', 3, '0'), 'abc');
256 }); 173 });
257 174
258 test('should pad equal chars on left and right for even padding count', () { 175 test('should pad equal chars on left and right for even padding count', () {
259 expect(center('abc', 5, '0'), '0abc0'); 176 expect(center('abc', 5, '0'), '0abc0');
260 expect(center('abc', 9, '0'), '000abc000'); 177 expect(center('abc', 9, '0'), '000abc000');
261 }); 178 });
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 }); 226 });
310 227
311 test('should return compare unequal Strings correctly', () { 228 test('should return compare unequal Strings correctly', () {
312 expect(compareIgnoreCase('abc', 'abd'), lessThan(0)); 229 expect(compareIgnoreCase('abc', 'abd'), lessThan(0));
313 expect(compareIgnoreCase('abc', 'abD'), lessThan(0)); 230 expect(compareIgnoreCase('abc', 'abD'), lessThan(0));
314 expect(compareIgnoreCase('abd', 'abc'), greaterThan(0)); 231 expect(compareIgnoreCase('abd', 'abc'), greaterThan(0));
315 expect(compareIgnoreCase('abD', 'abc'), greaterThan(0)); 232 expect(compareIgnoreCase('abD', 'abc'), greaterThan(0));
316 }); 233 });
317 }); 234 });
318 } 235 }
OLDNEW
« no previous file with comments | « packages/quiver/test/streams/streambuffer_test.dart ('k') | packages/quiver/test/testing/async/fake_async_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698