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: character_class.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: character_class.js'); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: michael@0: // 'abcde'.match(new RegExp('ab[ercst]de')) michael@0: new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[ercst]de'))", michael@0: String(["abcde"]), String('abcde'.match(new RegExp('ab[ercst]de')))); michael@0: michael@0: // 'abcde'.match(new RegExp('ab[erst]de')) michael@0: new TestCase ( SECTION, "'abcde'.match(new RegExp('ab[erst]de'))", michael@0: null, 'abcde'.match(new RegExp('ab[erst]de'))); michael@0: michael@0: // 'abcdefghijkl'.match(new RegExp('[d-h]+')) michael@0: new TestCase ( SECTION, "'abcdefghijkl'.match(new RegExp('[d-h]+'))", michael@0: String(["defgh"]), String('abcdefghijkl'.match(new RegExp('[d-h]+')))); michael@0: michael@0: // 'abc6defghijkl'.match(new RegExp('[1234567].{2}')) michael@0: new TestCase ( SECTION, "'abc6defghijkl'.match(new RegExp('[1234567].{2}'))", michael@0: String(["6de"]), String('abc6defghijkl'.match(new RegExp('[1234567].{2}')))); michael@0: michael@0: // '\n\n\abc324234\n'.match(new RegExp('[a-c\d]+')) michael@0: new TestCase ( SECTION, "'\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+'))", michael@0: String(["abc324234"]), String('\n\n\abc324234\n'.match(new RegExp('[a-c\\d]+')))); michael@0: michael@0: // 'abc'.match(new RegExp('ab[.]?c')) michael@0: new TestCase ( SECTION, "'abc'.match(new RegExp('ab[.]?c'))", michael@0: String(["abc"]), String('abc'.match(new RegExp('ab[.]?c')))); michael@0: michael@0: // 'abc'.match(new RegExp('a[b]c')) michael@0: new TestCase ( SECTION, "'abc'.match(new RegExp('a[b]c'))", michael@0: String(["abc"]), String('abc'.match(new RegExp('a[b]c')))); michael@0: michael@0: // 'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]')) michael@0: new TestCase ( SECTION, "'a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]'))", michael@0: String(["def"]), String('a1b b2c c3d def f4g'.match(new RegExp('[a-z][^1-9][a-z]')))); michael@0: michael@0: // '123*&$abc'.match(new RegExp('[*&$]{3}')) michael@0: new TestCase ( SECTION, "'123*&$abc'.match(new RegExp('[*&$]{3}'))", michael@0: String(["*&$"]), String('123*&$abc'.match(new RegExp('[*&$]{3}')))); michael@0: michael@0: // 'abc'.match(new RegExp('a[^1-9]c')) michael@0: new TestCase ( SECTION, "'abc'.match(new RegExp('a[^1-9]c'))", michael@0: String(["abc"]), String('abc'.match(new RegExp('a[^1-9]c')))); michael@0: michael@0: // 'abc'.match(new RegExp('a[^b]c')) michael@0: new TestCase ( SECTION, "'abc'.match(new RegExp('a[^b]c'))", michael@0: null, 'abc'.match(new RegExp('a[^b]c'))); michael@0: michael@0: // 'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}')) michael@0: new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}'))", michael@0: String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(new RegExp('[^a-z]{4}')))); michael@0: michael@0: // 'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/) michael@0: new TestCase ( SECTION, "'abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/)", michael@0: String(["%&*@"]), String('abc#$%def%&*@ghi)(*&'.match(/[^a-z]{4}/))); michael@0: michael@0: test();