Debian Codegraph @

rhino/testsrc/tests/ecma_2/RegExp/hex-001.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5
6 gTestfile = 'hex-001.js';
7
8 /**
9 * File Name: RegExp/hex-001.js
10 * ECMA Section: 15.7.3.1
11 * Description: Based on ECMA 2 Draft 7 February 1999
12 * Positive test cases for constructing a RegExp object
13 * Author: [email protected]
14 * Date: 19 February 1999
15 */
16 var SECTION = "RegExp/hex-001";
17 var VERSION = "ECMA_2";
18 var TITLE = "RegExp patterns that contain HexicdecimalEscapeSequences";
19
20 startTest();
21
22 // These examples come from 15.7.1, HexidecimalEscapeSequence
23
24 AddRegExpCases( new RegExp("\x41"), "new RegExp('\\x41')", "A", "A", 1, 0, ["A"] );
25 AddRegExpCases( new RegExp("\x412"),"new RegExp('\\x412')", "A2", "A2", 1, 0, ["A2"] );
26 AddRegExpCases( new RegExp("\x1g"), "new RegExp('\\x1g')", "x1g","x1g", 1, 0, ["x1g"] );
27
28 AddRegExpCases( new RegExp("A"), "new RegExp('A')", "\x41", "\\x41", 1, 0, ["A"] );
29 AddRegExpCases( new RegExp("A"), "new RegExp('A')", "\x412", "\\x412", 1, 0, ["A"] );
30 AddRegExpCases( new RegExp("^x"), "new RegExp('^x')", "x412", "x412", 1, 0, ["x"]);
31 AddRegExpCases( new RegExp("A"), "new RegExp('A')", "A2", "A2", 1, 0, ["A"] );
32
33 test();
34
35 function AddRegExpCases(
36 regexp, str_regexp, pattern, str_pattern, length, index, matches_array ) {
37
38 // prevent a runtime error
39
40 if ( regexp.exec(pattern) == null || matches_array == null ) {
41 AddTestCase(
42 str_regexp + ".exec(" + pattern +")",
43 matches_array,
44 regexp.exec(pattern) );
45
46 return;
47 }
48
49 AddTestCase(
50 str_regexp + ".exec(" + str_pattern +").length",
51 length,
52 regexp.exec(pattern).length );
53
54 AddTestCase(
55 str_regexp + ".exec(" + str_pattern +").index",
56 index,
57 regexp.exec(pattern).index );
58
59 AddTestCase(
60 str_regexp + ".exec(" + str_pattern +").input",
61 pattern,
62 regexp.exec(pattern).input );
63
64 for ( var matches = 0; matches < matches_array.length; matches++ ) {
65 AddTestCase(
66 str_regexp + ".exec(" + str_pattern +")[" + matches +"]",
67 matches_array[matches],
68 regexp.exec(pattern)[matches] );
69 }
70 }