1/* The contents of this file are subject to the Netscape Public 2 * License Version 1.1 (the "License"); you may not use this file 3 * except in compliance with the License. You may obtain a copy of 4 * the License at http://www.mozilla.org/NPL/ 5 * 6 * Software distributed under the License is distributed on an "AS 7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or 8 * implied. See the License for the specific language governing 9 * rights and limitations under the License. 10 * 11 * The Original Code is Mozilla Communicator client code, released March 12 * 31, 1998. 13 * 14 * The Initial Developer of the Original Code is Netscape Communications 15 * Corporation. Portions created by Netscape are 16 * Copyright (C) 1998 Netscape Communications Corporation. All 17 * Rights Reserved. 18 * 19 * Contributor(s): 20 * 21 */ 22/** 23 Filename: parentheses.js 24 Description: 'Tests regular expressions containing ()' 25 26 Author: Nick Lerissa 27 Date: March 10, 1998 28*/ 29 30 var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; 31 var VERSION = 'no version'; 32 startTest(); 33 var TITLE = 'RegExp: ()'; 34 35 writeHeaderToLog('Executing script: parentheses.js'); 36 writeHeaderToLog( SECTION + " "+ TITLE); 37 38 var count = 0; 39 var testcases = new Array(); 40 41 // 'abc'.match(new RegExp('(abc)')) 42 testcases[count++] = new TestCase ( SECTION, "'abc'.match(new RegExp('(abc)'))", 43 String(["abc","abc"]), String('abc'.match(new RegExp('(abc)')))); 44 45 // 'abcdefg'.match(new RegExp('a(bc)d(ef)g')) 46 testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(bc)d(ef)g'))", 47 String(["abcdefg","bc","ef"]), String('abcdefg'.match(new RegExp('a(bc)d(ef)g')))); 48 49 // 'abcdefg'.match(new RegExp('(.{3})(.{4})')) 50 testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(.{3})(.{4})'))", 51 String(["abcdefg","abc","defg"]), String('abcdefg'.match(new RegExp('(.{3})(.{4})')))); 52 53 // 'aabcdaabcd'.match(new RegExp('(aa)bcd\1')) 54 testcases[count++] = new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))", 55 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa)bcd\\1')))); 56 57 // 'aabcdaabcd'.match(new RegExp('(aa).+\1')) 58 testcases[count++] = new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa).+\\1'))", 59 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa).+\\1')))); 60 61 // 'aabcdaabcd'.match(new RegExp('(.{2}).+\1')) 62 testcases[count++] = new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))", 63 String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(.{2}).+\\1')))); 64 65 // '123456123456'.match(new RegExp('(\d{3})(\d{3})\1\2')) 66 testcases[count++] = new TestCase ( SECTION, "'123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))", 67 String(["123456123456","123","456"]), String('123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2')))); 68 69 // 'abcdefg'.match(new RegExp('a(..(..)..)')) 70 testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(..(..)..)'))", 71 String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(new RegExp('a(..(..)..)')))); 72 73 // 'abcdefg'.match(/a(..(..)..)/) 74 testcases[count++] = new TestCase ( SECTION, "'abcdefg'.match(/a(..(..)..)/)", 75 String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(/a(..(..)..)/))); 76 77 // 'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')) 78 testcases[count++] = new TestCase ( SECTION, "'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))", 79 String(["abcdef","abc","bc","c","def","ef","f"]), String('xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')))); 80 81 // 'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\2\5')) 82 testcases[count++] = new TestCase ( SECTION, "'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))", 83 String(["abcdefbcef","abc","bc","c","def","ef","f"]), String('xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5')))); 84 85 // 'abcd'.match(new RegExp('a(.?)b\1c\1d\1')) 86 testcases[count++] = new TestCase ( SECTION, "'abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))", 87 String(["abcd",""]), String('abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1')))); 88 89 // 'abcd'.match(/a(.?)b\1c\1d\1/) 90 testcases[count++] = new TestCase ( SECTION, "'abcd'.match(/a(.?)b\\1c\\1d\\1/)", 91 String(["abcd",""]), String('abcd'.match(/a(.?)b\1c\1d\1/))); 92 93 function test() 94 { 95 for ( tc=0; tc < testcases.length; tc++ ) { 96 testcases[tc].passed = writeTestCaseResult( 97 testcases[tc].expect, 98 testcases[tc].actual, 99 testcases[tc].description +" = "+ 100 testcases[tc].actual ); 101 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 102 } 103 stopTest(); 104 return ( testcases ); 105 } 106 107 test(); 108