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: digit.js michael@0: Description: 'Tests regular expressions containing \d' 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: \\d'; michael@0: michael@0: writeHeaderToLog('Executing script: digit.js'); michael@0: writeHeaderToLog( SECTION + " "+ TITLE); michael@0: michael@0: var non_digits = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\f\n\r\t\v~`!@#$%^&*()-+={[}]|\\:;'<,>./? " + '"'; michael@0: michael@0: var digits = "1234567890"; michael@0: michael@0: // be sure all digits are matched by \d michael@0: new TestCase ( SECTION, michael@0: "'" + digits + "'.match(new RegExp('\\d+'))", michael@0: String([digits]), String(digits.match(new RegExp('\\d+')))); michael@0: michael@0: // be sure all non-digits are matched by \D michael@0: new TestCase ( SECTION, michael@0: "'" + non_digits + "'.match(new RegExp('\\D+'))", michael@0: String([non_digits]), String(non_digits.match(new RegExp('\\D+')))); michael@0: michael@0: // be sure all non-digits are not matched by \d michael@0: new TestCase ( SECTION, michael@0: "'" + non_digits + "'.match(new RegExp('\\d'))", michael@0: null, non_digits.match(new RegExp('\\d'))); michael@0: michael@0: // be sure all digits are not matched by \D michael@0: new TestCase ( SECTION, michael@0: "'" + digits + "'.match(new RegExp('\\D'))", michael@0: null, digits.match(new RegExp('\\D'))); michael@0: michael@0: var s = non_digits + digits; michael@0: michael@0: // be sure all digits are matched by \d michael@0: new TestCase ( SECTION, michael@0: "'" + s + "'.match(new RegExp('\\d+'))", michael@0: String([digits]), String(s.match(new RegExp('\\d+')))); michael@0: michael@0: var s = digits + non_digits; michael@0: michael@0: // be sure all non-digits are matched by \D michael@0: new TestCase ( SECTION, michael@0: "'" + s + "'.match(new RegExp('\\D+'))", michael@0: String([non_digits]), String(s.match(new RegExp('\\D+')))); michael@0: michael@0: var i; michael@0: michael@0: // be sure all digits match individually michael@0: for (i = 0; i < digits.length; ++i) michael@0: { michael@0: s = 'ab' + digits[i] + 'cd'; michael@0: new TestCase ( SECTION, michael@0: "'" + s + "'.match(new RegExp('\\d'))", michael@0: String([digits[i]]), String(s.match(new RegExp('\\d')))); michael@0: new TestCase ( SECTION, michael@0: "'" + s + "'.match(/\\d/)", michael@0: String([digits[i]]), String(s.match(/\d/))); michael@0: } michael@0: // be sure all non_digits match individually michael@0: for (i = 0; i < non_digits.length; ++i) michael@0: { michael@0: s = '12' + non_digits[i] + '34'; michael@0: new TestCase ( SECTION, michael@0: "'" + s + "'.match(new RegExp('\\D'))", michael@0: String([non_digits[i]]), String(s.match(new RegExp('\\D')))); michael@0: new TestCase ( SECTION, michael@0: "'" + s + "'.match(/\\D/)", michael@0: String([non_digits[i]]), String(s.match(/\D/))); michael@0: } michael@0: michael@0: test();