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