1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/RegExp/regress-191479.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,164 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* 1.10 + * 1.11 + * Date: 31 January 2003 1.12 + * SUMMARY: Testing regular expressions of form /(x|y){n,}/ 1.13 + * 1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=191479 1.15 + * 1.16 + */ 1.17 +//----------------------------------------------------------------------------- 1.18 +var i = 0; 1.19 +var BUGNUMBER = 191479; 1.20 +var summary = 'Testing regular expressions of form /(x|y){n,}/'; 1.21 +var status = ''; 1.22 +var statusmessages = new Array(); 1.23 +var pattern = ''; 1.24 +var patterns = new Array(); 1.25 +var string = ''; 1.26 +var strings = new Array(); 1.27 +var actualmatch = ''; 1.28 +var actualmatches = new Array(); 1.29 +var expectedmatch = ''; 1.30 +var expectedmatches = new Array(); 1.31 + 1.32 + 1.33 +status = inSection(1); 1.34 +string = '12 3 45'; 1.35 +pattern = /(\d|\d\s){2,}/; 1.36 +actualmatch = string.match(pattern); 1.37 +expectedmatch = Array('12', '2'); 1.38 +addThis(); 1.39 + 1.40 +status = inSection(2); 1.41 +string = '12 3 45'; 1.42 +pattern = /(\d|\d\s){4,}/; 1.43 +actualmatch = string.match(pattern); 1.44 +expectedmatch = Array(string, '5'); 1.45 +addThis(); 1.46 + 1.47 +status = inSection(3); 1.48 +string = '12 3 45'; 1.49 +pattern = /(\d|\d\s)+/; 1.50 +actualmatch = string.match(pattern); 1.51 +expectedmatch = Array('12', '2'); 1.52 +addThis(); 1.53 + 1.54 +status = inSection(4); 1.55 +string = '12 3 45'; 1.56 +pattern = /(\d\s?){4,}/; 1.57 +actualmatch = string.match(pattern); 1.58 +expectedmatch = Array(string, '5'); 1.59 +addThis(); 1.60 + 1.61 +/* 1.62 + * Let's reverse the operands in Sections 1-3 above - 1.63 + */ 1.64 +status = inSection(5); 1.65 +string = '12 3 45'; 1.66 +pattern = /(\d\s|\d){2,}/; 1.67 +actualmatch = string.match(pattern); 1.68 +expectedmatch = Array(string, '5'); 1.69 +addThis(); 1.70 + 1.71 +status = inSection(6); 1.72 +string = '12 3 45'; 1.73 +pattern = /(\d\s|\d){4,}/; 1.74 +actualmatch = string.match(pattern); 1.75 +expectedmatch = Array(string, '5'); 1.76 +addThis(); 1.77 + 1.78 +status = inSection(7); 1.79 +string = '12 3 45'; 1.80 +pattern = /(\d\s|\d)+/; 1.81 +actualmatch = string.match(pattern); 1.82 +expectedmatch = Array(string, '5'); 1.83 +addThis(); 1.84 + 1.85 + 1.86 +/* 1.87 + * Let's take all 7 sections above and make each quantifer non-greedy. 1.88 + * 1.89 + * This is done by appending ? to it. It doesn't change the meaning of 1.90 + * the quantifier, but makes it non-greedy, which affects the results - 1.91 + */ 1.92 +status = inSection(8); 1.93 +string = '12 3 45'; 1.94 +pattern = /(\d|\d\s){2,}?/; 1.95 +actualmatch = string.match(pattern); 1.96 +expectedmatch = Array('12', '2'); 1.97 +addThis(); 1.98 + 1.99 +status = inSection(9); 1.100 +string = '12 3 45'; 1.101 +pattern = /(\d|\d\s){4,}?/; 1.102 +actualmatch = string.match(pattern); 1.103 +expectedmatch = Array('12 3 4', '4'); 1.104 +addThis(); 1.105 + 1.106 +status = inSection(10); 1.107 +string = '12 3 45'; 1.108 +pattern = /(\d|\d\s)+?/; 1.109 +actualmatch = string.match(pattern); 1.110 +expectedmatch = Array('1', '1'); 1.111 +addThis(); 1.112 + 1.113 +status = inSection(11); 1.114 +string = '12 3 45'; 1.115 +pattern = /(\d\s?){4,}?/; 1.116 +actualmatch = string.match(pattern); 1.117 +expectedmatch = Array('12 3 4', '4'); 1.118 +addThis(); 1.119 + 1.120 +status = inSection(12); 1.121 +string = '12 3 45'; 1.122 +pattern = /(\d\s|\d){2,}?/; 1.123 +actualmatch = string.match(pattern); 1.124 +expectedmatch = Array('12 ', '2 '); 1.125 +addThis(); 1.126 + 1.127 +status = inSection(13); 1.128 +string = '12 3 45'; 1.129 +pattern = /(\d\s|\d){4,}?/; 1.130 +actualmatch = string.match(pattern); 1.131 +expectedmatch = Array('12 3 4', '4'); 1.132 +addThis(); 1.133 + 1.134 +status = inSection(14); 1.135 +string = '12 3 45'; 1.136 +pattern = /(\d\s|\d)+?/; 1.137 +actualmatch = string.match(pattern); 1.138 +expectedmatch = Array('1', '1'); 1.139 +addThis(); 1.140 + 1.141 + 1.142 + 1.143 +//----------------------------------------------------------------------------- 1.144 +test(); 1.145 +//----------------------------------------------------------------------------- 1.146 + 1.147 + 1.148 + 1.149 +function addThis() 1.150 +{ 1.151 + statusmessages[i] = status; 1.152 + patterns[i] = pattern; 1.153 + strings[i] = string; 1.154 + actualmatches[i] = actualmatch; 1.155 + expectedmatches[i] = expectedmatch; 1.156 + i++; 1.157 +} 1.158 + 1.159 + 1.160 +function test() 1.161 +{ 1.162 + enterFunc ('test'); 1.163 + printBugNumber(BUGNUMBER); 1.164 + printStatus (summary); 1.165 + testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 1.166 + exitFunc ('test'); 1.167 +}