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