js/src/tests/ecma_2/RegExp/hex-001.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/hex-001.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,68 @@
     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/hex-001.js
    1.12 + *  ECMA Section:       15.7.3.1
    1.13 + *  Description:        Based on ECMA 2 Draft 7 February 1999
    1.14 + *  Positive test cases for constructing a RegExp object
    1.15 + *  Author:             christine@netscape.com
    1.16 + *  Date:               19 February 1999
    1.17 + */
    1.18 +var SECTION = "RegExp/hex-001";
    1.19 +var VERSION = "ECMA_2";
    1.20 +var TITLE   = "RegExp patterns that contain HexicdecimalEscapeSequences";
    1.21 +
    1.22 +startTest();
    1.23 +
    1.24 +// These examples come from 15.7.1, HexidecimalEscapeSequence
    1.25 +
    1.26 +AddRegExpCases( new RegExp("\x41"),  "new RegExp('\\x41')",  "A",  "A", 1, 0, ["A"] );
    1.27 +AddRegExpCases( new RegExp("\x412"),"new RegExp('\\x412')", "A2", "A2", 1, 0, ["A2"] );
    1.28 +
    1.29 +AddRegExpCases( new RegExp("A"),  "new RegExp('A')",  "\x41",  "\\x41",  1, 0, ["A"] );
    1.30 +AddRegExpCases( new RegExp("A"),  "new RegExp('A')",  "\x412", "\\x412", 1, 0, ["A"] );
    1.31 +AddRegExpCases( new RegExp("^x"), "new RegExp('^x')", "x412",  "x412",   1, 0, ["x"]);
    1.32 +AddRegExpCases( new RegExp("A"),  "new RegExp('A')",  "A2",    "A2",     1, 0, ["A"] );
    1.33 +
    1.34 +test();
    1.35 +
    1.36 +function AddRegExpCases(
    1.37 +  regexp, str_regexp, pattern, str_pattern, length, index, matches_array ) {
    1.38 +
    1.39 +  // prevent a runtime error
    1.40 +
    1.41 +  if ( regexp.exec(pattern) == null || matches_array == null ) {
    1.42 +    AddTestCase(
    1.43 +      str_regexp + ".exec(" + pattern +")",
    1.44 +      matches_array,
    1.45 +      regexp.exec(pattern) );
    1.46 +
    1.47 +    return;
    1.48 +  }
    1.49 +
    1.50 +  AddTestCase(
    1.51 +    str_regexp + ".exec(" + str_pattern +").length",
    1.52 +    length,
    1.53 +    regexp.exec(pattern).length );
    1.54 +
    1.55 +  AddTestCase(
    1.56 +    str_regexp + ".exec(" + str_pattern +").index",
    1.57 +    index,
    1.58 +    regexp.exec(pattern).index );
    1.59 +
    1.60 +  AddTestCase(
    1.61 +    str_regexp + ".exec(" + str_pattern +").input",
    1.62 +    pattern,
    1.63 +    regexp.exec(pattern).input );
    1.64 +
    1.65 +  for ( var matches = 0; matches < matches_array.length; matches++ ) {
    1.66 +    AddTestCase(
    1.67 +      str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
    1.68 +      matches_array[matches],
    1.69 +      regexp.exec(pattern)[matches] );
    1.70 +  }
    1.71 +}

mercurial