| 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 'Test regular expression processing with alternatives that match consuming
no characters'); | |
| 31 | |
| 32 var emptyStr = ""; | |
| 33 var s1 = "xxxx"; | |
| 34 var s2 = "aaaa"; | |
| 35 var s3 = "aax"; | |
| 36 var s4 = "abab"; | |
| 37 var s5 = "ab"; | |
| 38 var s6 = "xabx"; | |
| 39 var s7 = "g0"; | |
| 40 | |
| 41 // Non-capturing empty first alternative greedy '*' | |
| 42 var re1 = new RegExp(r"(?:|a|z)*"); | |
| 43 shouldBe(firstMatch(emptyStr, re1), [""]); | |
| 44 shouldBe(firstMatch(s1, re1), [""]); | |
| 45 shouldBe(firstMatch(s2, re1), ["aaaa"]); | |
| 46 shouldBe(firstMatch(s3, re1), ["aa"]); | |
| 47 | |
| 48 // Non-capturing empty middle alternative greedy '*' | |
| 49 var re2 = new RegExp(r"(?:a||z)*"); | |
| 50 shouldBe(firstMatch(emptyStr, re2), [""]); | |
| 51 shouldBe(firstMatch(s1, re2), [""]); | |
| 52 shouldBe(firstMatch(s2, re2), ["aaaa"]); | |
| 53 shouldBe(firstMatch(s3, re2), ["aa"]); | |
| 54 | |
| 55 // Non-capturing empty last alternative greedy '*' | |
| 56 var re3 = new RegExp(r"(?:a|z|)*"); | |
| 57 shouldBe(firstMatch(emptyStr, re3), [""]); | |
| 58 shouldBe(firstMatch(s1, re3), [""]); | |
| 59 shouldBe(firstMatch(s2, re3), ["aaaa"]); | |
| 60 shouldBe(firstMatch(s3, re3), ["aa"]); | |
| 61 | |
| 62 // Capturing empty first alternative greedy '*' | |
| 63 var re4 = new RegExp(r"(|a|z)*"); | |
| 64 shouldBe(firstMatch(emptyStr, re4), ["", null]); | |
| 65 shouldBe(firstMatch(s1, re4), ["", null]); | |
| 66 shouldBe(firstMatch(s2, re4), ["aaaa", "a"]); | |
| 67 shouldBe(firstMatch(s3, re4), ["aa", "a"]); | |
| 68 | |
| 69 // Capturing empty middle alternative greedy '*' | |
| 70 var re5 = new RegExp(r"(a||z)*"); | |
| 71 shouldBe(firstMatch(emptyStr, re5), ["", null]); | |
| 72 shouldBe(firstMatch(s1, re5), ["", null]); | |
| 73 shouldBe(firstMatch(s2, re5), ["aaaa", "a"]); | |
| 74 shouldBe(firstMatch(s3, re5), ["aa", "a"]); | |
| 75 | |
| 76 // Capturing empty last alternative greedy '*' | |
| 77 var re6 = new RegExp(r"(a|z|)*"); | |
| 78 shouldBe(firstMatch(emptyStr, re6), ["", null]); | |
| 79 shouldBe(firstMatch(s1, re6), ["", null]); | |
| 80 shouldBe(firstMatch(s2, re6), ["aaaa", "a"]); | |
| 81 shouldBe(firstMatch(s3, re6), ["aa", "a"]); | |
| 82 | |
| 83 // Non-capturing empty first alternative fixed-count | |
| 84 var re7 = new RegExp(r"(?:|a|z){2,5}"); | |
| 85 shouldBe(firstMatch(emptyStr, re7), [""]); | |
| 86 shouldBe(firstMatch(s1, re7), [""]); | |
| 87 shouldBe(firstMatch(s2, re7), ["aaa"]); | |
| 88 shouldBe(firstMatch(s3, re7), ["aa"]); | |
| 89 | |
| 90 // Non-capturing empty middle alternative fixed-count | |
| 91 var re8 = new RegExp(r"(?:a||z){2,5}"); | |
| 92 shouldBe(firstMatch(emptyStr, re8), [""]); | |
| 93 shouldBe(firstMatch(s1, re8), [""]); | |
| 94 shouldBe(firstMatch(s2, re8), ["aaaa"]); | |
| 95 shouldBe(firstMatch(s3, re8), ["aa"]); | |
| 96 | |
| 97 // Non-capturing empty last alternative fixed-count | |
| 98 var re9 = new RegExp(r"(?:a|z|){2,5}"); | |
| 99 shouldBe(firstMatch(emptyStr, re9), [""]); | |
| 100 shouldBe(firstMatch(s1, re9), [""]); | |
| 101 shouldBe(firstMatch(s2, re9), ["aaaa"]); | |
| 102 shouldBe(firstMatch(s3, re9), ["aa"]); | |
| 103 | |
| 104 // Non-capturing empty first alternative non-greedy '*' | |
| 105 var re10 = new RegExp(r"(?:|a|z)*?"); | |
| 106 shouldBe(firstMatch(emptyStr, re10), [""]); | |
| 107 shouldBe(firstMatch(s1, re10), [""]); | |
| 108 shouldBe(firstMatch(s2, re10), [""]); | |
| 109 shouldBe(firstMatch(s3, re10), [""]); | |
| 110 | |
| 111 // Non-capturing empty middle alternative non-greedy '*' | |
| 112 var re11 = new RegExp(r"(?:a||z)*?"); | |
| 113 shouldBe(firstMatch(emptyStr, re11), [""]); | |
| 114 shouldBe(firstMatch(s1, re11), [""]); | |
| 115 shouldBe(firstMatch(s2, re11), [""]); | |
| 116 shouldBe(firstMatch(s3, re11), [""]); | |
| 117 | |
| 118 // Non-capturing empty last alternative non-greedy '*' | |
| 119 var re12 = new RegExp(r"(?:a|z|)*?"); | |
| 120 shouldBe(firstMatch(emptyStr, re12), [""]); | |
| 121 shouldBe(firstMatch(s1, re12), [""]); | |
| 122 shouldBe(firstMatch(s2, re12), [""]); | |
| 123 shouldBe(firstMatch(s3, re12), [""]); | |
| 124 | |
| 125 // Capturing empty first alternative non-greedy '*' | |
| 126 var re13 = new RegExp(r"(|a|z)*?"); | |
| 127 shouldBe(firstMatch(emptyStr, re13), ["", null]); | |
| 128 shouldBe(firstMatch(s1, re13), ["", null]); | |
| 129 shouldBe(firstMatch(s2, re13), ["", null]); | |
| 130 shouldBe(firstMatch(s3, re13), ["", null]); | |
| 131 | |
| 132 // Capturing empty middle alternative non-greedy '*' | |
| 133 var re14 = new RegExp(r"(a||z)*?"); | |
| 134 shouldBe(firstMatch(emptyStr, re14), ["", null]); | |
| 135 shouldBe(firstMatch(s1, re14), ["", null]); | |
| 136 shouldBe(firstMatch(s2, re14), ["", null]); | |
| 137 shouldBe(firstMatch(s3, re14), ["", null]); | |
| 138 | |
| 139 // Capturing empty last alternative non-greedy '*' | |
| 140 var re15 = new RegExp(r"(a|z|)*?"); | |
| 141 shouldBe(firstMatch(emptyStr, re15), ["", null]); | |
| 142 shouldBe(firstMatch(s1, re15), ["", null]); | |
| 143 shouldBe(firstMatch(s2, re15), ["", null]); | |
| 144 shouldBe(firstMatch(s3, re15), ["", null]); | |
| 145 | |
| 146 // Non-capturing empty first alternative greedy '?' | |
| 147 var re16 = new RegExp(r"(?:|a|z)?"); | |
| 148 shouldBe(firstMatch(emptyStr, re16), [""]); | |
| 149 shouldBe(firstMatch(s1, re16), [""]); | |
| 150 shouldBe(firstMatch(s2, re16), ["a"]); | |
| 151 shouldBe(firstMatch(s3, re16), ["a"]); | |
| 152 | |
| 153 // Non-capturing empty middle alternative greedy '?' | |
| 154 var re17 = new RegExp(r"(?:a||z)?"); | |
| 155 shouldBe(firstMatch(emptyStr, re17), [""]); | |
| 156 shouldBe(firstMatch(s1, re17), [""]); | |
| 157 shouldBe(firstMatch(s2, re17), ["a"]); | |
| 158 shouldBe(firstMatch(s3, re17), ["a"]); | |
| 159 | |
| 160 // Non-capturing empty last alternative greedy '?' | |
| 161 var re18 = new RegExp(r"(?:a|z|)?"); | |
| 162 shouldBe(firstMatch(emptyStr, re18), [""]); | |
| 163 shouldBe(firstMatch(s1, re18), [""]); | |
| 164 shouldBe(firstMatch(s2, re18), ["a"]); | |
| 165 shouldBe(firstMatch(s3, re18), ["a"]); | |
| 166 | |
| 167 // Capturing empty first alternative greedy '?' | |
| 168 var re19 = new RegExp(r"(|a|z)?"); | |
| 169 shouldBe(firstMatch(emptyStr, re19), ["", null]); | |
| 170 shouldBe(firstMatch(s1, re19), ["", null]); | |
| 171 shouldBe(firstMatch(s2, re19), ["a", "a"]); | |
| 172 shouldBe(firstMatch(s3, re19), ["a", "a"]); | |
| 173 | |
| 174 // Capturing empty middle alternative greedy '?' | |
| 175 var re20 = new RegExp(r"(a||z)?"); | |
| 176 shouldBe(firstMatch(emptyStr, re20), ["", null]); | |
| 177 shouldBe(firstMatch(s1, re20), ["", null]); | |
| 178 shouldBe(firstMatch(s2, re20), ["a", "a"]); | |
| 179 shouldBe(firstMatch(s3, re20), ["a", "a"]); | |
| 180 | |
| 181 // Capturing empty last alternative greedy '?' | |
| 182 var re21 = new RegExp(r"(a|z|)?"); | |
| 183 shouldBe(firstMatch(emptyStr, re21), ["", null]); | |
| 184 shouldBe(firstMatch(s1, re21), ["", null]); | |
| 185 shouldBe(firstMatch(s2, re21), ["a", "a"]); | |
| 186 shouldBe(firstMatch(s3, re21), ["a", "a"]); | |
| 187 | |
| 188 // Non-capturing empty first alternative non-greedy '?' | |
| 189 var re22 = new RegExp(r"(?:|a|z)??"); | |
| 190 shouldBe(firstMatch(emptyStr, re22), [""]); | |
| 191 shouldBe(firstMatch(s1, re22), [""]); | |
| 192 shouldBe(firstMatch(s2, re22), [""]); | |
| 193 shouldBe(firstMatch(s3, re22), [""]); | |
| 194 | |
| 195 // Non-capturing empty middle alternative non-greedy '?' | |
| 196 var re23 = new RegExp(r"(?:a||z)??"); | |
| 197 shouldBe(firstMatch(emptyStr, re23), [""]); | |
| 198 shouldBe(firstMatch(s1, re23), [""]); | |
| 199 shouldBe(firstMatch(s2, re23), [""]); | |
| 200 shouldBe(firstMatch(s3, re23), [""]); | |
| 201 | |
| 202 // Non-capturing empty last alternative non-greedy '?' | |
| 203 var re24 = new RegExp(r"(?:a|z|)??"); | |
| 204 shouldBe(firstMatch(emptyStr, re24), [""]); | |
| 205 shouldBe(firstMatch(s1, re24), [""]); | |
| 206 shouldBe(firstMatch(s2, re24), [""]); | |
| 207 shouldBe(firstMatch(s3, re24), [""]); | |
| 208 | |
| 209 // Capturing empty first alternative non-greedy '?' | |
| 210 var re25 = new RegExp(r"(|a|z)??"); | |
| 211 shouldBe(firstMatch(emptyStr, re25), ["", null]); | |
| 212 shouldBe(firstMatch(s1, re25), ["", null]); | |
| 213 shouldBe(firstMatch(s2, re25), ["", null]); | |
| 214 shouldBe(firstMatch(s3, re25), ["", null]); | |
| 215 | |
| 216 // Capturing empty middle alternative non-greedy '?' | |
| 217 var re26 = new RegExp(r"(a||z)??"); | |
| 218 shouldBe(firstMatch(emptyStr, re26), ["", null]); | |
| 219 shouldBe(firstMatch(s1, re26), ["", null]); | |
| 220 shouldBe(firstMatch(s2, re26), ["", null]); | |
| 221 shouldBe(firstMatch(s3, re26), ["", null]); | |
| 222 | |
| 223 // Capturing empty last alternative non-greedy '?' | |
| 224 var re27 = new RegExp(r"(a|z|)??"); | |
| 225 shouldBe(firstMatch(emptyStr, re27), ["", null]); | |
| 226 shouldBe(firstMatch(s1, re27), ["", null]); | |
| 227 shouldBe(firstMatch(s2, re27), ["", null]); | |
| 228 shouldBe(firstMatch(s3, re27), ["", null]); | |
| 229 | |
| 230 // Non-capturing empty first alternative greedy '*' non-terminal | |
| 231 var re28 = new RegExp(r"(?:|a|z)*x"); | |
| 232 shouldBe(firstMatch(emptyStr, re28), null); | |
| 233 shouldBe(firstMatch(s1, re28), ["x"]); | |
| 234 shouldBe(firstMatch(s2, re28), null); | |
| 235 shouldBe(firstMatch(s3, re28), ["aax"]); | |
| 236 | |
| 237 // Non-capturing empty middle alternative greedy '*' non-terminal | |
| 238 var re29 = new RegExp(r"(?:a||z)*x"); | |
| 239 shouldBe(firstMatch(emptyStr, re29), null); | |
| 240 shouldBe(firstMatch(s1, re29), ["x"]); | |
| 241 shouldBe(firstMatch(s2, re29), null); | |
| 242 shouldBe(firstMatch(s3, re29), ["aax"]); | |
| 243 | |
| 244 // Non-capturing empty last alternative greedy '*' non-terminal | |
| 245 var re30 = new RegExp(r"(?:a|z|)*x"); | |
| 246 shouldBe(firstMatch(emptyStr, re30), null); | |
| 247 shouldBe(firstMatch(s1, re30), ["x"]); | |
| 248 shouldBe(firstMatch(s2, re30), null); | |
| 249 shouldBe(firstMatch(s3, re30), ["aax"]); | |
| 250 | |
| 251 // Non-capturing two possibly empty alternatives greedy '*' | |
| 252 var re31 = new RegExp(r"(?:a*|b*)*"); | |
| 253 shouldBe(firstMatch(emptyStr, re31), [""]); | |
| 254 shouldBe(firstMatch(s1, re31), [""]); | |
| 255 shouldBe(firstMatch(s3, re31), ["aa"]); | |
| 256 shouldBe(firstMatch(s4, re31), ["abab"]); | |
| 257 | |
| 258 // Non-capturing two possibly empty non-greedy alternatives non-greedy '*' | |
| 259 var re32 = new RegExp(r"(?:a*?|b*?)*"); | |
| 260 shouldBe(firstMatch(emptyStr, re32), [""]); | |
| 261 shouldBe(firstMatch(s1, re32), [""]); | |
| 262 shouldBe(firstMatch(s2, re32), ["aaaa"]); | |
| 263 shouldBe(firstMatch(s4, re32), ["abab"]); | |
| 264 shouldBe(firstMatch(s5, re32), ["ab"]); | |
| 265 shouldBe(firstMatch(s6, re32), [""]); | |
| 266 | |
| 267 // Three possibly empty alternatives with greedy + | |
| 268 var re33 = new RegExp(r"(?:(?:(?!))|g?|0*\*?)+"); | |
| 269 shouldBe(firstMatch(emptyStr, re33), [""]); | |
| 270 shouldBe(firstMatch(s1, re33), [""]); | |
| 271 shouldBe(firstMatch(s7, re33), ["g0"]); | |
| 272 | |
| 273 // first alternative zero length fixed count | |
| 274 var re34 = new RegExp(r"(?:|a)"); | |
| 275 shouldBe(firstMatch(emptyStr, re34), [""]); | |
| 276 shouldBe(firstMatch(s1, re34), [""]); | |
| 277 shouldBe(firstMatch(s2, re34), [""]); | |
| 278 shouldBe(firstMatch(s3, re34), [""]); | |
| 279 } | |
| OLD | NEW |