initial import
[vuplus_webkit] / Source / JavaScriptCore / tests / mozilla / ecma_2 / RegExp / multiline-001.js
1 /**
2  *  File Name:          RegExp/multiline-001.js
3  *  ECMA Section:
4  *  Description:        Based on ECMA 2 Draft 7 February 1999
5  *
6  *  Date:               19 February 1999
7  */
8
9     var SECTION = "RegExp/multiline-001";
10     var VERSION = "ECMA_2";
11     var TITLE   = "RegExp: multiline flag";
12     var BUGNUMBER="343901";
13
14     startTest();
15
16     var woodpeckers = "ivory-billed\ndowny\nhairy\nacorn\nyellow-bellied sapsucker\n" +
17         "northern flicker\npileated\n";
18
19     AddRegExpCases( /.*[y]$/m, woodpeckers, woodpeckers.indexOf("downy"), ["downy"] );
20
21     AddRegExpCases( /.*[d]$/m, woodpeckers, woodpeckers.indexOf("ivory-billed"), ["ivory-billed"] );
22
23     test();
24
25
26 function AddRegExpCases
27     ( regexp, pattern, index, matches_array ) {
28
29     // prevent a runtime error
30
31     if ( regexp.exec(pattern) == null || matches_array == null ) {
32         AddTestCase(
33             regexp + ".exec(" + pattern +")",
34             matches_array,
35             regexp.exec(pattern) );
36
37         return;
38     }
39
40     AddTestCase(
41         regexp.toString() + ".exec(" + pattern +").length",
42         matches_array.length,
43         regexp.exec(pattern).length );
44
45     AddTestCase(
46         regexp.toString() + ".exec(" + pattern +").index",
47         index,
48         regexp.exec(pattern).index );
49
50     AddTestCase(
51         regexp + ".exec(" + pattern +").input",
52         pattern,
53         regexp.exec(pattern).input );
54
55
56     for ( var matches = 0; matches < matches_array.length; matches++ ) {
57         AddTestCase(
58             regexp + ".exec(" + pattern +")[" + matches +"]",
59             matches_array[matches],
60             regexp.exec(pattern)[matches] );
61     }
62 }