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: asterisk.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: aterisk.js'); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: // 'abcddddefg'.match(new RegExp('d*')) michael@0: new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('d*'))", michael@0: String([""]), String('abcddddefg'.match(new RegExp('d*')))); michael@0: michael@0: // 'abcddddefg'.match(new RegExp('cd*')) michael@0: new TestCase ( SECTION, "'abcddddefg'.match(new RegExp('cd*'))", michael@0: String(["cdddd"]), String('abcddddefg'.match(new RegExp('cd*')))); michael@0: michael@0: // 'abcdefg'.match(new RegExp('cx*d')) michael@0: new TestCase ( SECTION, "'abcdefg'.match(new RegExp('cx*d'))", michael@0: String(["cd"]), String('abcdefg'.match(new RegExp('cx*d')))); michael@0: michael@0: // 'xxxxxxx'.match(new RegExp('(x*)(x+)')) michael@0: new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('(x*)(x+)'))", michael@0: String(["xxxxxxx","xxxxxx","x"]), String('xxxxxxx'.match(new RegExp('(x*)(x+)')))); michael@0: michael@0: // '1234567890'.match(new RegExp('(\\d*)(\\d+)')) michael@0: new TestCase ( SECTION, "'1234567890'.match(new RegExp('(\\d*)(\\d+)'))", michael@0: String(["1234567890","123456789","0"]), michael@0: String('1234567890'.match(new RegExp('(\\d*)(\\d+)')))); michael@0: michael@0: // '1234567890'.match(new RegExp('(\\d*)\\d(\\d+)')) michael@0: new TestCase ( SECTION, "'1234567890'.match(new RegExp('(\\d*)\\d(\\d+)'))", michael@0: String(["1234567890","12345678","0"]), michael@0: String('1234567890'.match(new RegExp('(\\d*)\\d(\\d+)')))); michael@0: michael@0: // 'xxxxxxx'.match(new RegExp('(x+)(x*)')) michael@0: new TestCase ( SECTION, "'xxxxxxx'.match(new RegExp('(x+)(x*)'))", michael@0: String(["xxxxxxx","xxxxxxx",""]), String('xxxxxxx'.match(new RegExp('(x+)(x*)')))); michael@0: michael@0: // 'xxxxxxyyyyyy'.match(new RegExp('x*y+$')) michael@0: new TestCase ( SECTION, "'xxxxxxyyyyyy'.match(new RegExp('x*y+$'))", michael@0: String(["xxxxxxyyyyyy"]), String('xxxxxxyyyyyy'.match(new RegExp('x*y+$')))); michael@0: michael@0: // 'abcdef'.match(/[\d]*[\s]*bc./) michael@0: new TestCase ( SECTION, "'abcdef'.match(/[\\d]*[\\s]*bc./)", michael@0: String(["bcd"]), String('abcdef'.match(/[\d]*[\s]*bc./))); michael@0: michael@0: // 'abcdef'.match(/bc..[\d]*[\s]*/) michael@0: new TestCase ( SECTION, "'abcdef'.match(/bc..[\\d]*[\\s]*/)", michael@0: String(["bcde"]), String('abcdef'.match(/bc..[\d]*[\s]*/))); michael@0: michael@0: // 'a1b2c3'.match(/.*/) michael@0: new TestCase ( SECTION, "'a1b2c3'.match(/.*/)", michael@0: String(["a1b2c3"]), String('a1b2c3'.match(/.*/))); michael@0: michael@0: // 'a0.b2.c3'.match(/[xyz]*1/) michael@0: new TestCase ( SECTION, "'a0.b2.c3'.match(/[xyz]*1/)", michael@0: null, 'a0.b2.c3'.match(/[xyz]*1/)); michael@0: michael@0: test();