regress-191479.js (3817B)
1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */ 2 /* This Source Code Form is subject to the terms of the Mozilla Public 3 * License, v. 2.0. If a copy of the MPL was not distributed with this 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 5 6 /* 7 * 8 * Date: 31 January 2003 9 * SUMMARY: Testing regular expressions of form /(x|y){n,}/ 10 * 11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=191479 12 * 13 */ 14 //----------------------------------------------------------------------------- 15 var i = 0; 16 var BUGNUMBER = 191479; 17 var summary = 'Testing regular expressions of form /(x|y){n,}/'; 18 var status = ''; 19 var statusmessages = new Array(); 20 var pattern = ''; 21 var patterns = new Array(); 22 var string = ''; 23 var strings = new Array(); 24 var actualmatch = ''; 25 var actualmatches = new Array(); 26 var expectedmatch = ''; 27 var expectedmatches = new Array(); 28 29 30 status = inSection(1); 31 string = '12 3 45'; 32 pattern = /(\d|\d\s){2,}/; 33 actualmatch = string.match(pattern); 34 expectedmatch = Array('12', '2'); 35 addThis(); 36 37 status = inSection(2); 38 string = '12 3 45'; 39 pattern = /(\d|\d\s){4,}/; 40 actualmatch = string.match(pattern); 41 expectedmatch = Array(string, '5'); 42 addThis(); 43 44 status = inSection(3); 45 string = '12 3 45'; 46 pattern = /(\d|\d\s)+/; 47 actualmatch = string.match(pattern); 48 expectedmatch = Array('12', '2'); 49 addThis(); 50 51 status = inSection(4); 52 string = '12 3 45'; 53 pattern = /(\d\s?){4,}/; 54 actualmatch = string.match(pattern); 55 expectedmatch = Array(string, '5'); 56 addThis(); 57 58 /* 59 * Let's reverse the operands in Sections 1-3 above - 60 */ 61 status = inSection(5); 62 string = '12 3 45'; 63 pattern = /(\d\s|\d){2,}/; 64 actualmatch = string.match(pattern); 65 expectedmatch = Array(string, '5'); 66 addThis(); 67 68 status = inSection(6); 69 string = '12 3 45'; 70 pattern = /(\d\s|\d){4,}/; 71 actualmatch = string.match(pattern); 72 expectedmatch = Array(string, '5'); 73 addThis(); 74 75 status = inSection(7); 76 string = '12 3 45'; 77 pattern = /(\d\s|\d)+/; 78 actualmatch = string.match(pattern); 79 expectedmatch = Array(string, '5'); 80 addThis(); 81 82 83 /* 84 * Let's take all 7 sections above and make each quantifer non-greedy. 85 * 86 * This is done by appending ? to it. It doesn't change the meaning of 87 * the quantifier, but makes it non-greedy, which affects the results - 88 */ 89 status = inSection(8); 90 string = '12 3 45'; 91 pattern = /(\d|\d\s){2,}?/; 92 actualmatch = string.match(pattern); 93 expectedmatch = Array('12', '2'); 94 addThis(); 95 96 status = inSection(9); 97 string = '12 3 45'; 98 pattern = /(\d|\d\s){4,}?/; 99 actualmatch = string.match(pattern); 100 expectedmatch = Array('12 3 4', '4'); 101 addThis(); 102 103 status = inSection(10); 104 string = '12 3 45'; 105 pattern = /(\d|\d\s)+?/; 106 actualmatch = string.match(pattern); 107 expectedmatch = Array('1', '1'); 108 addThis(); 109 110 status = inSection(11); 111 string = '12 3 45'; 112 pattern = /(\d\s?){4,}?/; 113 actualmatch = string.match(pattern); 114 expectedmatch = Array('12 3 4', '4'); 115 addThis(); 116 117 status = inSection(12); 118 string = '12 3 45'; 119 pattern = /(\d\s|\d){2,}?/; 120 actualmatch = string.match(pattern); 121 expectedmatch = Array('12 ', '2 '); 122 addThis(); 123 124 status = inSection(13); 125 string = '12 3 45'; 126 pattern = /(\d\s|\d){4,}?/; 127 actualmatch = string.match(pattern); 128 expectedmatch = Array('12 3 4', '4'); 129 addThis(); 130 131 status = inSection(14); 132 string = '12 3 45'; 133 pattern = /(\d\s|\d)+?/; 134 actualmatch = string.match(pattern); 135 expectedmatch = Array('1', '1'); 136 addThis(); 137 138 139 140 //----------------------------------------------------------------------------- 141 test(); 142 //----------------------------------------------------------------------------- 143 144 145 146 function addThis() 147 { 148 statusmessages[i] = status; 149 patterns[i] = pattern; 150 strings[i] = string; 151 actualmatches[i] = actualmatch; 152 expectedmatches[i] = expectedmatch; 153 i++; 154 } 155 156 157 function test() 158 { 159 printBugNumber(BUGNUMBER); 160 printStatus (summary); 161 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 162 }