1 // Copyright 2013 the V8 project authors. All rights reserved. 2 // Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 3 // 4 // Redistribution and use in source and binary forms, with or without 5 // modification, are permitted provided that the following conditions 6 // are met: 7 // 1. Redistributions of source code must retain the above copyright 8 // notice, this list of conditions and the following disclaimer. 9 // 2. Redistributions in binary form must reproduce the above copyright 10 // notice, this list of conditions and the following disclaimer in the 11 // documentation and/or other materials provided with the distribution. 12 // 13 // THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY 14 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 // DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY 17 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 20 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 24 description("This page tests handling of parentheses subexpressions."); 25 26 var regexp1 = /.*blah.*/; 27 shouldBeNull("regexp1.exec('test')"); 28 shouldBe("regexp1.exec('blah')", "['blah']"); 29 shouldBe("regexp1.exec('1blah')", "['1blah']"); 30 shouldBe("regexp1.exec('blah1')", "['blah1']"); 31 shouldBe("regexp1.exec('blah blah blah')", "['blah blah blah']"); 32 shouldBe("regexp1.exec('blah\\nsecond')", "['blah']"); 33 shouldBe("regexp1.exec('first\\nblah')", "['blah']"); 34 shouldBe("regexp1.exec('first\\nblah\\nthird')", "['blah']"); 35 shouldBe("regexp1.exec('first\\nblah2\\nblah3')", "['blah2']"); 36 37 var regexp2 = /^.*blah.*/; 38 shouldBeNull("regexp2.exec('test')"); 39 shouldBe("regexp2.exec('blah')", "['blah']"); 40 shouldBe("regexp2.exec('1blah')", "['1blah']"); 41 shouldBe("regexp2.exec('blah1')", "['blah1']"); 42 shouldBe("regexp2.exec('blah blah blah')", "['blah blah blah']"); 43 shouldBe("regexp2.exec('blah\\nsecond')", "['blah']"); 44 shouldBeNull("regexp2.exec('first\\nblah')"); 45 shouldBeNull("regexp2.exec('first\\nblah\\nthird')"); 46 shouldBeNull("regexp2.exec('first\\nblah2\\nblah3')"); 47 48 var regexp3 = /.*blah.*$/; 49 shouldBeNull("regexp3.exec('test')"); 50 shouldBe("regexp3.exec('blah')", "['blah']"); 51 shouldBe("regexp3.exec('1blah')", "['1blah']"); 52 shouldBe("regexp3.exec('blah1')", "['blah1']"); 53 shouldBe("regexp3.exec('blah blah blah')", "['blah blah blah']"); 54 shouldBeNull("regexp3.exec('blah\\nsecond')"); 55 shouldBe("regexp3.exec('first\\nblah')", "['blah']"); 56 shouldBeNull("regexp3.exec('first\\nblah\\nthird')"); 57 shouldBe("regexp3.exec('first\\nblah2\\nblah3')", "['blah3']"); 58 59 var regexp4 = /^.*blah.*$/; 60 shouldBeNull("regexp4.exec('test')"); 61 shouldBe("regexp4.exec('blah')", "['blah']"); 62 shouldBe("regexp4.exec('1blah')", "['1blah']"); 63 shouldBe("regexp4.exec('blah1')", "['blah1']"); 64 shouldBe("regexp4.exec('blah blah blah')", "['blah blah blah']"); 65 shouldBeNull("regexp4.exec('blah\\nsecond')"); 66 shouldBeNull("regexp4.exec('first\\nblah')"); 67 shouldBeNull("regexp4.exec('first\\nblah\\nthird')"); 68 shouldBeNull("regexp4.exec('first\\nblah2\\nblah3')"); 69 70 var regexp5 = /.*?blah.*/; 71 shouldBeNull("regexp5.exec('test')"); 72 shouldBe("regexp5.exec('blah')", "['blah']"); 73 shouldBe("regexp5.exec('1blah')", "['1blah']"); 74 shouldBe("regexp5.exec('blah1')", "['blah1']"); 75 shouldBe("regexp5.exec('blah blah blah')", "['blah blah blah']"); 76 shouldBe("regexp5.exec('blah\\nsecond')", "['blah']"); 77 shouldBe("regexp5.exec('first\\nblah')", "['blah']"); 78 shouldBe("regexp5.exec('first\\nblah\\nthird')", "['blah']"); 79 shouldBe("regexp5.exec('first\\nblah2\\nblah3')", "['blah2']"); 80 81 var regexp6 = /.*blah.*?/; 82 shouldBeNull("regexp6.exec('test')"); 83 shouldBe("regexp6.exec('blah')", "['blah']"); 84 shouldBe("regexp6.exec('1blah')", "['1blah']"); 85 shouldBe("regexp6.exec('blah1')", "['blah']"); 86 shouldBe("regexp6.exec('blah blah blah')", "['blah blah blah']"); 87 shouldBe("regexp6.exec('blah\\nsecond')", "['blah']"); 88 shouldBe("regexp6.exec('first\\nblah')", "['blah']"); 89 shouldBe("regexp6.exec('first\\nblah\\nthird')", "['blah']"); 90 shouldBe("regexp6.exec('first\\nblah2\\nblah3')", "['blah']"); 91 92 var regexp7 = /^.*?blah.*?$/; 93 shouldBeNull("regexp7.exec('test')"); 94 shouldBe("regexp7.exec('blah')", "['blah']"); 95 shouldBe("regexp7.exec('1blah')", "['1blah']"); 96 shouldBe("regexp7.exec('blah1')", "['blah1']"); 97 shouldBe("regexp7.exec('blah blah blah')", "['blah blah blah']"); 98 shouldBeNull("regexp7.exec('blah\\nsecond')"); 99 shouldBeNull("regexp7.exec('first\\nblah')"); 100 shouldBeNull("regexp7.exec('first\\nblah\\nthird')"); 101 shouldBeNull("regexp7.exec('first\\nblah2\\nblah3')"); 102 103 var regexp8 = /^(.*)blah.*$/; 104 shouldBeNull("regexp8.exec('test')"); 105 shouldBe("regexp8.exec('blah')", "['blah','']"); 106 shouldBe("regexp8.exec('1blah')", "['1blah','1']"); 107 shouldBe("regexp8.exec('blah1')", "['blah1','']"); 108 shouldBe("regexp8.exec('blah blah blah')", "['blah blah blah','blah blah ']"); 109 shouldBeNull("regexp8.exec('blah\\nsecond')"); 110 shouldBeNull("regexp8.exec('first\\nblah')"); 111 shouldBeNull("regexp8.exec('first\\nblah\\nthird')"); 112 shouldBeNull("regexp8.exec('first\\nblah2\\nblah3')"); 113 114 var regexp9 = /.*blah.*/m; 115 shouldBeNull("regexp9.exec('test')"); 116 shouldBe("regexp9.exec('blah')", "['blah']"); 117 shouldBe("regexp9.exec('1blah')", "['1blah']"); 118 shouldBe("regexp9.exec('blah1')", "['blah1']"); 119 shouldBe("regexp9.exec('blah blah blah')", "['blah blah blah']"); 120 shouldBe("regexp9.exec('blah\\nsecond')", "['blah']"); 121 shouldBe("regexp9.exec('first\\nblah')", "['blah']"); 122 shouldBe("regexp9.exec('first\\nblah\\nthird')", "['blah']"); 123 shouldBe("regexp9.exec('first\\nblah2\\nblah3')", "['blah2']"); 124 125 var regexp10 = /^.*blah.*/m; 126 shouldBeNull("regexp10.exec('test')"); 127 shouldBe("regexp10.exec('blah')", "['blah']"); 128 shouldBe("regexp10.exec('1blah')", "['1blah']"); 129 shouldBe("regexp10.exec('blah1')", "['blah1']"); 130 shouldBe("regexp10.exec('blah blah blah')", "['blah blah blah']"); 131 shouldBe("regexp10.exec('blah\\nsecond')", "['blah']"); 132 shouldBe("regexp10.exec('first\\nblah')", "['blah']"); 133 shouldBe("regexp10.exec('first\\nblah\\nthird')", "['blah']"); 134 shouldBe("regexp10.exec('first\\nblah2\\nblah3')", "['blah2']"); 135 136 var regexp11 = /.*(?:blah).*$/; 137 shouldBeNull("regexp11.exec('test')"); 138 shouldBe("regexp11.exec('blah')", "['blah']"); 139 shouldBe("regexp11.exec('1blah')", "['1blah']"); 140 shouldBe("regexp11.exec('blah1')", "['blah1']"); 141 shouldBe("regexp11.exec('blah blah blah')", "['blah blah blah']"); 142 shouldBeNull("regexp11.exec('blah\\nsecond')"); 143 shouldBe("regexp11.exec('first\\nblah')", "['blah']"); 144 shouldBeNull("regexp11.exec('first\\nblah\\nthird')"); 145 shouldBe("regexp11.exec('first\\nblah2\\nblah3')", "['blah3']"); 146 147 var regexp12 = /.*(?:blah|buzz|bang).*$/; 148 shouldBeNull("regexp12.exec('test')"); 149 shouldBe("regexp12.exec('blah')", "['blah']"); 150 shouldBe("regexp12.exec('1blah')", "['1blah']"); 151 shouldBe("regexp12.exec('blah1')", "['blah1']"); 152 shouldBe("regexp12.exec('blah blah blah')", "['blah blah blah']"); 153 shouldBeNull("regexp12.exec('blah\\nsecond')"); 154 shouldBe("regexp12.exec('first\\nblah')", "['blah']"); 155 shouldBeNull("regexp12.exec('first\\nblah\\nthird')"); 156 shouldBe("regexp12.exec('first\\nblah2\\nblah3')", "['blah3']"); 157 158 var regexp13 = /.*\n\d+.*/; 159 shouldBe("regexp13.exec('abc\\n123')", "['abc\\n123']"); 160