Chromium Code Reviews| Index: tests/corelib/regexp/RegExp_test.dart |
| diff --git a/tests/corelib/regexp/RegExp_test.dart b/tests/corelib/regexp/RegExp_test.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4d57e3a66fbc7283ebdaba2f36bcb771667d6ee3 |
| --- /dev/null |
| +++ b/tests/corelib/regexp/RegExp_test.dart |
| @@ -0,0 +1,69 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
|
Lasse Reichstein Nielsen
2014/10/23 13:21:57
What was the license text on the original?
|
| + |
| +import 'util.dart'; |
| +import 'package:expect/expect.dart'; |
| + |
| +void main() { |
| + description("KDE JS Test"); |
| + |
| + var ri = new RegExp(r"a", caseSensitive: false); |
| + var rm = new RegExp(r"a", multiLine: true); |
| + var rg = new RegExp(r"a"); |
| + |
| + shouldBe(new RegExp(r"(b)c").firstMatch('abcd'), ["bc", "b"]); |
| + |
| + shouldBe(firstMatch('abcdefghi', new RegExp(r"(abc)def(ghi)")), ['abcdefghi', 'abc', 'ghi']); |
| + shouldBe(new RegExp(r"(abc)def(ghi)").firstMatch('abcdefghi'), ['abcdefghi', 'abc', 'ghi']); |
| + |
| + shouldBe(firstMatch('abcdefghi', new RegExp(r"(a(b(c(d(e)f)g)h)i)")), ['abcdefghi', 'abcdefghi', 'bcdefgh', 'cdefg', 'def', 'e']); |
| + |
| + shouldBe(firstMatch('(100px 200px 150px 15px)', new RegExp(r"\((\d+)(px)* (\d+)(px)* (\d+)(px)* (\d+)(px)*\)")), |
| + ['(100px 200px 150px 15px)', '100', 'px', '200', 'px', '150', 'px', '15', 'px']); |
| + shouldBeNull(firstMatch('', new RegExp(r"\((\d+)(px)* (\d+)(px)* (\d+)(px)* (\d+)(px)*\)"))); |
| + |
| + var invalidChars = new RegExp(r"[^@\.\w]"); // #47092 |
| + shouldBeTrue(firstMatch('faure@kde.org', invalidChars) == null); |
| + shouldBeFalse(firstMatch('faure-kde@kde.org', invalidChars) == null); |
| + |
| + assertEquals('test1test2'.replaceAll('test','X'),'X1X2'); |
| + assertEquals('test1test2'.replaceAll(new RegExp(r"\d"),'X'),'testXtestX'); |
| + assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"),''),'testtest'); |
| + assertEquals('test1test2'.replaceAll(new RegExp(r"test"),'X'),'X1X2'); |
| + assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"),''),'testtest'); |
| + assertEquals('1test2test3'.replaceAll(new RegExp(r"x"),''),'1test2test3'); |
| + assertEquals('test1test2'.replaceAllMapped(new RegExp(r"(te)(st)"), |
| + (m) => "${m.group(2)}${m.group(1)}"),'stte1stte2'); |
| + assertEquals('foo+bar'.replaceAll(new RegExp(r"\+"),'%2B'), 'foo%2Bbar'); |
| + var caught = false; try { new RegExp("+"); } catch (e) { caught = true; } |
| + shouldBeTrue(caught); // #40435 |
| + assertEquals('foo'.replaceAll(new RegExp(r"z?"),'x'), 'xfxoxox'); |
| + assertEquals('test test'.replaceAll(new RegExp(r"\s*"),''),'testtest'); // #50985 |
| + assertEquals('abc\$%@'.replaceAll(new RegExp(r"[^0-9a-z]*", caseSensitive: false),''),'abc'); // #50848 |
| + assertEquals('ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false),''),''); // #75292 |
| + assertEquals('1ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false),''),'1'); // #75292 |
| + |
| + Expect.listEquals('1test2test3blah'.split(new RegExp(r"test")), ['1', '2', '3blah']); |
| + var reg = new RegExp(r"(\d\d )"); |
| + var str = '98 76 blah'; |
| + shouldBe(reg.firstMatch(str),['98 ', '98 ']); |
| + |
| + str = "For more information, see Chapter 3.4.5.1"; |
| + var re = new RegExp(r"(chapter \d+(\.\d)*)", caseSensitive: false); |
| + // This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1 |
| + // 'Chapter 3.4.5.1' is the first match and the first value remembered from (Chapter \d+(\.\d)*). |
| + // '.1' is the second value remembered from (\.\d) |
| + shouldBe(firstMatch(str, re),['Chapter 3.4.5.1', 'Chapter 3.4.5.1', '.1']); |
| + |
| + str = "abcDdcba"; |
| + // The returned array contains D, d. |
| + re = new RegExp(r"d", caseSensitive: false); |
| + var matches = re.allMatches(str); |
| + Expect.listEquals( |
| + matches.map((m) => m.group(0)).toList(), |
| + ['D', 'd']); |
| + |
| + // unicode escape sequence |
| + shouldBe(firstMatch('abc', new RegExp(r"\u0062")), ['b']); |
| +} |