1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/ecma_2/RegExp/multiline-001.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 + 1.10 +/** 1.11 + * File Name: RegExp/multiline-001.js 1.12 + * ECMA Section: 1.13 + * Description: Based on ECMA 2 Draft 7 February 1999 1.14 + * 1.15 + * Date: 19 February 1999 1.16 + */ 1.17 + 1.18 +var SECTION = "RegExp/multiline-001"; 1.19 +var VERSION = "ECMA_2"; 1.20 +var TITLE = "RegExp: multiline flag"; 1.21 +var BUGNUMBER="343901"; 1.22 + 1.23 +startTest(); 1.24 + 1.25 +var woodpeckers = "ivory-billed\ndowny\nhairy\nacorn\nyellow-bellied sapsucker\n" + 1.26 + "northern flicker\npileated\n"; 1.27 + 1.28 +AddRegExpCases( /.*[y]$/m, woodpeckers, woodpeckers.indexOf("downy"), ["downy"] ); 1.29 + 1.30 +AddRegExpCases( /.*[d]$/m, woodpeckers, woodpeckers.indexOf("ivory-billed"), ["ivory-billed"] ); 1.31 + 1.32 +test(); 1.33 + 1.34 + 1.35 +function AddRegExpCases 1.36 +( regexp, pattern, index, matches_array ) { 1.37 + 1.38 + // prevent a runtime error 1.39 + 1.40 + if ( regexp.exec(pattern) == null || matches_array == null ) { 1.41 + AddTestCase( 1.42 + regexp + ".exec(" + pattern +")", 1.43 + matches_array, 1.44 + regexp.exec(pattern) ); 1.45 + 1.46 + return; 1.47 + } 1.48 + 1.49 + AddTestCase( 1.50 + regexp.toString() + ".exec(" + pattern +").length", 1.51 + matches_array.length, 1.52 + regexp.exec(pattern).length ); 1.53 + 1.54 + AddTestCase( 1.55 + regexp.toString() + ".exec(" + pattern +").index", 1.56 + index, 1.57 + regexp.exec(pattern).index ); 1.58 + 1.59 + AddTestCase( 1.60 + regexp + ".exec(" + pattern +").input", 1.61 + pattern, 1.62 + regexp.exec(pattern).input ); 1.63 + 1.64 + 1.65 + for ( var matches = 0; matches < matches_array.length; matches++ ) { 1.66 + AddTestCase( 1.67 + regexp + ".exec(" + pattern +")[" + matches +"]", 1.68 + matches_array[matches], 1.69 + regexp.exec(pattern)[matches] ); 1.70 + } 1.71 +}