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