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 r; 16 17r = new RegExp ("a"); 18assert (r.exec ("a") == "a"); 19assert (r.exec ("b") == undefined); 20 21r = new RegExp ("abc"); 22assert (r.exec ("abc") == "abc"); 23 24r = new RegExp ("a*"); 25assert (r.exec ("aaa") == "aaa"); 26assert (r.exec ("b") == ""); 27 28r = new RegExp ("a+"); 29assert (r.exec ("aaa") == "aaa"); 30assert (r.exec ("b") == undefined); 31 32r = new RegExp ("ab*"); 33assert (r.exec ("a") == "a"); 34assert (r.exec ("ab") == "ab"); 35assert (r.exec ("abbbb") == "abbbb"); 36assert (r.exec ("bbb") == undefined); 37 38r = new RegExp ("a?"); 39assert (r.exec ("a") == "a"); 40assert (r.exec ("b") == ""); 41 42r = new RegExp ("a{4}"); 43assert (r.exec ("aaa") == undefined); 44assert (r.exec ("aaaaa") == "aaaa"); 45assert (r.exec ("aaaa") == "aaaa"); 46 47r = new RegExp ("a{2,6}"); 48assert (r.exec ("a") == undefined); 49assert (r.exec ("aa") == "aa"); 50assert (r.exec ("aaaaaa") == "aaaaaa"); 51assert (r.exec ("aaaaaaa") == "aaaaaa"); 52 53r = new RegExp (".*"); 54assert (r.exec ("abcdefghijkl") == "abcdefghijkl"); 55 56r = /\n/; 57assert (r.exec ("\n") == "\n"); 58 59assert (/[\12]+/.exec ("1\n\n\n\n\n2") == "\n\n\n\n\n"); 60assert (/[\1284]+/.exec ("1\n\n8\n4\n\n2") == "\n\n8\n4\n\n"); 61assert (/[\89]12/.exec ("1\9128123") == "912"); 62assert (/[\11]/.exec ("1\n\n\t\n\n2") == "\t"); 63assert (/[\142][\143][\144]/.exec ("abcde") == "bcd"); 64 65assert (/\12+/.exec ("1\n\n\n\n\n2") == "\n\n\n\n\n"); 66assert (/\11/.exec ("1\n\n\t\n\n2") == "\t"); 67assert (/\142\143\144/.exec ("abcde") == "bcd"); 68assert (/\942\143\144/.exec ("a942cde") == "942cd"); 69assert (/\14234/.exec ("b34") == "b34"); 70 71assert (/(\d+)\2([abc]+)\1\2/.exec("123abc123abc") == "123abc123abc,123,abc"); 72assert (/([abc]+)\40([d-f]+)\12\1/.exec("abc def\nabc") == "abc def\nabc,abc,def"); 73 74var expected = "8765432911,8,7,6,5,4,3,2,9,1"; 75assert (/(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)\9(\d)\9/.exec("8765432911") == expected); 76 77r = /\c/; 78assert (r.exec ("\\c") == "\\c"); 79 80r = /[\c]/; 81assert (r.exec ("c") == "c"); 82 83r = /[\c1]/; 84assert (r.exec ("\u0011") == "\u0011"); 85 86r = /\c3/; 87assert (r.exec ("\\c3") == "\\c3"); 88 89r = /\cIasd/; 90assert (r.exec ("\tasd") == "\tasd"); 91 92r = /.??$/; 93assert (JSON.stringify (r.exec("asd")) === '["d"]'); 94