1 /* 2 * The contents of this file are subject to the Netscape Public 3 * License Version 1.1 (the "License"); you may not use this file 4 * except in compliance with the License. You may obtain a copy of 5 * the License at http://www.mozilla.org/NPL/ 6 * 7 * Software distributed under the License is distributed on an "AS IS" 8 * basis, WITHOUT WARRANTY OF ANY KIND, either expressed 9 * or implied. See the License for the specific language governing 10 * rights and limitations under the License. 11 * 12 * The Original Code is mozilla.org code. 13 * 14 * The Initial Developer of the Original Code is Netscape 15 * Communications Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. 17 * All Rights Reserved. 18 * 19 * Contributor(s): pschwartau (at) netscape.com 20 * Date: 17 September 2001 21 * 22 * SUMMARY: Regression test for Bugzilla bug 100199 23 * See http://bugzilla.mozilla.org/show_bug.cgi?id=100199 24 * 25 * The empty character class [] is a valid RegExp construct: the condition 26 * that a given character belong to a set containing no characters. As such, 27 * it can never be met and is always FALSE. Similarly, [^] is a condition 28 * that matches any given character and is always TRUE. 29 * 30 * Neither one of these conditions should cause syntax errors in a RegExp. 31 */ 32 //----------------------------------------------------------------------------- 33 var i = 0; 34 var bug = 100199; 35 var summary = '[], [^] are valid RegExp conditions. Should not cause errors -'; 36 var status = ''; 37 var statusmessages = new Array(); 38 var pattern = ''; 39 var patterns = new Array(); 40 var string = ''; 41 var strings = new Array(); 42 var actualmatch = ''; 43 var actualmatches = new Array(); 44 var expectedmatch = ''; 45 var expectedmatches = new Array(); 46 47 48 pattern = /[]/; 49 string = 'abc'; 50 status = inSection(1); 51 actualmatch = string.match(pattern); 52 expectedmatch = null; 53 addThis(); 54 55 string = ''; 56 status = inSection(2); 57 actualmatch = string.match(pattern); 58 expectedmatch = null; 59 addThis(); 60 61 string = '['; 62 status = inSection(3); 63 actualmatch = string.match(pattern); 64 expectedmatch = null; 65 addThis(); 66 67 string = '/'; 68 status = inSection(4); 69 actualmatch = string.match(pattern); 70 expectedmatch = null; 71 addThis(); 72 73 string = '['; 74 status = inSection(5); 75 actualmatch = string.match(pattern); 76 expectedmatch = null; 77 addThis(); 78 79 string = ']'; 80 status = inSection(6); 81 actualmatch = string.match(pattern); 82 expectedmatch = null; 83 addThis(); 84 85 string = '[]'; 86 status = inSection(7); 87 actualmatch = string.match(pattern); 88 expectedmatch = null; 89 addThis(); 90 91 string = '[ ]'; 92 status = inSection(8); 93 actualmatch = string.match(pattern); 94 expectedmatch = null; 95 addThis(); 96 97 string = ']['; 98 status = inSection(9); 99 actualmatch = string.match(pattern); 100 expectedmatch = null; 101 addThis(); 102 103 104 pattern = /a[]/; 105 string = 'abc'; 106 status = inSection(10); 107 actualmatch = string.match(pattern); 108 expectedmatch = null; 109 addThis(); 110 111 string = ''; 112 status = inSection(11); 113 actualmatch = string.match(pattern); 114 expectedmatch = null; 115 addThis(); 116 117 string = 'a['; 118 status = inSection(12); 119 actualmatch = string.match(pattern); 120 expectedmatch = null; 121 addThis(); 122 123 string = 'a[]'; 124 status = inSection(13); 125 actualmatch = string.match(pattern); 126 expectedmatch = null; 127 addThis(); 128 129 string = '['; 130 status = inSection(14); 131 actualmatch = string.match(pattern); 132 expectedmatch = null; 133 addThis(); 134 135 string = ']'; 136 status = inSection(15); 137 actualmatch = string.match(pattern); 138 expectedmatch = null; 139 addThis(); 140 141 string = '[]'; 142 status = inSection(16); 143 actualmatch = string.match(pattern); 144 expectedmatch = null; 145 addThis(); 146 147 string = '[ ]'; 148 status = inSection(17); 149 actualmatch = string.match(pattern); 150 expectedmatch = null; 151 addThis(); 152 153 string = ']['; 154 status = inSection(18); 155 actualmatch = string.match(pattern); 156 expectedmatch = null; 157 addThis(); 158 159 160 pattern = /[^]/; 161 string = 'abc'; 162 status = inSection(19); 163 actualmatch = string.match(pattern); 164 expectedmatch = Array('a'); 165 addThis(); 166 167 string = ''; 168 status = inSection(20); 169 actualmatch = string.match(pattern); 170 expectedmatch = null; //there are no characters to test against the condition 171 addThis(); 172 173 string = '\/'; 174 status = inSection(21); 175 actualmatch = string.match(pattern); 176 expectedmatch = Array('/'); 177 addThis(); 178 179 string = '\['; 180 status = inSection(22); 181 actualmatch = string.match(pattern); 182 expectedmatch = Array('['); 183 addThis(); 184 185 string = '['; 186 status = inSection(23); 187 actualmatch = string.match(pattern); 188 expectedmatch = Array('['); 189 addThis(); 190 191 string = ']'; 192 status = inSection(24); 193 actualmatch = string.match(pattern); 194 expectedmatch = Array(']'); 195 addThis(); 196 197 string = '[]'; 198 status = inSection(25); 199 actualmatch = string.match(pattern); 200 expectedmatch = Array('['); 201 addThis(); 202 203 string = '[ ]'; 204 status = inSection(26); 205 actualmatch = string.match(pattern); 206 expectedmatch = Array('['); 207 addThis(); 208 209 string = ']['; 210 status = inSection(27); 211 actualmatch = string.match(pattern); 212 expectedmatch = Array(']'); 213 addThis(); 214 215 216 pattern = /a[^]/; 217 string = 'abc'; 218 status = inSection(28); 219 actualmatch = string.match(pattern); 220 expectedmatch = Array('ab'); 221 addThis(); 222 223 string = ''; 224 status = inSection(29); 225 actualmatch = string.match(pattern); 226 expectedmatch = null; //there are no characters to test against the condition 227 addThis(); 228 229 string = 'a['; 230 status = inSection(30); 231 actualmatch = string.match(pattern); 232 expectedmatch = Array('a['); 233 addThis(); 234 235 string = 'a]'; 236 status = inSection(31); 237 actualmatch = string.match(pattern); 238 expectedmatch = Array('a]'); 239 addThis(); 240 241 string = 'a[]'; 242 status = inSection(32); 243 actualmatch = string.match(pattern); 244 expectedmatch = Array('a['); 245 addThis(); 246 247 string = 'a[ ]'; 248 status = inSection(33); 249 actualmatch = string.match(pattern); 250 expectedmatch = Array('a['); 251 addThis(); 252 253 string = 'a]['; 254 status = inSection(34); 255 actualmatch = string.match(pattern); 256 expectedmatch = Array('a]'); 257 addThis(); 258 259 260 261 262 //----------------------------------------------------------------------------- 263 test(); 264 //----------------------------------------------------------------------------- 265 266 267 268 function addThis() 269 { 270 statusmessages[i] = status; 271 patterns[i] = pattern; 272 strings[i] = string; 273 actualmatches[i] = actualmatch; 274 expectedmatches[i] = expectedmatch; 275 i++; 276 } 277 278 279 function test() 280 { 281 enterFunc ('test'); 282 printBugNumber (bug); 283 printStatus (summary); 284 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 285 exitFunc ('test'); 286 } 287