js/src/tests/ecma_2/RegExp/octal-003.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/tests/ecma_2/RegExp/octal-003.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,87 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +
    1.10 +/**
    1.11 + *  File Name:          RegExp/octal-003.js
    1.12 + *  ECMA Section:       15.7.1
    1.13 + *  Description:        Based on ECMA 2 Draft 7 February 1999
    1.14 + *  Simple test cases for matching OctalEscapeSequences.
    1.15 + *  Author:             christine@netscape.com
    1.16 + *  Date:               19 February 1999
    1.17 + *
    1.18 + *  Revised:            02 August 2002
    1.19 + *  Author:             pschwartau@netscape.com
    1.20 + *
    1.21 + *  WHY:  the original test expected the regexp /.\011/
    1.22 + *        to match 'a' + String.fromCharCode(0) + '11'
    1.23 + *
    1.24 + *  This is incorrect: the string is a 4-character string consisting of
    1.25 + *  the characters <'a'>, <nul>, <'1'>, <'1'>. By contrast, the \011 in the
    1.26 + *  regexp should be parsed as a single token: it is the octal escape sequence
    1.27 + *  for the horizontal tab character '\t' === '\u0009' === '\x09' === '\011'.
    1.28 + *
    1.29 + *  So the regexp consists of 2 characters: <any-character>, <'\t'>.
    1.30 + *  There is no match between the regexp and the string.
    1.31 + *
    1.32 + *  See the testcase ecma_3/RegExp/octal-002.js for an elaboration.
    1.33 + *
    1.34 + */
    1.35 +var SECTION = "RegExp/octal-003.js";
    1.36 +var VERSION = "ECMA_2";
    1.37 +var TITLE   = "RegExp patterns that contain OctalEscapeSequences";
    1.38 +var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346132";
    1.39 +
    1.40 +startTest();
    1.41 +
    1.42 +AddRegExpCases( /.\011/, "/\\011/", "a" + String.fromCharCode(0) + "11", "a\\011", 0, null );
    1.43 +
    1.44 +test();
    1.45 +
    1.46 +function AddRegExpCases(
    1.47 +  regexp, str_regexp, pattern, str_pattern, index, matches_array ) {
    1.48 +
    1.49 +  // prevent a runtime error
    1.50 +
    1.51 +  if ( regexp.exec(pattern) == null || matches_array == null ) {
    1.52 +    AddTestCase(
    1.53 +      regexp + ".exec(" + str_pattern +")",
    1.54 +      matches_array,
    1.55 +      regexp.exec(pattern) );
    1.56 +
    1.57 +    return;
    1.58 +  }
    1.59 +  AddTestCase(
    1.60 +    str_regexp + ".exec(" + str_pattern +").length",
    1.61 +    matches_array.length,
    1.62 +    regexp.exec(pattern).length );
    1.63 +
    1.64 +  AddTestCase(
    1.65 +    str_regexp + ".exec(" + str_pattern +").index",
    1.66 +    index,
    1.67 +    regexp.exec(pattern).index );
    1.68 +
    1.69 +  AddTestCase(
    1.70 +    str_regexp + ".exec(" + str_pattern +").input",
    1.71 +    escape(pattern),
    1.72 +    escape(regexp.exec(pattern).input) );
    1.73 +
    1.74 +  AddTestCase(
    1.75 +    str_regexp + ".exec(" + str_pattern +").toString()",
    1.76 +    matches_array.toString(),
    1.77 +    escape(regexp.exec(pattern).toString()) );
    1.78 +
    1.79 +  var limit = matches_array.length > regexp.exec(pattern).length
    1.80 +    ? matches_array.length
    1.81 +    : regexp.exec(pattern).length;
    1.82 +
    1.83 +  for ( var matches = 0; matches < limit; matches++ ) {
    1.84 +    AddTestCase(
    1.85 +      str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
    1.86 +      matches_array[matches],
    1.87 +      escape(regexp.exec(pattern)[matches]) );
    1.88 +  }
    1.89 +
    1.90 +}

mercurial