michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: /** michael@0: Filename: parentheses.js michael@0: Description: 'Tests regular expressions containing ()' michael@0: michael@0: Author: Nick Lerissa michael@0: Date: March 10, 1998 michael@0: */ michael@0: michael@0: var SECTION = 'As described in Netscape doc "Whats new in JavaScript 1.2"'; michael@0: var VERSION = 'no version'; michael@0: startTest(); michael@0: var TITLE = 'RegExp: ()'; michael@0: michael@0: writeHeaderToLog('Executing script: parentheses.js'); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: // 'abc'.match(new RegExp('(abc)')) michael@0: new TestCase ( SECTION, "'abc'.match(new RegExp('(abc)'))", michael@0: String(["abc","abc"]), String('abc'.match(new RegExp('(abc)')))); michael@0: michael@0: // 'abcdefg'.match(new RegExp('a(bc)d(ef)g')) michael@0: new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(bc)d(ef)g'))", michael@0: String(["abcdefg","bc","ef"]), String('abcdefg'.match(new RegExp('a(bc)d(ef)g')))); michael@0: michael@0: // 'abcdefg'.match(new RegExp('(.{3})(.{4})')) michael@0: new TestCase ( SECTION, "'abcdefg'.match(new RegExp('(.{3})(.{4})'))", michael@0: String(["abcdefg","abc","defg"]), String('abcdefg'.match(new RegExp('(.{3})(.{4})')))); michael@0: michael@0: // 'aabcdaabcd'.match(new RegExp('(aa)bcd\1')) michael@0: new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa)bcd\\1'))", michael@0: String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa)bcd\\1')))); michael@0: michael@0: // 'aabcdaabcd'.match(new RegExp('(aa).+\1')) michael@0: new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(aa).+\\1'))", michael@0: String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(aa).+\\1')))); michael@0: michael@0: // 'aabcdaabcd'.match(new RegExp('(.{2}).+\1')) michael@0: new TestCase ( SECTION, "'aabcdaabcd'.match(new RegExp('(.{2}).+\\1'))", michael@0: String(["aabcdaa","aa"]), String('aabcdaabcd'.match(new RegExp('(.{2}).+\\1')))); michael@0: michael@0: // '123456123456'.match(new RegExp('(\d{3})(\d{3})\1\2')) michael@0: new TestCase ( SECTION, "'123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2'))", michael@0: String(["123456123456","123","456"]), String('123456123456'.match(new RegExp('(\\d{3})(\\d{3})\\1\\2')))); michael@0: michael@0: // 'abcdefg'.match(new RegExp('a(..(..)..)')) michael@0: new TestCase ( SECTION, "'abcdefg'.match(new RegExp('a(..(..)..)'))", michael@0: String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(new RegExp('a(..(..)..)')))); michael@0: michael@0: // 'abcdefg'.match(/a(..(..)..)/) michael@0: new TestCase ( SECTION, "'abcdefg'.match(/a(..(..)..)/)", michael@0: String(["abcdefg","bcdefg","de"]), String('abcdefg'.match(/a(..(..)..)/))); michael@0: michael@0: // 'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')) michael@0: new TestCase ( SECTION, "'xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))'))", michael@0: String(["abcdef","abc","bc","c","def","ef","f"]), String('xabcdefg'.match(new RegExp('(a(b(c)))(d(e(f)))')))); michael@0: michael@0: // 'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\2\5')) michael@0: new TestCase ( SECTION, "'xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5'))", michael@0: String(["abcdefbcef","abc","bc","c","def","ef","f"]), String('xabcdefbcefg'.match(new RegExp('(a(b(c)))(d(e(f)))\\2\\5')))); michael@0: michael@0: // 'abcd'.match(new RegExp('a(.?)b\1c\1d\1')) michael@0: new TestCase ( SECTION, "'abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1'))", michael@0: String(["abcd",""]), String('abcd'.match(new RegExp('a(.?)b\\1c\\1d\\1')))); michael@0: michael@0: // 'abcd'.match(/a(.?)b\1c\1d\1/) michael@0: new TestCase ( SECTION, "'abcd'.match(/a(.?)b\\1c\\1d\\1/)", michael@0: String(["abcd",""]), String('abcd'.match(/a(.?)b\1c\1d\1/))); michael@0: michael@0: test();