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): mozilla@pdavis.cx, pschwartau@netscape.com
20 * Date: 22 October 2001
22 * SUMMARY: Regression test for Bugzilla bug 105972:
23 * "/^.*?$/ will not match anything"
25 * See http://bugzilla.mozilla.org/show_bug.cgi?id=105972
27 //-----------------------------------------------------------------------------
30 var summary = 'Regression test for Bugzilla bug 105972';
31 var cnEmptyString = '';
33 var statusmessages = new Array();
35 var patterns = new Array();
37 var strings = new Array();
39 var actualmatches = new Array();
40 var expectedmatch = '';
41 var expectedmatches = new Array();
45 * The bug: this match was coming up null in Rhino and SpiderMonkey.
46 * It should match the whole string. The reason:
48 * The * operator is greedy, but *? is non-greedy: it will stop
49 * at the simplest match it can find. But the pattern here asks us
50 * to match till the end of the string. So the simplest match must
51 * go all the way out to the end, and *? has no choice but to do it.
53 status = inSection(1);
55 string = 'Hello World';
56 actualmatch = string.match(pattern);
57 expectedmatch = Array(string);
62 * Leave off the '$' condition - here we expect the empty string.
63 * Unlike the above pattern, we don't have to match till the end of
64 * the string, so the non-greedy operator *? doesn't try to...
66 status = inSection(2);
68 string = 'Hello World';
69 actualmatch = string.match(pattern);
70 expectedmatch = Array(cnEmptyString);
75 * Try '$' combined with an 'or' operator.
77 * The operator *? will consume the string from left to right,
78 * attempting to satisfy the condition (:|$). When it hits ':',
79 * the match will stop because the operator *? is non-greedy.
81 * The submatch $1 = (:|$) will contain the ':'
83 status = inSection(3);
84 pattern = /^.*?(:|$)/;
85 string = 'Hello: World';
86 actualmatch = string.match(pattern);
87 expectedmatch = Array('Hello:', ':');
92 * Again, '$' combined with an 'or' operator.
94 * The operator * will consume the string from left to right,
95 * attempting to satisfy the condition (:|$). When it hits ':',
96 * the match will not stop since * is greedy. The match will
97 * continue until it hits $, the end-of-string boundary.
99 * The submatch $1 = (:|$) will contain the empty string
100 * conceived to exist at the end-of-string boundary.
102 status = inSection(4);
103 pattern = /^.*(:|$)/;
104 string = 'Hello: World';
105 actualmatch = string.match(pattern);
106 expectedmatch = Array(string, cnEmptyString);
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
120 statusmessages[i] = status;
121 patterns[i] = pattern;
123 actualmatches[i] = actualmatch;
124 expectedmatches[i] = expectedmatch;
132 printBugNumber (bug);
133 printStatus (summary);
134 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);