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: * File Name: RegExp/octal-003.js michael@0: * ECMA Section: 15.7.1 michael@0: * Description: Based on ECMA 2 Draft 7 February 1999 michael@0: * Simple test cases for matching OctalEscapeSequences. michael@0: * Author: christine@netscape.com michael@0: * Date: 19 February 1999 michael@0: * michael@0: * Revised: 02 August 2002 michael@0: * Author: pschwartau@netscape.com michael@0: * michael@0: * WHY: the original test expected the regexp /.\011/ michael@0: * to match 'a' + String.fromCharCode(0) + '11' michael@0: * michael@0: * This is incorrect: the string is a 4-character string consisting of michael@0: * the characters <'a'>, , <'1'>, <'1'>. By contrast, the \011 in the michael@0: * regexp should be parsed as a single token: it is the octal escape sequence michael@0: * for the horizontal tab character '\t' === '\u0009' === '\x09' === '\011'. michael@0: * michael@0: * So the regexp consists of 2 characters: , <'\t'>. michael@0: * There is no match between the regexp and the string. michael@0: * michael@0: * See the testcase ecma_3/RegExp/octal-002.js for an elaboration. michael@0: * michael@0: */ michael@0: var SECTION = "RegExp/octal-003.js"; michael@0: var VERSION = "ECMA_2"; michael@0: var TITLE = "RegExp patterns that contain OctalEscapeSequences"; michael@0: var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346132"; michael@0: michael@0: startTest(); michael@0: michael@0: AddRegExpCases( /.\011/, "/\\011/", "a" + String.fromCharCode(0) + "11", "a\\011", 0, null ); michael@0: michael@0: test(); michael@0: michael@0: function AddRegExpCases( michael@0: regexp, str_regexp, pattern, str_pattern, index, matches_array ) { michael@0: michael@0: // prevent a runtime error michael@0: michael@0: if ( regexp.exec(pattern) == null || matches_array == null ) { michael@0: AddTestCase( michael@0: regexp + ".exec(" + str_pattern +")", michael@0: matches_array, michael@0: regexp.exec(pattern) ); michael@0: michael@0: return; michael@0: } michael@0: AddTestCase( michael@0: str_regexp + ".exec(" + str_pattern +").length", michael@0: matches_array.length, michael@0: regexp.exec(pattern).length ); michael@0: michael@0: AddTestCase( michael@0: str_regexp + ".exec(" + str_pattern +").index", michael@0: index, michael@0: regexp.exec(pattern).index ); michael@0: michael@0: AddTestCase( michael@0: str_regexp + ".exec(" + str_pattern +").input", michael@0: escape(pattern), michael@0: escape(regexp.exec(pattern).input) ); michael@0: michael@0: AddTestCase( michael@0: str_regexp + ".exec(" + str_pattern +").toString()", michael@0: matches_array.toString(), michael@0: escape(regexp.exec(pattern).toString()) ); michael@0: michael@0: var limit = matches_array.length > regexp.exec(pattern).length michael@0: ? matches_array.length michael@0: : regexp.exec(pattern).length; michael@0: michael@0: for ( var matches = 0; matches < limit; matches++ ) { michael@0: AddTestCase( michael@0: str_regexp + ".exec(" + str_pattern +")[" + matches +"]", michael@0: matches_array[matches], michael@0: escape(regexp.exec(pattern)[matches]) ); michael@0: } michael@0: michael@0: }