regress-67773.js (4420B)
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 * Date: 06 February 2001 8 * 9 * SUMMARY: Arose from Bugzilla bug 67773: 10 * "Regular subexpressions followed by + failing to run to completion" 11 * 12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=67773 13 * See http://bugzilla.mozilla.org/show_bug.cgi?id=69989 14 */ 15 //----------------------------------------------------------------------------- 16 var i = 0; 17 var BUGNUMBER = 67773; 18 var summary = 'Testing regular subexpressions followed by ? or +\n'; 19 var cnSingleSpace = ' '; 20 var status = ''; 21 var statusmessages = new Array(); 22 var pattern = ''; 23 var patterns = new Array(); 24 var string = ''; 25 var strings = new Array(); 26 var actualmatch = ''; 27 var actualmatches = new Array(); 28 var expectedmatch = ''; 29 var expectedmatches = new Array(); 30 31 32 pattern = /^(\S+)?( ?)(B+)$/; //single space before second ? character 33 status = inSection(1); 34 string = 'AAABBB AAABBB '; //single space at middle and at end - 35 actualmatch = string.match(pattern); 36 expectedmatch = null; 37 addThis(); 38 39 status = inSection(2); 40 string = 'AAABBB BBB'; //single space in the middle 41 actualmatch = string.match(pattern); 42 expectedmatch = Array(string, 'AAABBB', cnSingleSpace, 'BBB'); 43 addThis(); 44 45 status = inSection(3); 46 string = 'AAABBB AAABBB'; //single space in the middle 47 actualmatch = string.match(pattern); 48 expectedmatch = null; 49 addThis(); 50 51 52 pattern = /^(A+B)+$/; 53 status = inSection(4); 54 string = 'AABAAB'; 55 actualmatch = string.match(pattern); 56 expectedmatch = Array(string, 'AAB'); 57 addThis(); 58 59 status = inSection(5); 60 string = 'ABAABAAAAAAB'; 61 actualmatch = string.match(pattern); 62 expectedmatch = Array(string, 'AAAAAAB'); 63 addThis(); 64 65 status = inSection(6); 66 string = 'ABAABAABAB'; 67 actualmatch = string.match(pattern); 68 expectedmatch = Array(string, 'AB'); 69 addThis(); 70 71 status = inSection(7); 72 string = 'ABAABAABABB'; 73 actualmatch = string.match(pattern); 74 expectedmatch = null; // because string doesn't match at end 75 addThis(); 76 77 78 pattern = /^(A+1)+$/; 79 status = inSection(8); 80 string = 'AA1AA1'; 81 actualmatch = string.match(pattern); 82 expectedmatch = Array(string, 'AA1'); 83 addThis(); 84 85 86 pattern = /^(\w+\-)+$/; 87 status = inSection(9); 88 string = ''; 89 actualmatch = string.match(pattern); 90 expectedmatch = null; 91 addThis(); 92 93 status = inSection(10); 94 string = 'bla-'; 95 actualmatch = string.match(pattern); 96 expectedmatch = Array(string, string); 97 addThis(); 98 99 status = inSection(11); 100 string = 'bla-bla'; // hyphen missing at end - 101 actualmatch = string.match(pattern); 102 expectedmatch = null; //because string doesn't match at end 103 addThis(); 104 105 status = inSection(12); 106 string = 'bla-bla-'; 107 actualmatch = string.match(pattern); 108 expectedmatch = Array(string, 'bla-'); 109 addThis(); 110 111 112 pattern = /^(\S+)+(A+)$/; 113 status = inSection(13); 114 string = 'asdldflkjAAA'; 115 actualmatch = string.match(pattern); 116 expectedmatch = Array(string, 'asdldflkjAA', 'A'); 117 addThis(); 118 119 status = inSection(14); 120 string = 'asdldflkj AAA'; // space in middle 121 actualmatch = string.match(pattern); 122 expectedmatch = null; //because of the space 123 addThis(); 124 125 126 pattern = /^(\S+)+(\d+)$/; 127 status = inSection(15); 128 string = 'asdldflkj122211'; 129 actualmatch = string.match(pattern); 130 expectedmatch = Array(string, 'asdldflkj12221', '1'); 131 addThis(); 132 133 status = inSection(16); 134 string = 'asdldflkj1111111aaa1'; 135 actualmatch = string.match(pattern); 136 expectedmatch = Array(string, 'asdldflkj1111111aaa', '1'); 137 addThis(); 138 139 140 /* 141 * This one comes from Stephen Ostermiller. 142 * See http://bugzilla.mozilla.org/show_bug.cgi?id=69989 143 */ 144 pattern = /^[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)+$/; 145 status = inSection(17); 146 string = 'some.host.tld'; 147 actualmatch = string.match(pattern); 148 expectedmatch = Array(string, '.tld', '.'); 149 addThis(); 150 151 152 153 //------------------------------------------------------------------------------------------------- 154 test(); 155 //------------------------------------------------------------------------------------------------- 156 157 158 159 function addThis() 160 { 161 statusmessages[i] = status; 162 patterns[i] = pattern; 163 strings[i] = string; 164 actualmatches[i] = actualmatch; 165 expectedmatches[i] = expectedmatch; 166 i++; 167 } 168 169 170 function test() 171 { 172 printBugNumber(BUGNUMBER); 173 printStatus (summary); 174 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 175 }