OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. All rights reserved. | |
2 // Copyright 2013 the V8 project authors. All rights reserved. | |
3 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. | |
4 // | |
5 // Redistribution and use in source and binary forms, with or without | |
6 // modification, are permitted provided that the following conditions | |
7 // are met: | |
8 // 1. Redistributions of source code must retain the above copyright | |
9 // notice, this list of conditions and the following disclaimer. | |
10 // 2. Redistributions in binary form must reproduce the above copyright | |
11 // notice, this list of conditions and the following disclaimer in the | |
12 // documentation and/or other materials provided with the distribution. | |
13 // | |
14 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND AN
Y | |
15 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
16 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |
17 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR AN
Y | |
18 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
19 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
20 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND O
N | |
21 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | |
23 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | |
25 import 'v8_regexp_utils.dart'; | |
26 import 'package:expect/expect.dart'; | |
27 | |
28 void main() { | |
29 description("KDE JS Test"); | |
30 | |
31 var ri = new RegExp(r"a", caseSensitive: false); | |
32 var rm = new RegExp(r"a", multiLine: true); | |
33 var rg = new RegExp(r"a"); | |
34 | |
35 shouldBe(new RegExp(r"(b)c").firstMatch('abcd'), ["bc", "b"]); | |
36 | |
37 shouldBe(firstMatch('abcdefghi', new RegExp(r"(abc)def(ghi)")), | |
38 ['abcdefghi', 'abc', 'ghi']); | |
39 shouldBe(new RegExp(r"(abc)def(ghi)").firstMatch('abcdefghi'), | |
40 ['abcdefghi', 'abc', 'ghi']); | |
41 | |
42 shouldBe(firstMatch('abcdefghi', new RegExp(r"(a(b(c(d(e)f)g)h)i)")), | |
43 ['abcdefghi', 'abcdefghi', 'bcdefgh', 'cdefg', 'def', 'e']); | |
44 | |
45 shouldBe( | |
46 firstMatch('(100px 200px 150px 15px)', | |
47 new RegExp(r"\((\d+)(px)* (\d+)(px)* (\d+)(px)* (\d+)(px)*\)")), | |
48 [ | |
49 '(100px 200px 150px 15px)', | |
50 '100', | |
51 'px', | |
52 '200', | |
53 'px', | |
54 '150', | |
55 'px', | |
56 '15', | |
57 'px' | |
58 ]); | |
59 shouldBeNull(firstMatch( | |
60 '', new RegExp(r"\((\d+)(px)* (\d+)(px)* (\d+)(px)* (\d+)(px)*\)"))); | |
61 | |
62 var invalidChars = new RegExp(r"[^@\.\w]"); // #47092 | |
63 shouldBeTrue(firstMatch('faure@kde.org', invalidChars) == null); | |
64 shouldBeFalse(firstMatch('faure-kde@kde.org', invalidChars) == null); | |
65 | |
66 assertEquals('test1test2'.replaceAll('test', 'X'), 'X1X2'); | |
67 assertEquals('test1test2'.replaceAll(new RegExp(r"\d"), 'X'), 'testXtestX'); | |
68 assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"), ''), 'testtest'); | |
69 assertEquals('test1test2'.replaceAll(new RegExp(r"test"), 'X'), 'X1X2'); | |
70 assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"), ''), 'testtest'); | |
71 assertEquals('1test2test3'.replaceAll(new RegExp(r"x"), ''), '1test2test3'); | |
72 assertEquals( | |
73 'test1test2'.replaceAllMapped( | |
74 new RegExp(r"(te)(st)"), (m) => "${m.group(2)}${m.group(1)}"), | |
75 'stte1stte2'); | |
76 assertEquals('foo+bar'.replaceAll(new RegExp(r"\+"), '%2B'), 'foo%2Bbar'); | |
77 var caught = false; | |
78 try { | |
79 new RegExp("+"); | |
80 } catch (e) { | |
81 caught = true; | |
82 } | |
83 shouldBeTrue(caught); // #40435 | |
84 assertEquals('foo'.replaceAll(new RegExp(r"z?"), 'x'), 'xfxoxox'); | |
85 assertEquals( | |
86 'test test'.replaceAll(new RegExp(r"\s*"), ''), 'testtest'); // #50985 | |
87 assertEquals( | |
88 'abc\$%@'.replaceAll(new RegExp(r"[^0-9a-z]*", caseSensitive: false), ''), | |
89 'abc'); // #50848 | |
90 assertEquals( | |
91 'ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false), ''), | |
92 ''); // #75292 | |
93 assertEquals( | |
94 '1ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false), ''), | |
95 '1'); // #75292 | |
96 | |
97 Expect.listEquals( | |
98 '1test2test3blah'.split(new RegExp(r"test")), ['1', '2', '3blah']); | |
99 var reg = new RegExp(r"(\d\d )"); | |
100 var str = '98 76 blah'; | |
101 shouldBe(reg.firstMatch(str), ['98 ', '98 ']); | |
102 | |
103 str = "For more information, see Chapter 3.4.5.1"; | |
104 var re = new RegExp(r"(chapter \d+(\.\d)*)", caseSensitive: false); | |
105 // This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1 | |
106 // 'Chapter 3.4.5.1' is the first match and the first value remembered from (C
hapter \d+(\.\d)*). | |
107 // '.1' is the second value remembered from (\.\d) | |
108 shouldBe(firstMatch(str, re), ['Chapter 3.4.5.1', 'Chapter 3.4.5.1', '.1']); | |
109 | |
110 str = "abcDdcba"; | |
111 // The returned array contains D, d. | |
112 re = new RegExp(r"d", caseSensitive: false); | |
113 var matches = re.allMatches(str); | |
114 Expect.listEquals(matches.map((m) => m.group(0)).toList(), ['D', 'd']); | |
115 | |
116 // unicode escape sequence | |
117 shouldBe(firstMatch('abc', new RegExp(r"\u0062")), ['b']); | |
118 } | |
OLD | NEW |