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

Side by Side Diff: tests/corelib/regexp/RegExp_test.dart

Issue 667043003: Port regexp tests from V8 to Dart. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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
OLDNEW
(Empty)
1 // Copyright (c) 2014, 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.
Lasse Reichstein Nielsen 2014/10/23 13:21:57 What was the license text on the original?
4
5 import 'util.dart';
6 import 'package:expect/expect.dart';
7
8 void main() {
9 description("KDE JS Test");
10
11 var ri = new RegExp(r"a", caseSensitive: false);
12 var rm = new RegExp(r"a", multiLine: true);
13 var rg = new RegExp(r"a");
14
15 shouldBe(new RegExp(r"(b)c").firstMatch('abcd'), ["bc", "b"]);
16
17 shouldBe(firstMatch('abcdefghi', new RegExp(r"(abc)def(ghi)")), ['abcdefghi', 'abc', 'ghi']);
18 shouldBe(new RegExp(r"(abc)def(ghi)").firstMatch('abcdefghi'), ['abcdefghi', ' abc', 'ghi']);
19
20 shouldBe(firstMatch('abcdefghi', new RegExp(r"(a(b(c(d(e)f)g)h)i)")), ['abcdef ghi', 'abcdefghi', 'bcdefgh', 'cdefg', 'def', 'e']);
21
22 shouldBe(firstMatch('(100px 200px 150px 15px)', new RegExp(r"\((\d+)(px)* (\d+ )(px)* (\d+)(px)* (\d+)(px)*\)")),
23 ['(100px 200px 150px 15px)', '100', 'px', '200', 'px', '150', 'px', '1 5', 'px']);
24 shouldBeNull(firstMatch('', new RegExp(r"\((\d+)(px)* (\d+)(px)* (\d+)(px)* (\ d+)(px)*\)")));
25
26 var invalidChars = new RegExp(r"[^@\.\w]"); // #47092
27 shouldBeTrue(firstMatch('faure@kde.org', invalidChars) == null);
28 shouldBeFalse(firstMatch('faure-kde@kde.org', invalidChars) == null);
29
30 assertEquals('test1test2'.replaceAll('test','X'),'X1X2');
31 assertEquals('test1test2'.replaceAll(new RegExp(r"\d"),'X'),'testXtestX');
32 assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"),''),'testtest');
33 assertEquals('test1test2'.replaceAll(new RegExp(r"test"),'X'),'X1X2');
34 assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"),''),'testtest');
35 assertEquals('1test2test3'.replaceAll(new RegExp(r"x"),''),'1test2test3');
36 assertEquals('test1test2'.replaceAllMapped(new RegExp(r"(te)(st)"),
37 (m) => "${m.group(2)}${m.group(1)}"),'stte1stte2');
38 assertEquals('foo+bar'.replaceAll(new RegExp(r"\+"),'%2B'), 'foo%2Bbar');
39 var caught = false; try { new RegExp("+"); } catch (e) { caught = true; }
40 shouldBeTrue(caught); // #40435
41 assertEquals('foo'.replaceAll(new RegExp(r"z?"),'x'), 'xfxoxox');
42 assertEquals('test test'.replaceAll(new RegExp(r"\s*"),''),'testtest'); // #50 985
43 assertEquals('abc\$%@'.replaceAll(new RegExp(r"[^0-9a-z]*", caseSensitive: fal se),''),'abc'); // #50848
44 assertEquals('ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false),'') ,''); // #75292
45 assertEquals('1ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false),'' ),'1'); // #75292
46
47 Expect.listEquals('1test2test3blah'.split(new RegExp(r"test")), ['1', '2', '3b lah']);
48 var reg = new RegExp(r"(\d\d )");
49 var str = '98 76 blah';
50 shouldBe(reg.firstMatch(str),['98 ', '98 ']);
51
52 str = "For more information, see Chapter 3.4.5.1";
53 var re = new RegExp(r"(chapter \d+(\.\d)*)", caseSensitive: false);
54 // This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1
55 // 'Chapter 3.4.5.1' is the first match and the first value remembered from (C hapter \d+(\.\d)*).
56 // '.1' is the second value remembered from (\.\d)
57 shouldBe(firstMatch(str, re),['Chapter 3.4.5.1', 'Chapter 3.4.5.1', '.1']);
58
59 str = "abcDdcba";
60 // The returned array contains D, d.
61 re = new RegExp(r"d", caseSensitive: false);
62 var matches = re.allMatches(str);
63 Expect.listEquals(
64 matches.map((m) => m.group(0)).toList(),
65 ['D', 'd']);
66
67 // unicode escape sequence
68 shouldBe(firstMatch('abc', new RegExp(r"\u0062")), ['b']);
69 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698