2
* The contents of this file are subject to the Netscape Public
3
* License Version 1.1 (the "License"); you may not use this file
4
* except in compliance with the License. You may obtain a copy of
5
* the License at http://www.mozilla.org/NPL/
7
* Software distributed under the License is distributed on an "AS IS"
8
* basis, WITHOUT WARRANTY OF ANY KIND, either expressed
9
* or implied. See the License for the specific language governing
10
* rights and limitations under the License.
12
* The Original Code is mozilla.org code.
14
* The Initial Developer of the Original Code is Netscape
15
* Communications Corporation. Portions created by Netscape are
16
* Copyright (C) 1998 Netscape Communications Corporation.
17
* All Rights Reserved.
19
* Contributor(s): pschwartau@netscape.com
22
* SUMMARY: Regression test for Bugzilla bug 87231:
23
* "Regular expression /(A)?(A.*)/ picks 'A' twice"
25
* See http://bugzilla.mozilla.org/show_bug.cgi?id=87231
28
* pattern = /^(A)?(A.*)$/;
30
* expectedmatch = Array('A', '', 'A');
33
* We expect the 1st subexpression (A)? NOT to consume the single 'A'.
34
* Recall that "?" means "match 0 or 1 times". Here, it should NOT do
35
* greedy matching: it should match 0 times instead of 1. This allows
36
* the 2nd subexpression to make the only match it can: the single 'A'.
37
* Such "altruism" is the only way there can be a successful global match...
39
//-------------------------------------------------------------------------------------------------
42
var cnEmptyString = '';
43
var summary = 'Testing regular expression /(A)?(A.*)/';
45
var statusmessages = new Array();
47
var patterns = new Array();
49
var strings = new Array();
51
var actualmatches = new Array();
52
var expectedmatch = '';
53
var expectedmatches = new Array();
56
pattern = /^(A)?(A.*)$/;
57
status = inSection(1);
59
actualmatch = string.match(pattern);
60
expectedmatch = Array('AAA', 'A', 'AA');
63
status = inSection(2);
65
actualmatch = string.match(pattern);
66
expectedmatch = Array('AA', 'A', 'A');
69
status = inSection(3);
71
actualmatch = string.match(pattern);
72
expectedmatch = Array('A', undefined, 'A'); // 'altruistic' case: see above
76
pattern = /(A)?(A.*)/;
77
var strL = 'zxcasd;fl\\\ ^';
78
var strR = 'aaAAaaaf;lrlrzs';
80
status = inSection(4);
81
string = strL + 'AAA' + strR;
82
actualmatch = string.match(pattern);
83
expectedmatch = Array('AAA' + strR, 'A', 'AA' + strR);
86
status = inSection(5);
87
string = strL + 'AA' + strR;
88
actualmatch = string.match(pattern);
89
expectedmatch = Array('AA' + strR, 'A', 'A' + strR);
92
status = inSection(6);
93
string = strL + 'A' + strR;
94
actualmatch = string.match(pattern);
95
expectedmatch = Array('A' + strR, undefined, 'A' + strR); // 'altruistic' case: see above
100
//-------------------------------------------------------------------------------------------------
102
//-------------------------------------------------------------------------------------------------
108
statusmessages[i] = status;
109
patterns[i] = pattern;
111
actualmatches[i] = actualmatch;
112
expectedmatches[i] = expectedmatch;
120
printBugNumber (bug);
121
printStatus (summary);
122
testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);