js/src/tests/ecma_2/RegExp/unicode-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/unicode-001.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     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/unicode-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/unicode-001.js";
    1.19 +var VERSION = "ECMA_2";
    1.20 +var TITLE   = "new RegExp( pattern, flags )";
    1.21 +
    1.22 +startTest();
    1.23 +
    1.24 +// These examples come from 15.7.1, UnicodeEscapeSequence
    1.25 +
    1.26 +AddRegExpCases( /\u0041/, "/\\u0041/",   "A", "A", 1, 0, ["A"] );
    1.27 +AddRegExpCases( /\u00412/, "/\\u00412/", "A2", "A2", 1, 0, ["A2"] );
    1.28 +AddRegExpCases( /\u00412/, "/\\u00412/", "A2", "A2", 1, 0, ["A2"] );
    1.29 +AddRegExpCases( /\u001g/, "/\\u001g/", "u001g", "u001g", 1, 0, ["u001g"] );
    1.30 +
    1.31 +AddRegExpCases( /A/,  "/A/",  "\u0041", "\\u0041",   1, 0, ["A"] );
    1.32 +AddRegExpCases( /A/,  "/A/",  "\u00412", "\\u00412", 1, 0, ["A"] );
    1.33 +AddRegExpCases( /A2/, "/A2/", "\u00412", "\\u00412", 1, 0, ["A2"]);
    1.34 +AddRegExpCases( /A/,  "/A/",  "A2",      "A2",       1, 0, ["A"] );
    1.35 +
    1.36 +test();
    1.37 +
    1.38 +function AddRegExpCases(
    1.39 +  regexp, str_regexp, pattern, str_pattern, length, index, matches_array ) {
    1.40 +
    1.41 +  AddTestCase(
    1.42 +    str_regexp + " .exec(" + str_pattern +").length",
    1.43 +    length,
    1.44 +    regexp.exec(pattern).length );
    1.45 +
    1.46 +  AddTestCase(
    1.47 +    str_regexp + " .exec(" + str_pattern +").index",
    1.48 +    index,
    1.49 +    regexp.exec(pattern).index );
    1.50 +
    1.51 +  AddTestCase(
    1.52 +    str_regexp + " .exec(" + str_pattern +").input",
    1.53 +    pattern,
    1.54 +    regexp.exec(pattern).input );
    1.55 +
    1.56 +  for ( var matches = 0; matches < matches_array.length; matches++ ) {
    1.57 +    AddTestCase(
    1.58 +      str_regexp + " .exec(" + str_pattern +")[" + matches +"]",
    1.59 +      matches_array[matches],
    1.60 +      regexp.exec(pattern)[matches] );
    1.61 +  }
    1.62 +}

mercurial