1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_3/RegExp/regress-209919.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,140 @@ 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: 19 June 2003 1.12 + * SUMMARY: Testing regexp submatches with quantifiers 1.13 + * 1.14 + * See http://bugzilla.mozilla.org/show_bug.cgi?id=209919 1.15 + * 1.16 + */ 1.17 +//----------------------------------------------------------------------------- 1.18 +var i = 0; 1.19 +var BUGNUMBER = 209919; 1.20 +var summary = 'Testing regexp submatches with quantifiers'; 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 +/* 1.34 + * Waldemar: "ECMA-262 15.10.2.5, third algorithm, step 2.1 states that 1.35 + * once the minimum repeat count (which is 0 for *, 1 for +, etc.) has 1.36 + * been satisfied, an atom being repeated must not match the empty string." 1.37 + * 1.38 + * In this example, the minimum repeat count is 0, so the last thing the 1.39 + * capturing parens is permitted to contain is the 'a'. It may NOT go on 1.40 + * to capture the '' at the $ position of 'a', even though '' satifies 1.41 + * the condition b* 1.42 + * 1.43 + */ 1.44 +status = inSection(1); 1.45 +string = 'a'; 1.46 +pattern = /(a|b*)*/; 1.47 +actualmatch = string.match(pattern); 1.48 +expectedmatch = Array(string, 'a'); 1.49 +addThis(); 1.50 + 1.51 + 1.52 +/* 1.53 + * In this example, the minimum repeat count is 5, so the capturing parens 1.54 + * captures the 'a', then goes on to capture the '' at the $ position of 'a' 1.55 + * 4 times before it has to stop. Therefore the last thing it contains is ''. 1.56 + */ 1.57 +status = inSection(2); 1.58 +string = 'a'; 1.59 +pattern = /(a|b*){5,}/; 1.60 +actualmatch = string.match(pattern); 1.61 +expectedmatch = Array(string, ''); 1.62 +addThis(); 1.63 + 1.64 + 1.65 +/* 1.66 + * Reduction of the above examples to contain only the condition b* 1.67 + * inside the capturing parens. This can be even harder to grasp! 1.68 + * 1.69 + * The global match is the '' at the ^ position of 'a', but the parens 1.70 + * is NOT permitted to capture it since the minimum repeat count is 0! 1.71 + */ 1.72 +status = inSection(3); 1.73 +string = 'a'; 1.74 +pattern = /(b*)*/; 1.75 +actualmatch = string.match(pattern); 1.76 +expectedmatch = Array('', undefined); 1.77 +addThis(); 1.78 + 1.79 + 1.80 +/* 1.81 + * Here we have used the + quantifier (repeat count 1) outside the parens. 1.82 + * Therefore the parens must capture at least once before stopping, so it 1.83 + * does capture the '' this time - 1.84 + */ 1.85 +status = inSection(4); 1.86 +string = 'a'; 1.87 +pattern = /(b*)+/; 1.88 +actualmatch = string.match(pattern); 1.89 +expectedmatch = Array('', ''); 1.90 +addThis(); 1.91 + 1.92 + 1.93 +/* 1.94 + * More complex examples - 1.95 + */ 1.96 +pattern = /^\-?(\d{1,}|\.{0,})*(\,\d{1,})?$/; 1.97 + 1.98 +status = inSection(5); 1.99 +string = '100.00'; 1.100 +actualmatch = string.match(pattern); 1.101 +expectedmatch = Array(string, '00', undefined); 1.102 +addThis(); 1.103 + 1.104 +status = inSection(6); 1.105 +string = '100,00'; 1.106 +actualmatch = string.match(pattern); 1.107 +expectedmatch = Array(string, '100', ',00'); 1.108 +addThis(); 1.109 + 1.110 +status = inSection(7); 1.111 +string = '1.000,00'; 1.112 +actualmatch = string.match(pattern); 1.113 +expectedmatch = Array(string, '000', ',00'); 1.114 +addThis(); 1.115 + 1.116 + 1.117 + 1.118 + 1.119 +//----------------------------------------------------------------------------- 1.120 +test(); 1.121 +//----------------------------------------------------------------------------- 1.122 + 1.123 + 1.124 + 1.125 +function addThis() 1.126 +{ 1.127 + statusmessages[i] = status; 1.128 + patterns[i] = pattern; 1.129 + strings[i] = string; 1.130 + actualmatches[i] = actualmatch; 1.131 + expectedmatches[i] = expectedmatch; 1.132 + i++; 1.133 +} 1.134 + 1.135 + 1.136 +function test() 1.137 +{ 1.138 + enterFunc ('test'); 1.139 + printBugNumber(BUGNUMBER); 1.140 + printStatus (summary); 1.141 + testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 1.142 + exitFunc ('test'); 1.143 +}