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)")), ['abcdefghi',
'abc', 'ghi']); |
| 38 shouldBe(new RegExp(r"(abc)def(ghi)").firstMatch('abcdefghi'), ['abcdefghi', '
abc', 'ghi']); |
| 39 |
| 40 shouldBe(firstMatch('abcdefghi', new RegExp(r"(a(b(c(d(e)f)g)h)i)")), ['abcdef
ghi', 'abcdefghi', 'bcdefgh', 'cdefg', 'def', 'e']); |
| 41 |
| 42 shouldBe(firstMatch('(100px 200px 150px 15px)', new RegExp(r"\((\d+)(px)* (\d+
)(px)* (\d+)(px)* (\d+)(px)*\)")), |
| 43 ['(100px 200px 150px 15px)', '100', 'px', '200', 'px', '150', 'px', '1
5', 'px']); |
| 44 shouldBeNull(firstMatch('', new RegExp(r"\((\d+)(px)* (\d+)(px)* (\d+)(px)* (\
d+)(px)*\)"))); |
| 45 |
| 46 var invalidChars = new RegExp(r"[^@\.\w]"); // #47092 |
| 47 shouldBeTrue(firstMatch('faure@kde.org', invalidChars) == null); |
| 48 shouldBeFalse(firstMatch('faure-kde@kde.org', invalidChars) == null); |
| 49 |
| 50 assertEquals('test1test2'.replaceAll('test','X'),'X1X2'); |
| 51 assertEquals('test1test2'.replaceAll(new RegExp(r"\d"),'X'),'testXtestX'); |
| 52 assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"),''),'testtest'); |
| 53 assertEquals('test1test2'.replaceAll(new RegExp(r"test"),'X'),'X1X2'); |
| 54 assertEquals('1test2test3'.replaceAll(new RegExp(r"\d"),''),'testtest'); |
| 55 assertEquals('1test2test3'.replaceAll(new RegExp(r"x"),''),'1test2test3'); |
| 56 assertEquals('test1test2'.replaceAllMapped(new RegExp(r"(te)(st)"), |
| 57 (m) => "${m.group(2)}${m.group(1)}"),'stte1stte2'); |
| 58 assertEquals('foo+bar'.replaceAll(new RegExp(r"\+"),'%2B'), 'foo%2Bbar'); |
| 59 var caught = false; try { new RegExp("+"); } catch (e) { caught = true; } |
| 60 shouldBeTrue(caught); // #40435 |
| 61 assertEquals('foo'.replaceAll(new RegExp(r"z?"),'x'), 'xfxoxox'); |
| 62 assertEquals('test test'.replaceAll(new RegExp(r"\s*"),''),'testtest'); // #50
985 |
| 63 assertEquals('abc\$%@'.replaceAll(new RegExp(r"[^0-9a-z]*", caseSensitive: fal
se),''),'abc'); // #50848 |
| 64 assertEquals('ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false),'')
,''); // #75292 |
| 65 assertEquals('1ab'.replaceAll(new RegExp(r"[^\d\.]*", caseSensitive: false),''
),'1'); // #75292 |
| 66 |
| 67 Expect.listEquals('1test2test3blah'.split(new RegExp(r"test")), ['1', '2', '3b
lah']); |
| 68 var reg = new RegExp(r"(\d\d )"); |
| 69 var str = '98 76 blah'; |
| 70 shouldBe(reg.firstMatch(str),['98 ', '98 ']); |
| 71 |
| 72 str = "For more information, see Chapter 3.4.5.1"; |
| 73 var re = new RegExp(r"(chapter \d+(\.\d)*)", caseSensitive: false); |
| 74 // This returns the array containing Chapter 3.4.5.1,Chapter 3.4.5.1,.1 |
| 75 // 'Chapter 3.4.5.1' is the first match and the first value remembered from (C
hapter \d+(\.\d)*). |
| 76 // '.1' is the second value remembered from (\.\d) |
| 77 shouldBe(firstMatch(str, re),['Chapter 3.4.5.1', 'Chapter 3.4.5.1', '.1']); |
| 78 |
| 79 str = "abcDdcba"; |
| 80 // The returned array contains D, d. |
| 81 re = new RegExp(r"d", caseSensitive: false); |
| 82 var matches = re.allMatches(str); |
| 83 Expect.listEquals( |
| 84 matches.map((m) => m.group(0)).toList(), |
| 85 ['D', 'd']); |
| 86 |
| 87 // unicode escape sequence |
| 88 shouldBe(firstMatch('abc', new RegExp(r"\u0062")), ['b']); |
| 89 } |
OLD | NEW |