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

Side by Side Diff: tests/corelib/string_trimlr_test.dart

Issue 190853009: Add string.trimLeft/trimRight. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove left-over debugging aid. Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « tests/corelib/corelib.status ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 import "package:expect/expect.dart";
6
7 // Characters with Whitespace property (Unicode 6.2).
8 // 0009..000D ; White_Space # Cc <control-0009>..<control-000D>
9 // 0020 ; White_Space # Zs SPACE
10 // 0085 ; White_Space # Cc <control-0085>
11 // 00A0 ; White_Space # Zs NO-BREAK SPACE
12 // 1680 ; White_Space # Zs OGHAM SPACE MARK
13 // 180E ; White_Space # Zs MONGOLIAN VOWEL SEPARATOR
14 // 2000..200A ; White_Space # Zs EN QUAD..HAIR SPACE
15 // 2028 ; White_Space # Zl LINE SEPARATOR
16 // 2029 ; White_Space # Zp PARAGRAPH SEPARATOR
17 // 202F ; White_Space # Zs NARROW NO-BREAK SPACE
18 // 205F ; White_Space # Zs MEDIUM MATHEMATICAL SPACE
19 // 3000 ; White_Space # Zs IDEOGRAPHIC SPACE
20 // And BOM:
21 // FEFF ; Byte order mark.
22 const WHITESPACE = const [
23 0x09,
24 0x0A,
25 0x0B,
26 0x0C,
27 0x0D,
28 0x20,
29 0x85,
30 0xA0,
31 0x1680,
32 0x180E,
33 0x2000,
34 0x2001,
35 0x2002,
36 0x2003,
37 0x2004,
38 0x2005,
39 0x2006,
40 0x2007,
41 0x2008,
42 0x2009,
43 0x200A,
44 0x2028,
45 0x2029,
46 0x202F,
47 0x205F,
48 0x3000,
49 0xFEFF,
50 ];
51
52 main() {
53 // Test the whitespace in different positions.
54 test(ws) {
55 // trimLeft
56 Expect.equals("", ws.trimLeft(), "K1");
57 Expect.equals("", (ws + ws).trimLeft(), "L2");
58 Expect.equals("a" + ws, ("a" + ws).trimLeft(), "L3");
59 Expect.equals("a", (ws + "a").trimLeft(), "L4");
60 Expect.equals("a" + ws + ws, (ws + ws + "a" + ws + ws).trimLeft(), "L5");
61 Expect.equals("a" + ws + "a", (ws + ws + "a" + ws + "a").trimLeft(), "L6");
62 var untrimmable = "a" + ws + "a";
63 Expect.identical(untrimmable, untrimmable.trimLeft(), "L7");
64 // trimRight
65 Expect.equals("", ws.trimRight(), "R1");
66 Expect.equals("", (ws + ws).trimRight(), "R2");
67 Expect.equals("a", ("a" + ws).trimRight(), "R3");
68 Expect.equals(ws + "a", (ws + "a").trimRight(), "R4");
69 Expect.equals(ws + ws + "a", (ws + ws + "a" + ws + ws).trimRight(), "R5");
70 Expect.equals("a" + ws + "a", ("a" + ws + "a" + ws + ws).trimRight(), "R6");
71 Expect.identical(untrimmable, untrimmable.trimRight(), "R7");
72 }
73
74 // Test each whitespace at different locations.
75 for (var ws in WHITESPACE) {
76 var c = new String.fromCharCode(ws);
77 test(c);
78 }
79 // Test all whitespaces at once at different locations.
80 test(new String.fromCharCodes(WHITESPACE));
81
82 // Empty strings.
83 Expect.identical("", "".trimLeft());
84 Expect.identical("", "".trimRight());
85
86 // Test all BMP chars and one surrogate pair.
87 for (int i = 0, j = 0; i <= 0x10000; i++) {
88 if (j < WHITESPACE.length && i == WHITESPACE[j]) {
89 j++;
90 continue;
91 }
92 // U+200b is currently being treated as whitespace by some JS engines.
93 // Should be fixed in tip-of-tree V8 per 2014-02-10.
94 // This line makes string_trimlr_test/none fail but /01 succeede where
95 // this bug is in the JS. Both succeede on the VM and where the bug is
96 // not. Remove this line and comment if all JS engines fix it.
97 if (i == 0x200b) continue; /// 01: ok
98
99 var s = new String.fromCharCode(i);
100 Expect.identical(s, s.trimLeft());
101 Expect.identical(s, s.trimRight());
102 }
103 }
OLDNEW
« no previous file with comments | « tests/corelib/corelib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698