OLD | NEW |
| (Empty) |
1 // Copyright (c) 2014, the Dart project authors. All rights reserved. | |
2 // Copyright 2008 the V8 project authors. All rights reserved. | |
3 // Redistribution and use in source and binary forms, with or without | |
4 // modification, are permitted provided that the following conditions are | |
5 // met: | |
6 // | |
7 // * Redistributions of source code must retain the above copyright | |
8 // notice, this list of conditions and the following disclaimer. | |
9 // * Redistributions in binary form must reproduce the above | |
10 // copyright notice, this list of conditions and the following | |
11 // disclaimer in the documentation and/or other materials provided | |
12 // with the distribution. | |
13 // * Neither the name of Google Inc. nor the names of its | |
14 // contributors may be used to endorse or promote products derived | |
15 // from this software without specific prior written permission. | |
16 // | |
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | |
29 /** | |
30 * @fileoverview Check that various regexp constructs work as intended. | |
31 * Particularly those regexps that use ^ and $. | |
32 */ | |
33 | |
34 import 'v8_regexp_utils.dart'; | |
35 import 'package:expect/expect.dart'; | |
36 | |
37 void main() { | |
38 assertTrue(new RegExp(r"^bar").hasMatch("bar")); | |
39 assertTrue(new RegExp(r"^bar").hasMatch("bar\nfoo")); | |
40 assertFalse(new RegExp(r"^bar").hasMatch("foo\nbar")); | |
41 assertTrue(new RegExp(r"^bar", multiLine: true).hasMatch("bar")); | |
42 assertTrue(new RegExp(r"^bar", multiLine: true).hasMatch("bar\nfoo")); | |
43 assertTrue(new RegExp(r"^bar", multiLine: true).hasMatch("foo\nbar")); | |
44 | |
45 assertTrue(new RegExp(r"bar$").hasMatch("bar")); | |
46 assertFalse(new RegExp(r"bar$").hasMatch("bar\nfoo")); | |
47 assertTrue(new RegExp(r"bar$").hasMatch("foo\nbar")); | |
48 assertTrue(new RegExp(r"bar$", multiLine: true).hasMatch("bar")); | |
49 assertTrue(new RegExp(r"bar$", multiLine: true).hasMatch("bar\nfoo")); | |
50 assertTrue(new RegExp(r"bar$", multiLine: true).hasMatch("foo\nbar")); | |
51 | |
52 assertFalse(new RegExp(r"^bxr").hasMatch("bar")); | |
53 assertFalse(new RegExp(r"^bxr").hasMatch("bar\nfoo")); | |
54 assertFalse(new RegExp(r"^bxr", multiLine: true).hasMatch("bar")); | |
55 assertFalse(new RegExp(r"^bxr", multiLine: true).hasMatch("bar\nfoo")); | |
56 assertFalse(new RegExp(r"^bxr", multiLine: true).hasMatch("foo\nbar")); | |
57 | |
58 assertFalse(new RegExp(r"bxr$").hasMatch("bar")); | |
59 assertFalse(new RegExp(r"bxr$").hasMatch("foo\nbar")); | |
60 assertFalse(new RegExp(r"bxr$", multiLine: true).hasMatch("bar")); | |
61 assertFalse(new RegExp(r"bxr$", multiLine: true).hasMatch("bar\nfoo")); | |
62 assertFalse(new RegExp(r"bxr$", multiLine: true).hasMatch("foo\nbar")); | |
63 | |
64 assertTrue(new RegExp(r"^.*$").hasMatch("")); | |
65 assertTrue(new RegExp(r"^.*$").hasMatch("foo")); | |
66 assertFalse(new RegExp(r"^.*$").hasMatch("\n")); | |
67 assertTrue(new RegExp(r"^.*$", multiLine: true).hasMatch("\n")); | |
68 | |
69 assertTrue(new RegExp(r"^[\s]*$").hasMatch(" ")); | |
70 assertTrue(new RegExp(r"^[\s]*$").hasMatch("\n")); | |
71 | |
72 assertTrue(new RegExp(r"^[^]*$").hasMatch("")); | |
73 assertTrue(new RegExp(r"^[^]*$").hasMatch("foo")); | |
74 assertTrue(new RegExp(r"^[^]*$").hasMatch("\n")); | |
75 | |
76 assertTrue(new RegExp(r"^([()\s]|.)*$").hasMatch("()\n()")); | |
77 assertTrue(new RegExp(r"^([()\n]|.)*$").hasMatch("()\n()")); | |
78 assertFalse(new RegExp(r"^([()]|.)*$").hasMatch("()\n()")); | |
79 assertTrue(new RegExp(r"^([()]|.)*$", multiLine: true).hasMatch("()\n()")); | |
80 assertTrue(new RegExp(r"^([()]|.)*$", multiLine: true).hasMatch("()\n")); | |
81 assertTrue(new RegExp(r"^[()]*$", multiLine: true).hasMatch("()\n.")); | |
82 | |
83 assertTrue(new RegExp(r"^[\].]*$").hasMatch("...]...")); | |
84 | |
85 dynamic check_case(lc, uc) { | |
86 var a = new RegExp("^" + lc + r"$"); | |
87 assertFalse(a.hasMatch(uc)); | |
88 a = new RegExp("^" + lc + r"$", caseSensitive: false); | |
89 assertTrue(a.hasMatch(uc)); | |
90 | |
91 var A = new RegExp("^" + uc + r"$"); | |
92 assertFalse(A.hasMatch(lc)); | |
93 A = new RegExp("^" + uc + r"$", caseSensitive: false); | |
94 assertTrue(A.hasMatch(lc)); | |
95 | |
96 a = new RegExp("^[" + lc + r"]$"); | |
97 assertFalse(a.hasMatch(uc)); | |
98 a = new RegExp("^[" + lc + r"]$", caseSensitive: false); | |
99 assertTrue(a.hasMatch(uc)); | |
100 | |
101 A = new RegExp("^[" + uc + r"]$"); | |
102 assertFalse(A.hasMatch(lc)); | |
103 A = new RegExp("^[" + uc + r"]$", caseSensitive: false); | |
104 assertTrue(A.hasMatch(lc)); | |
105 } | |
106 | |
107 check_case("a", "A"); | |
108 // Aring | |
109 check_case(new String.fromCharCode(229), new String.fromCharCode(197)); | |
110 // Russian G | |
111 check_case(new String.fromCharCode(0x413), new String.fromCharCode(0x433)); | |
112 | |
113 assertThrows(() => new RegExp('[z-a]')); | |
114 } | |
OLD | NEW |