|
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 |
|
7 /** |
|
8 * File Name: RegExp/hex-001.js |
|
9 * ECMA Section: 15.7.3.1 |
|
10 * Description: Based on ECMA 2 Draft 7 February 1999 |
|
11 * Positive test cases for constructing a RegExp object |
|
12 * Author: christine@netscape.com |
|
13 * Date: 19 February 1999 |
|
14 */ |
|
15 var SECTION = "RegExp/hex-001"; |
|
16 var VERSION = "ECMA_2"; |
|
17 var TITLE = "RegExp patterns that contain HexicdecimalEscapeSequences"; |
|
18 |
|
19 startTest(); |
|
20 |
|
21 // These examples come from 15.7.1, HexidecimalEscapeSequence |
|
22 |
|
23 AddRegExpCases( new RegExp("\x41"), "new RegExp('\\x41')", "A", "A", 1, 0, ["A"] ); |
|
24 AddRegExpCases( new RegExp("\x412"),"new RegExp('\\x412')", "A2", "A2", 1, 0, ["A2"] ); |
|
25 |
|
26 AddRegExpCases( new RegExp("A"), "new RegExp('A')", "\x41", "\\x41", 1, 0, ["A"] ); |
|
27 AddRegExpCases( new RegExp("A"), "new RegExp('A')", "\x412", "\\x412", 1, 0, ["A"] ); |
|
28 AddRegExpCases( new RegExp("^x"), "new RegExp('^x')", "x412", "x412", 1, 0, ["x"]); |
|
29 AddRegExpCases( new RegExp("A"), "new RegExp('A')", "A2", "A2", 1, 0, ["A"] ); |
|
30 |
|
31 test(); |
|
32 |
|
33 function AddRegExpCases( |
|
34 regexp, str_regexp, pattern, str_pattern, length, index, matches_array ) { |
|
35 |
|
36 // prevent a runtime error |
|
37 |
|
38 if ( regexp.exec(pattern) == null || matches_array == null ) { |
|
39 AddTestCase( |
|
40 str_regexp + ".exec(" + pattern +")", |
|
41 matches_array, |
|
42 regexp.exec(pattern) ); |
|
43 |
|
44 return; |
|
45 } |
|
46 |
|
47 AddTestCase( |
|
48 str_regexp + ".exec(" + str_pattern +").length", |
|
49 length, |
|
50 regexp.exec(pattern).length ); |
|
51 |
|
52 AddTestCase( |
|
53 str_regexp + ".exec(" + str_pattern +").index", |
|
54 index, |
|
55 regexp.exec(pattern).index ); |
|
56 |
|
57 AddTestCase( |
|
58 str_regexp + ".exec(" + str_pattern +").input", |
|
59 pattern, |
|
60 regexp.exec(pattern).input ); |
|
61 |
|
62 for ( var matches = 0; matches < matches_array.length; matches++ ) { |
|
63 AddTestCase( |
|
64 str_regexp + ".exec(" + str_pattern +")[" + matches +"]", |
|
65 matches_array[matches], |
|
66 regexp.exec(pattern)[matches] ); |
|
67 } |
|
68 } |