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( | |
30 'Tests that regular expressions do not have extensions that diverge from t
he JavaScript specification. ' + | |
31 'Because WebKit originally used a copy of PCRE, various non-JavaScript
regular expression features were historically present. ' + | |
32 'Also tests various related edge cases.'); | |
33 | |
34 shouldBeNull(new RegExp(r"\\x{41}").firstMatch("yA1")); | |
35 assertEquals(new RegExp(r"[\x{41}]").firstMatch("yA1").group(0), "1"); | |
36 assertEquals(new RegExp(r"\x1g").firstMatch("x1g").group(0), "x1g"); | |
37 assertEquals(new RegExp(r"[\x1g]").firstMatch("x").group(0), "x"); | |
38 assertEquals(new RegExp(r"[\x1g]").firstMatch("1").group(0), "1"); | |
39 assertEquals( | |
40 new RegExp(r"\2147483648") | |
41 .firstMatch(new String.fromCharCode(140) + "7483648") | |
42 .group(0), | |
43 new String.fromCharCode(140) + "7483648"); | |
44 assertEquals(new RegExp(r"\4294967296").firstMatch("\"94967296").group(0), | |
45 "\"94967296"); | |
46 assertEquals(new RegExp(r"\8589934592").firstMatch("\8589934592").group(0), | |
47 "\8589934592"); | |
48 assertEquals( | |
49 "\nAbc\n".replaceAllMapped(new RegExp(r"(\n)[^\n]+$"), (m) => m.group(1)), | |
50 "\nAbc\n"); | |
51 shouldBeNull(new RegExp(r"x$").firstMatch("x\n")); | |
52 assertThrows(() => new RegExp(r"x++")); | |
53 shouldBeNull(new RegExp(r"[]]").firstMatch("]")); | |
54 | |
55 assertEquals(new RegExp(r"\060").firstMatch("y01").group(0), "0"); | |
56 assertEquals(new RegExp(r"[\060]").firstMatch("y01").group(0), "0"); | |
57 assertEquals(new RegExp(r"\606").firstMatch("y06").group(0), "06"); | |
58 assertEquals(new RegExp(r"[\606]").firstMatch("y06").group(0), "0"); | |
59 assertEquals(new RegExp(r"[\606]").firstMatch("y6").group(0), "6"); | |
60 assertEquals(new RegExp(r"\101").firstMatch("yA1").group(0), "A"); | |
61 assertEquals(new RegExp(r"[\101]").firstMatch("yA1").group(0), "A"); | |
62 assertEquals(new RegExp(r"\1011").firstMatch("yA1").group(0), "A1"); | |
63 assertEquals(new RegExp(r"[\1011]").firstMatch("yA1").group(0), "A"); | |
64 assertEquals(new RegExp(r"[\1011]").firstMatch("y1").group(0), "1"); | |
65 assertEquals( | |
66 new RegExp(r"\10q") | |
67 .firstMatch("y" + new String.fromCharCode(8) + "q") | |
68 .group(0), | |
69 new String.fromCharCode(8) + "q"); | |
70 assertEquals( | |
71 new RegExp(r"[\10q]") | |
72 .firstMatch("y" + new String.fromCharCode(8) + "q") | |
73 .group(0), | |
74 new String.fromCharCode(8)); | |
75 assertEquals( | |
76 new RegExp(r"\1q") | |
77 .firstMatch("y" + new String.fromCharCode(1) + "q") | |
78 .group(0), | |
79 new String.fromCharCode(1) + "q"); | |
80 assertEquals( | |
81 new RegExp(r"[\1q]") | |
82 .firstMatch("y" + new String.fromCharCode(1) + "q") | |
83 .group(0), | |
84 new String.fromCharCode(1)); | |
85 assertEquals(new RegExp(r"[\1q]").firstMatch("yq").group(0), "q"); | |
86 assertEquals(new RegExp(r"\8q").firstMatch("\8q").group(0), "\8q"); | |
87 assertEquals(new RegExp(r"[\8q]").firstMatch("y8q").group(0), "8"); | |
88 assertEquals(new RegExp(r"[\8q]").firstMatch("yq").group(0), "q"); | |
89 shouldBe(new RegExp(r"(x)\1q").firstMatch("xxq"), ["xxq", "x"]); | |
90 shouldBe(new RegExp(r"(x)[\1q]").firstMatch("xxq"), ["xq", "x"]); | |
91 shouldBe( | |
92 new RegExp(r"(x)[\1q]").firstMatch("xx" + new String.fromCharCode(1)), | |
93 ["x" + new String.fromCharCode(1), "x"]); | |
94 } | |
OLD | NEW |