1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15var t; 16 17t = new RegExp ("^alma$").exec("alma"); 18assert (t == "alma"); 19 20t = new RegExp ("^alma$").exec("almaa"); 21assert (t == undefined); 22 23t = new RegExp ("^alma$").exec("aalma"); 24assert (t == undefined); 25 26t = new RegExp ("^alma").exec("alma"); 27assert (t == "alma"); 28 29t = new RegExp ("^alma").exec("almaa"); 30assert (t == "alma"); 31 32t = new RegExp ("^alma").exec("aalma"); 33assert (t == undefined); 34 35t = new RegExp ("alma$").exec("alma"); 36assert (t == "alma"); 37 38t = new RegExp ("alma$").exec("almaa"); 39assert (t == undefined); 40 41t = new RegExp ("alma$").exec("aalma"); 42assert (t == "alma"); 43 44t = new RegExp ("\\bis\\b").exec("This island is beautiful"); 45assert (t == "is"); 46 47t = new RegExp ("\\Bis\\B").exec("This island is beautiful"); 48assert (t == undefined); 49 50t = new RegExp ("\\Bis").exec("This island is beautiful"); 51assert (t == "is"); 52 53t = new RegExp ("is\\B").exec("This island is beautiful"); 54assert (t == "is"); 55 56t = new RegExp ("\\Bis\\b").exec("This island is beautiful"); 57assert (t == "is"); 58 59t = new RegExp ("\\bis\\B").exec("This island is beautiful"); 60assert (t == "is"); 61 62t = new RegExp ("al(?=(ma))").exec("al"); 63assert (t == undefined); 64 65t = new RegExp ("al(?!(ma))").exec("ala"); 66assert (t[0] == "al"); 67assert (t[1] == undefined); 68 69t = new RegExp ("al(?=(ma))").exec("alma"); 70assert (t[0] == "al"); 71assert (t[1] == "ma"); 72 73t = new RegExp ("al(?=(ma))").exec("almama"); 74assert (t[0] == "al"); 75assert (t[1] == "ma"); 76 77t = new RegExp ("(al)(?=(ma))ma").exec("al"); 78assert (t == undefined); 79 80t = new RegExp ("(al)(?=(ma)ma)").exec("al"); 81assert (t == undefined); 82 83t = new RegExp ("al(?=(ma))*ma").exec("alma"); 84assert (t[0] == "alma"); 85assert (t[1] == undefined); 86 87t = new RegExp ("al(?!(ma))*ma").exec("alma"); 88assert (t[0] == "alma"); 89assert (t[1] == undefined); 90 91t = new RegExp ("al(?=(ma))ma").exec("alma"); 92assert (t[0] == "alma"); 93assert (t[1] == "ma"); 94 95t = new RegExp ("al(?!(ma))ma").exec("alma"); 96assert (t == undefined); 97 98t = new RegExp ("(al)(?=(ma))ma").exec("almama"); 99t = new RegExp ("(al)(?=(ma)ma)").exec("almama"); 100 101t = new RegExp ("al(?=(ma))ma").exec("almama"); 102assert (t[0] == "alma"); 103assert (t[1] == "ma"); 104 105t = new RegExp ("al(?=(ma)ma)").exec("almama"); 106assert (t[0] == "al"); 107assert (t[1] == "ma"); 108 109t = new RegExp ("al(?!(ma))ma").exec("almama"); 110assert (t == undefined); 111 112t = new RegExp ("a(?=(a)(a))aab|aaac").exec("aaac"); 113t = new RegExp ("a(?=(a)(a))aab|aaac").exec("aaab"); 114 115t = new RegExp ("(?!(a)b)|ab").exec("ab"); 116assert (t[0] == "ab"); 117assert (t[1] == undefined); 118 119t = new RegExp ("(?=(a)b)|ab").exec("ab"); 120assert (t[0] == ""); 121assert (t[1] == "a"); 122 123t = new RegExp ("(?=a|.)Dt").exec("Dt"); 124assert (t == "Dt"); 125 126t = new RegExp ("(?=.|a)Dt").exec("Dt"); 127assert (t == "Dt"); 128 129t = new RegExp ("(?=a|b)Dt").exec("Dt"); 130assert (t == undefined); 131 132t = new RegExp ("(?=.|P)").exec("a"); 133assert (t == ""); 134 135t = new RegExp ("(?=.)").exec("a"); 136assert (t == ""); 137 138t = new RegExp ("(?!a|.)Dt").exec("Dt"); 139assert (t == undefined); 140 141t = new RegExp ("(?!.|a)Dt").exec("Dt"); 142assert (t == undefined); 143 144t = new RegExp ("(?!a|b)Dt").exec("Dt"); 145assert (t == "Dt"); 146 147t = new RegExp ("(?!.|P)").exec("a"); 148assert (t == ""); 149 150t = new RegExp ("(?!.)").exec("a"); 151assert (t == ""); 152 153t = new RegExp ("abc","g"); 154t.lastIndex = {toString: function () { return "4"}}; 155var result = t.exec("abc abc"); 156assert(result[0] === "abc"); 157assert(result.index === 6); 158 159t = new RegExp ("abc","g"); 160t.lastIndex = {valueOf: function () { return "4"}}; 161var result = t.exec("abc abc"); 162assert(result[0] === "abc"); 163assert(result.index === 6); 164 165t = new RegExp ("abc","g"); 166t.lastIndex = "2" 167var result = t.exec("abc abc"); 168assert(result[0] === "abc"); 169assert(result.index === 6); 170