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