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("This page tests handling of parentheses subexpressions."); |
| 30 |
| 31 var regexp1 = new RegExp(r".*blah.*"); |
| 32 shouldBeNull(regexp1.firstMatch('test')); |
| 33 shouldBe(regexp1.firstMatch('blah'), ['blah']); |
| 34 shouldBe(regexp1.firstMatch('1blah'), ['1blah']); |
| 35 shouldBe(regexp1.firstMatch('blah1'), ['blah1']); |
| 36 shouldBe(regexp1.firstMatch('blah blah blah'), ['blah blah blah']); |
| 37 shouldBe(regexp1.firstMatch('blah\nsecond'), ['blah']); |
| 38 shouldBe(regexp1.firstMatch('first\nblah'), ['blah']); |
| 39 shouldBe(regexp1.firstMatch('first\nblah\nthird'), ['blah']); |
| 40 shouldBe(regexp1.firstMatch('first\nblah2\nblah3'), ['blah2']); |
| 41 |
| 42 var regexp2 = new RegExp(r"^.*blah.*"); |
| 43 shouldBeNull(regexp2.firstMatch('test')); |
| 44 shouldBe(regexp2.firstMatch('blah'), ['blah']); |
| 45 shouldBe(regexp2.firstMatch('1blah'), ['1blah']); |
| 46 shouldBe(regexp2.firstMatch('blah1'), ['blah1']); |
| 47 shouldBe(regexp2.firstMatch('blah blah blah'), ['blah blah blah']); |
| 48 shouldBe(regexp2.firstMatch('blah\nsecond'), ['blah']); |
| 49 shouldBeNull(regexp2.firstMatch('first\nblah')); |
| 50 shouldBeNull(regexp2.firstMatch('first\nblah\nthird')); |
| 51 shouldBeNull(regexp2.firstMatch('first\nblah2\nblah3')); |
| 52 |
| 53 var regexp3 = new RegExp(r".*blah.*$"); |
| 54 shouldBeNull(regexp3.firstMatch('test')); |
| 55 shouldBe(regexp3.firstMatch('blah'), ['blah']); |
| 56 shouldBe(regexp3.firstMatch('1blah'), ['1blah']); |
| 57 shouldBe(regexp3.firstMatch('blah1'), ['blah1']); |
| 58 shouldBe(regexp3.firstMatch('blah blah blah'), ['blah blah blah']); |
| 59 shouldBeNull(regexp3.firstMatch('blah\nsecond')); |
| 60 shouldBe(regexp3.firstMatch('first\nblah'), ['blah']); |
| 61 shouldBeNull(regexp3.firstMatch('first\nblah\nthird')); |
| 62 shouldBe(regexp3.firstMatch('first\nblah2\nblah3'), ['blah3']); |
| 63 |
| 64 var regexp4 = new RegExp(r"^.*blah.*$"); |
| 65 shouldBeNull(regexp4.firstMatch('test')); |
| 66 shouldBe(regexp4.firstMatch('blah'), ['blah']); |
| 67 shouldBe(regexp4.firstMatch('1blah'), ['1blah']); |
| 68 shouldBe(regexp4.firstMatch('blah1'), ['blah1']); |
| 69 shouldBe(regexp4.firstMatch('blah blah blah'), ['blah blah blah']); |
| 70 shouldBeNull(regexp4.firstMatch('blah\nsecond')); |
| 71 shouldBeNull(regexp4.firstMatch('first\nblah')); |
| 72 shouldBeNull(regexp4.firstMatch('first\nblah\nthird')); |
| 73 shouldBeNull(regexp4.firstMatch('first\nblah2\nblah3')); |
| 74 |
| 75 var regexp5 = new RegExp(r".*?blah.*"); |
| 76 shouldBeNull(regexp5.firstMatch('test')); |
| 77 shouldBe(regexp5.firstMatch('blah'), ['blah']); |
| 78 shouldBe(regexp5.firstMatch('1blah'), ['1blah']); |
| 79 shouldBe(regexp5.firstMatch('blah1'), ['blah1']); |
| 80 shouldBe(regexp5.firstMatch('blah blah blah'), ['blah blah blah']); |
| 81 shouldBe(regexp5.firstMatch('blah\nsecond'), ['blah']); |
| 82 shouldBe(regexp5.firstMatch('first\nblah'), ['blah']); |
| 83 shouldBe(regexp5.firstMatch('first\nblah\nthird'), ['blah']); |
| 84 shouldBe(regexp5.firstMatch('first\nblah2\nblah3'), ['blah2']); |
| 85 |
| 86 var regexp6 = new RegExp(r".*blah.*?"); |
| 87 shouldBeNull(regexp6.firstMatch('test')); |
| 88 shouldBe(regexp6.firstMatch('blah'), ['blah']); |
| 89 shouldBe(regexp6.firstMatch('1blah'), ['1blah']); |
| 90 shouldBe(regexp6.firstMatch('blah1'), ['blah']); |
| 91 shouldBe(regexp6.firstMatch('blah blah blah'), ['blah blah blah']); |
| 92 shouldBe(regexp6.firstMatch('blah\nsecond'), ['blah']); |
| 93 shouldBe(regexp6.firstMatch('first\nblah'), ['blah']); |
| 94 shouldBe(regexp6.firstMatch('first\nblah\nthird'), ['blah']); |
| 95 shouldBe(regexp6.firstMatch('first\nblah2\nblah3'), ['blah']); |
| 96 |
| 97 var regexp7 = new RegExp(r"^.*?blah.*?$"); |
| 98 shouldBeNull(regexp7.firstMatch('test')); |
| 99 shouldBe(regexp7.firstMatch('blah'), ['blah']); |
| 100 shouldBe(regexp7.firstMatch('1blah'), ['1blah']); |
| 101 shouldBe(regexp7.firstMatch('blah1'), ['blah1']); |
| 102 shouldBe(regexp7.firstMatch('blah blah blah'), ['blah blah blah']); |
| 103 shouldBeNull(regexp7.firstMatch('blah\nsecond')); |
| 104 shouldBeNull(regexp7.firstMatch('first\nblah')); |
| 105 shouldBeNull(regexp7.firstMatch('first\nblah\nthird')); |
| 106 shouldBeNull(regexp7.firstMatch('first\nblah2\nblah3')); |
| 107 |
| 108 var regexp8 = new RegExp(r"^(.*)blah.*$"); |
| 109 shouldBeNull(regexp8.firstMatch('test')); |
| 110 shouldBe(regexp8.firstMatch('blah'), ['blah','']); |
| 111 shouldBe(regexp8.firstMatch('1blah'), ['1blah','1']); |
| 112 shouldBe(regexp8.firstMatch('blah1'), ['blah1','']); |
| 113 shouldBe(regexp8.firstMatch('blah blah blah'), ['blah blah blah','blah blah ']
); |
| 114 shouldBeNull(regexp8.firstMatch('blah\nsecond')); |
| 115 shouldBeNull(regexp8.firstMatch('first\nblah')); |
| 116 shouldBeNull(regexp8.firstMatch('first\nblah\nthird')); |
| 117 shouldBeNull(regexp8.firstMatch('first\nblah2\nblah3')); |
| 118 |
| 119 var regexp9 = new RegExp(r".*blah.*", multiLine: true); |
| 120 shouldBeNull(regexp9.firstMatch('test')); |
| 121 shouldBe(regexp9.firstMatch('blah'), ['blah']); |
| 122 shouldBe(regexp9.firstMatch('1blah'), ['1blah']); |
| 123 shouldBe(regexp9.firstMatch('blah1'), ['blah1']); |
| 124 shouldBe(regexp9.firstMatch('blah blah blah'), ['blah blah blah']); |
| 125 shouldBe(regexp9.firstMatch('blah\nsecond'), ['blah']); |
| 126 shouldBe(regexp9.firstMatch('first\nblah'), ['blah']); |
| 127 shouldBe(regexp9.firstMatch('first\nblah\nthird'), ['blah']); |
| 128 shouldBe(regexp9.firstMatch('first\nblah2\nblah3'), ['blah2']); |
| 129 |
| 130 var regexp10 = new RegExp(r"^.*blah.*", multiLine: true); |
| 131 shouldBeNull(regexp10.firstMatch('test')); |
| 132 shouldBe(regexp10.firstMatch('blah'), ['blah']); |
| 133 shouldBe(regexp10.firstMatch('1blah'), ['1blah']); |
| 134 shouldBe(regexp10.firstMatch('blah1'), ['blah1']); |
| 135 shouldBe(regexp10.firstMatch('blah blah blah'), ['blah blah blah']); |
| 136 shouldBe(regexp10.firstMatch('blah\nsecond'), ['blah']); |
| 137 shouldBe(regexp10.firstMatch('first\nblah'), ['blah']); |
| 138 shouldBe(regexp10.firstMatch('first\nblah\nthird'), ['blah']); |
| 139 shouldBe(regexp10.firstMatch('first\nblah2\nblah3'), ['blah2']); |
| 140 |
| 141 var regexp11 = new RegExp(r".*(?:blah).*$"); |
| 142 shouldBeNull(regexp11.firstMatch('test')); |
| 143 shouldBe(regexp11.firstMatch('blah'), ['blah']); |
| 144 shouldBe(regexp11.firstMatch('1blah'), ['1blah']); |
| 145 shouldBe(regexp11.firstMatch('blah1'), ['blah1']); |
| 146 shouldBe(regexp11.firstMatch('blah blah blah'), ['blah blah blah']); |
| 147 shouldBeNull(regexp11.firstMatch('blah\nsecond')); |
| 148 shouldBe(regexp11.firstMatch('first\nblah'), ['blah']); |
| 149 shouldBeNull(regexp11.firstMatch('first\nblah\nthird')); |
| 150 shouldBe(regexp11.firstMatch('first\nblah2\nblah3'), ['blah3']); |
| 151 |
| 152 var regexp12 = new RegExp(r".*(?:blah|buzz|bang).*$"); |
| 153 shouldBeNull(regexp12.firstMatch('test')); |
| 154 shouldBe(regexp12.firstMatch('blah'), ['blah']); |
| 155 shouldBe(regexp12.firstMatch('1blah'), ['1blah']); |
| 156 shouldBe(regexp12.firstMatch('blah1'), ['blah1']); |
| 157 shouldBe(regexp12.firstMatch('blah blah blah'), ['blah blah blah']); |
| 158 shouldBeNull(regexp12.firstMatch('blah\nsecond')); |
| 159 shouldBe(regexp12.firstMatch('first\nblah'), ['blah']); |
| 160 shouldBeNull(regexp12.firstMatch('first\nblah\nthird')); |
| 161 shouldBe(regexp12.firstMatch('first\nblah2\nblah3'), ['blah3']); |
| 162 |
| 163 var regexp13 = new RegExp(r".*\n\d+.*"); |
| 164 shouldBe(regexp13.firstMatch('abc\n123'), ['abc\n123']); |
| 165 } |
OLD | NEW |