1425bb815Sopenharmony_ci// Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci// 3425bb815Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci// you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci// You may obtain a copy of the License at 6425bb815Sopenharmony_ci// 7425bb815Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci// 9425bb815Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci// See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci// limitations under the License. 14425bb815Sopenharmony_ci 15425bb815Sopenharmony_cifunction test_match(re, input, expected) 16425bb815Sopenharmony_ci{ 17425bb815Sopenharmony_ci var result = re.exec(input); 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_ci if (expected === null) 20425bb815Sopenharmony_ci { 21425bb815Sopenharmony_ci assert (result === null); 22425bb815Sopenharmony_ci return; 23425bb815Sopenharmony_ci } 24425bb815Sopenharmony_ci 25425bb815Sopenharmony_ci assert (result !== null); 26425bb815Sopenharmony_ci assert (result.length === expected.length); 27425bb815Sopenharmony_ci 28425bb815Sopenharmony_ci for (var idx = 0; idx < result.length; idx++) 29425bb815Sopenharmony_ci { 30425bb815Sopenharmony_ci assert (result[idx] === expected[idx]); 31425bb815Sopenharmony_ci } 32425bb815Sopenharmony_ci} 33425bb815Sopenharmony_ci 34425bb815Sopenharmony_citest_match (new RegExp ("A{1,2}"), "B", null); 35425bb815Sopenharmony_citest_match (new RegExp ("A{1,2}"), "", null); 36425bb815Sopenharmony_citest_match (new RegExp ("A{1,2}"), "A", ["A"]); 37425bb815Sopenharmony_citest_match (new RegExp ("A{1,2}"), "AA", ["AA"]); 38425bb815Sopenharmony_citest_match (new RegExp ("A{1,2}"), "AAA", ["AA"]); 39425bb815Sopenharmony_ci 40425bb815Sopenharmony_citest_match (new RegExp ("A{1,}"), "B", null); 41425bb815Sopenharmony_citest_match (new RegExp ("A{1,}"), "GA", ["A"]); 42425bb815Sopenharmony_citest_match (new RegExp ("A{1,}"), "FAAAW", ["AAA"]); 43425bb815Sopenharmony_citest_match (new RegExp ("A{1,}"), "FAdAAW", ["A"]); 44425bb815Sopenharmony_ci 45425bb815Sopenharmony_ci/* Test web compatiblity (ES2015 Annex B 1.4) */ 46425bb815Sopenharmony_ci 47425bb815Sopenharmony_citest_match (new RegExp ("A{1,2"), "A", null); 48425bb815Sopenharmony_citest_match (new RegExp ("A{1,2"), "AA", null); 49425bb815Sopenharmony_citest_match (new RegExp ("A{1,2"), "A{1,2", ["A{1,2"]); 50425bb815Sopenharmony_citest_match (new RegExp ("A{1,2"), "AA{1,2", ["A{1,2"]); 51425bb815Sopenharmony_ci 52425bb815Sopenharmony_citest_match (new RegExp ("A{1,"), "A", null); 53425bb815Sopenharmony_citest_match (new RegExp ("A{1,"), "AA", null); 54425bb815Sopenharmony_citest_match (new RegExp ("A{1,"), "A{1,", ["A{1,"]); 55425bb815Sopenharmony_citest_match (new RegExp ("A{1,"), "A{1,2", ["A{1,"]); 56425bb815Sopenharmony_citest_match (new RegExp ("A{1,"), "AA{1,2", ["A{1,"]); 57425bb815Sopenharmony_ci 58425bb815Sopenharmony_citest_match (new RegExp ("A{1"), "A", null); 59425bb815Sopenharmony_citest_match (new RegExp ("A{1"), "AA", null); 60425bb815Sopenharmony_citest_match (new RegExp ("A{1"), "A{1,", ["A{1"]); 61425bb815Sopenharmony_citest_match (new RegExp ("A{1"), "A{1,2", ["A{1"]); 62425bb815Sopenharmony_citest_match (new RegExp ("A{1"), "AA{1,2", ["A{1"]); 63425bb815Sopenharmony_ci 64425bb815Sopenharmony_citest_match (new RegExp ("A{"), "A", null); 65425bb815Sopenharmony_citest_match (new RegExp ("A{"), "AA", null); 66425bb815Sopenharmony_citest_match (new RegExp ("A{"), "A{,", ["A{"]); 67425bb815Sopenharmony_citest_match (new RegExp ("A{"), "A{1,", ["A{"]); 68425bb815Sopenharmony_citest_match (new RegExp ("A{"), "A{1,2", ["A{"]); 69425bb815Sopenharmony_citest_match (new RegExp ("A{"), "AA{1,2", ["A{"]); 70425bb815Sopenharmony_ci 71425bb815Sopenharmony_citest_match (new RegExp ("{"), "", null); 72425bb815Sopenharmony_citest_match (new RegExp ("{"), "AA", null); 73425bb815Sopenharmony_citest_match (new RegExp ("{"), "{,", ["{"]); 74425bb815Sopenharmony_citest_match (new RegExp ("{"), "{1,", ["{"]); 75425bb815Sopenharmony_citest_match (new RegExp ("{"), "{1,2", ["{"]); 76425bb815Sopenharmony_citest_match (new RegExp ("{"), "A{1,2", ["{"]); 77425bb815Sopenharmony_ci 78425bb815Sopenharmony_citest_match (new RegExp ("{{2,3}"), "", null); 79425bb815Sopenharmony_citest_match (new RegExp ("{{2,3}"), "AA", null); 80425bb815Sopenharmony_citest_match (new RegExp ("{{2,3}"), "{{,", ["{{"]); 81425bb815Sopenharmony_citest_match (new RegExp ("{{2,3}"), "{{{,", ["{{{"]); 82425bb815Sopenharmony_citest_match (new RegExp ("{{2,3}"), "{{{{,", ["{{{"]); 83425bb815Sopenharmony_ci 84425bb815Sopenharmony_citest_match (new RegExp ("{{2,3"), "{{{{,", null); 85425bb815Sopenharmony_citest_match (new RegExp ("{{2,3"), "{{2,3,", ["{{2,3"]); 86425bb815Sopenharmony_ci 87425bb815Sopenharmony_citest_match (/A{1,2/, "A", null); 88425bb815Sopenharmony_citest_match (/A{1,2/, "AA", null); 89425bb815Sopenharmony_citest_match (/A{1,2/, "A{1,2", ["A{1,2"]); 90425bb815Sopenharmony_citest_match (/A{1,2/, "AA{1,2", ["A{1,2"]); 91425bb815Sopenharmony_ci 92425bb815Sopenharmony_citest_match (/A{1,/, "A", null); 93425bb815Sopenharmony_citest_match (/A{1,/, "AA", null); 94425bb815Sopenharmony_citest_match (/A{1,/, "A{1,", ["A{1,"]); 95425bb815Sopenharmony_citest_match (/A{1,/, "A{1,2", ["A{1,"]); 96425bb815Sopenharmony_citest_match (/A{1,/, "AA{1,2", ["A{1,"]); 97425bb815Sopenharmony_ci 98425bb815Sopenharmony_citest_match (/A{1/, "A", null); 99425bb815Sopenharmony_citest_match (/A{1/, "AA", null); 100425bb815Sopenharmony_citest_match (/A{1/, "A{1,", ["A{1"]); 101425bb815Sopenharmony_citest_match (/A{1/, "A{1,2", ["A{1"]); 102425bb815Sopenharmony_citest_match (/A{1/, "AA{1,2", ["A{1"]); 103425bb815Sopenharmony_ci 104425bb815Sopenharmony_citest_match (/A{/, "A", null); 105425bb815Sopenharmony_citest_match (/A{/, "AA", null); 106425bb815Sopenharmony_citest_match (/A{/, "A{,", ["A{"]); 107425bb815Sopenharmony_citest_match (/A{/, "A{1,", ["A{"]); 108425bb815Sopenharmony_citest_match (/A{/, "A{1,2", ["A{"]); 109425bb815Sopenharmony_citest_match (/A{/, "AA{1,2", ["A{"]); 110425bb815Sopenharmony_ci 111425bb815Sopenharmony_citest_match (/{/, "", null); 112425bb815Sopenharmony_citest_match (/{/, "AA", null); 113425bb815Sopenharmony_citest_match (/{/, "{,", ["{"]); 114425bb815Sopenharmony_citest_match (/{/, "{1,", ["{"]); 115425bb815Sopenharmony_citest_match (/{/, "{1,2", ["{"]); 116425bb815Sopenharmony_citest_match (/{/, "A{1,2", ["{"]); 117425bb815Sopenharmony_ci 118425bb815Sopenharmony_citest_match (/{{2,3}/, "", null); 119425bb815Sopenharmony_citest_match (/{{2,3}/, "AA", null); 120425bb815Sopenharmony_citest_match (/{{2,3}/, "{{,", ["{{"]); 121425bb815Sopenharmony_citest_match (/{{2,3}/, "{{{,", ["{{{"]); 122425bb815Sopenharmony_citest_match (/{{2,3}/, "{{{{,", ["{{{"]); 123425bb815Sopenharmony_ci 124425bb815Sopenharmony_citest_match (/{{2,3/, "{{{{,", null); 125425bb815Sopenharmony_citest_match (/{{2,3/, "{{2,3,", ["{{2,3"]); 126425bb815Sopenharmony_ci 127425bb815Sopenharmony_citry { 128425bb815Sopenharmony_ci new RegExp ("["); 129425bb815Sopenharmony_ci assert (false); 130425bb815Sopenharmony_ci} catch (ex) { 131425bb815Sopenharmony_ci assert (ex instanceof SyntaxError); 132425bb815Sopenharmony_ci} 133425bb815Sopenharmony_ci 134425bb815Sopenharmony_citry { 135425bb815Sopenharmony_ci eval ("/[/"); 136425bb815Sopenharmony_ci assert (false); 137425bb815Sopenharmony_ci} catch (ex) { 138425bb815Sopenharmony_ci assert (ex instanceof SyntaxError); 139425bb815Sopenharmony_ci} 140425bb815Sopenharmony_ci 141425bb815Sopenharmony_citry { 142425bb815Sopenharmony_ci new RegExp ("("); 143425bb815Sopenharmony_ci assert (false); 144425bb815Sopenharmony_ci} catch (ex) { 145425bb815Sopenharmony_ci assert (ex instanceof SyntaxError); 146425bb815Sopenharmony_ci} 147425bb815Sopenharmony_ci 148425bb815Sopenharmony_citry { 149425bb815Sopenharmony_ci eval ("/(/"); 150425bb815Sopenharmony_ci assert (false); 151425bb815Sopenharmony_ci} catch (ex) { 152425bb815Sopenharmony_ci assert (ex instanceof SyntaxError); 153425bb815Sopenharmony_ci} 154425bb815Sopenharmony_ci 155425bb815Sopenharmony_citest_match (new RegExp("\s+{3,4"), "s+{3,4", null); 156425bb815Sopenharmony_citest_match (new RegExp("\s+{3,4"), "s{3,4", ["s{3,4"]); 157425bb815Sopenharmony_citest_match (new RegExp("\s+{3,4"), "ss{3,4", ["ss{3,4"]); 158425bb815Sopenharmony_citest_match (new RegExp("\\s+{3,4"), " {3,4", [" {3,4"]); 159425bb815Sopenharmony_citest_match (new RegExp("\\s+{3,4"), " d{3,4", null); 160425bb815Sopenharmony_ci 161425bb815Sopenharmony_citest_match (/s+{3,4/, "s+{3,4", null); 162425bb815Sopenharmony_citest_match (/s+{3,4/, "s{3,4", ["s{3,4"]); 163425bb815Sopenharmony_citest_match (/s+{3,4/, "ss{3,4", ["ss{3,4"]); 164425bb815Sopenharmony_citest_match (/\s+{3,4/, " {3,4", [" {3,4"]); 165425bb815Sopenharmony_citest_match (/\s+{3,4/, " d{3,4", null); 166425bb815Sopenharmony_ci 167425bb815Sopenharmony_citry { 168425bb815Sopenharmony_ci new RegExp ("\s+{3,4}"); 169425bb815Sopenharmony_ci assert (false); 170425bb815Sopenharmony_ci} catch (ex) { 171425bb815Sopenharmony_ci assert (ex instanceof SyntaxError); 172425bb815Sopenharmony_ci} 173425bb815Sopenharmony_ci 174425bb815Sopenharmony_citry { 175425bb815Sopenharmony_ci eval ("/\\s+{3,4}/"); 176425bb815Sopenharmony_ci assert (false); 177425bb815Sopenharmony_ci} catch (ex) { 178425bb815Sopenharmony_ci assert (ex instanceof SyntaxError); 179425bb815Sopenharmony_ci} 180425bb815Sopenharmony_ci 181425bb815Sopenharmony_citry { 182425bb815Sopenharmony_ci new RegExp ("a{2,3}{2,3}"); 183425bb815Sopenharmony_ci assert (false); 184425bb815Sopenharmony_ci} catch (ex) { 185425bb815Sopenharmony_ci assert (ex instanceof SyntaxError); 186425bb815Sopenharmony_ci} 187425bb815Sopenharmony_ci 188425bb815Sopenharmony_citry { 189425bb815Sopenharmony_ci eval ("/a{2,3}{2,3}/"); 190425bb815Sopenharmony_ci assert (false); 191425bb815Sopenharmony_ci} catch (ex) { 192425bb815Sopenharmony_ci assert (ex instanceof SyntaxError); 193425bb815Sopenharmony_ci} 194