| 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 |
* Date: 06 February 2001 |
| 8 |
* |
| 9 |
* SUMMARY: Arose from Bugzilla bug 78156: |
| 10 |
* "m flag of regular expression does not work with $" |
| 11 |
* |
| 12 |
* See http://bugzilla.mozilla.org/show_bug.cgi?id=78156 |
| 13 |
* |
| 14 |
* The m flag means a regular expression should search strings |
| 15 |
* across multiple lines, i.e. across '\n', '\r'. |
| 16 |
*/ |
| 17 |
//----------------------------------------------------------------------------- |
| 18 |
var i = 0; |
| 19 |
var BUGNUMBER = 78156; |
| 20 |
var summary = 'Testing regular expressions with ^, $, and the m flag -'; |
| 21 |
var status = ''; |
| 22 |
var statusmessages = new Array(); |
| 23 |
var pattern = ''; |
| 24 |
var patterns = new Array(); |
| 25 |
var string = ''; |
| 26 |
var strings = new Array(); |
| 27 |
var actualmatch = ''; |
| 28 |
var actualmatches = new Array(); |
| 29 |
var expectedmatch = ''; |
| 30 |
var expectedmatches = new Array(); |
| 31 |
|
| 32 |
/* |
| 33 |
* All patterns have an m flag; all strings are multiline. |
| 34 |
* Looking for digit characters at beginning/end of lines. |
| 35 |
*/ |
| 36 |
|
| 37 |
string = 'aaa\n789\r\nccc\r\n345'; |
| 38 |
status = inSection(1); |
| 39 |
pattern = /^\d/gm; |
| 40 |
actualmatch = string.match(pattern); |
| 41 |
expectedmatch = ['7','3']; |
| 42 |
addThis(); |
| 43 |
|
| 44 |
status = inSection(2); |
| 45 |
pattern = /\d$/gm; |
| 46 |
actualmatch = string.match(pattern); |
| 47 |
expectedmatch = ['9','5']; |
| 48 |
addThis(); |
| 49 |
|
| 50 |
string = 'aaa\n789\r\nccc\r\nddd'; |
| 51 |
status = inSection(3); |
| 52 |
pattern = /^\d/gm; |
| 53 |
actualmatch = string.match(pattern); |
| 54 |
expectedmatch = ['7']; |
| 55 |
addThis(); |
| 56 |
|
| 57 |
status = inSection(4); |
| 58 |
pattern = /\d$/gm; |
| 59 |
actualmatch = string.match(pattern); |
| 60 |
expectedmatch = ['9']; |
| 61 |
addThis(); |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
//------------------------------------------------------------------------------------------------- |
| 66 |
test(); |
| 67 |
//------------------------------------------------------------------------------------------------- |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
function addThis() |
| 72 |
{ |
| 73 |
statusmessages[i] = status; |
| 74 |
patterns[i] = pattern; |
| 75 |
strings[i] = string; |
| 76 |
actualmatches[i] = actualmatch; |
| 77 |
expectedmatches[i] = expectedmatch; |
| 78 |
i++; |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
function test() |
| 83 |
{ |
| 84 |
printBugNumber(BUGNUMBER); |
| 85 |
printStatus (summary); |
| 86 |
testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); |
| 87 |
} |