Home | History | Annotate | Download | only in RegExp
      1 /**
      2  *  File Name:          RegExp/octal-003.js
      3  *  ECMA Section:       15.7.1
      4  *  Description:        Based on ECMA 2 Draft 7 February 1999
      5  *  Simple test cases for matching OctalEscapeSequences.
      6  *  Author:             christine (at) netscape.com
      7  *  Date:               19 February 1999
      8  *
      9  *  Revised:            02 August 2002
     10  *  Author:             pschwartau (at) netscape.com
     11  *
     12  *  WHY:  the original test expected the regexp /.\011/
     13  *        to match 'a' + String.fromCharCode(0) + '11'
     14  *
     15  *  This is incorrect: the string is a 4-character string consisting of
     16  *  the characters <'a'>, <nul>, <'1'>, <'1'>. By contrast, the \011 in the
     17  *  regexp should be parsed as a single token: it is the octal escape sequence
     18  *  for the horizontal tab character '\t' === '\u0009' === '\x09' === '\011'.
     19  *
     20  *  So the regexp consists of 2 characters: <any-character>, <'\t'>.
     21  *  There is no match between the regexp and the string.
     22  *
     23  *  See the testcase ecma_3/RegExp/octal-002.js for an elaboration.
     24  *
     25  */
     26     var SECTION = "RegExp/octal-003.js";
     27     var VERSION = "ECMA_2";
     28     var TITLE   = "RegExp patterns that contain OctalEscapeSequences";
     29     var BUGNUMBER="http://scopus/bugsplat/show_bug.cgi?id=346132";
     30 
     31     startTest();
     32 
     33     AddRegExpCases( /.\011/, "/\\011/", "a" + String.fromCharCode(0) + "11", "a\\011", 0, null );
     34 
     35     test();
     36 
     37 function AddRegExpCases(
     38     regexp, str_regexp, pattern, str_pattern, index, matches_array ) {
     39 
     40     // prevent a runtime error
     41 
     42     if ( regexp.exec(pattern) == null || matches_array == null ) {
     43         AddTestCase(
     44             regexp + ".exec(" + str_pattern +")",
     45             matches_array,
     46             regexp.exec(pattern) );
     47 
     48         return;
     49     }
     50     AddTestCase(
     51         str_regexp + ".exec(" + str_pattern +").length",
     52         matches_array.length,
     53         regexp.exec(pattern).length );
     54 
     55     AddTestCase(
     56         str_regexp + ".exec(" + str_pattern +").index",
     57         index,
     58         regexp.exec(pattern).index );
     59 
     60     AddTestCase(
     61         str_regexp + ".exec(" + str_pattern +").input",
     62         escape(pattern),
     63         escape(regexp.exec(pattern).input) );
     64 
     65     AddTestCase(
     66         str_regexp + ".exec(" + str_pattern +").toString()",
     67         matches_array.toString(),
     68         escape(regexp.exec(pattern).toString()) );
     69 
     70     var limit = matches_array.length > regexp.exec(pattern).length
     71                 ? matches_array.length
     72                 : regexp.exec(pattern).length;
     73 
     74     for ( var matches = 0; matches < limit; matches++ ) {
     75         AddTestCase(
     76             str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
     77             matches_array[matches],
     78             escape(regexp.exec(pattern)[matches]) );
     79     }
     80 
     81 }
     82