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