regress-187133.js (2580B)
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: 06 January 2003 9 * SUMMARY: RegExp conformance test 10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=187133 11 * 12 * The tests here employ the regular expression construct: 13 * 14 * (?!pattern) 15 * 16 * This is a "zero-width lookahead negative assertion". 17 * From the Perl documentation: 18 * 19 * For example, /foo(?!bar)/ matches any occurrence 20 * of 'foo' that isn't followed by 'bar'. 21 * 22 * It is "zero-width" means that it does not consume any characters and that 23 * the parens are non-capturing. A non-null match array in the example above 24 * will have only have length 1, not 2. 25 * 26 */ 27 //----------------------------------------------------------------------------- 28 var i = 0; 29 var BUGNUMBER = 187133; 30 var summary = 'RegExp conformance test'; 31 var status = ''; 32 var statusmessages = new Array(); 33 var pattern = ''; 34 var patterns = new Array(); 35 var string = ''; 36 var strings = new Array(); 37 var actualmatch = ''; 38 var actualmatches = new Array(); 39 var expectedmatch = ''; 40 var expectedmatches = new Array(); 41 42 43 pattern = /(\.(?!com|org)|\/)/; 44 status = inSection(1); 45 string = 'ah.info'; 46 actualmatch = string.match(pattern); 47 expectedmatch = ['.', '.']; 48 addThis(); 49 50 status = inSection(2); 51 string = 'ah/info'; 52 actualmatch = string.match(pattern); 53 expectedmatch = ['/', '/']; 54 addThis(); 55 56 status = inSection(3); 57 string = 'ah.com'; 58 actualmatch = string.match(pattern); 59 expectedmatch = null; 60 addThis(); 61 62 63 pattern = /(?!a|b)|c/; 64 status = inSection(4); 65 string = ''; 66 actualmatch = string.match(pattern); 67 expectedmatch = ['']; 68 addThis(); 69 70 status = inSection(5); 71 string = 'bc'; 72 actualmatch = string.match(pattern); 73 expectedmatch = ['']; 74 addThis(); 75 76 status = inSection(6); 77 string = 'd'; 78 actualmatch = string.match(pattern); 79 expectedmatch = ['']; 80 addThis(); 81 82 83 84 85 //------------------------------------------------------------------------------------------------- 86 test(); 87 //------------------------------------------------------------------------------------------------- 88 89 90 function addThis() 91 { 92 statusmessages[i] = status; 93 patterns[i] = pattern; 94 strings[i] = string; 95 actualmatches[i] = actualmatch; 96 expectedmatches[i] = expectedmatch; 97 i++; 98 } 99 100 101 function test() 102 { 103 printBugNumber(BUGNUMBER); 104 printStatus (summary); 105 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); 106 }