]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/ecma_3/RegExp/regress-57572.js
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
20 * Date: 28 December 2000
22 * SUMMARY: Testing regular expressions containing the ? character.
23 * Arose from Bugzilla bug 57572: "RegExp with ? matches incorrectly"
25 * See http://bugzilla.mozilla.org/show_bug.cgi?id=57572
28 //-----------------------------------------------------------------------------
31 var summary
= 'Testing regular expressions containing "?"';
32 var cnEmptyString
= ''; var cnSingleSpace
= ' ';
34 var statusmessages
= new Array();
36 var patterns
= new Array();
38 var strings
= new Array();
40 var actualmatches
= new Array();
41 var expectedmatch
= '';
42 var expectedmatches
= new Array();
45 status
= inSection(1);
46 pattern
= /(\S+)?(.*)/;
48 actualmatch
= string
.match(pattern
);
49 expectedmatch
= Array(string
, 'Test', ' this'); //single space in front of 'this'
52 status
= inSection(2);
53 pattern
= /(\S
+)? ?(.*)/; //single space between the ? characters
55 actualmatch
= string
.match(pattern
);
56 expectedmatch
= Array(string
, 'Test', 'this'); //NO space in front of 'this'
59 status
= inSection(3);
60 pattern
= /(\S+)?(.*)/;
61 string
= 'Stupid phrase, with six - (short) words';
62 actualmatch
= string
.match(pattern
);
63 expectedmatch
= Array(string
, 'Stupid', ' phrase, with six - (short) words'); //single space in front of 'phrase'
66 status
= inSection(4);
67 pattern
= /(\S
+)? ?(.*)/; //single space between the ? characters
68 string
= 'Stupid phrase, with six - (short) words';
69 actualmatch
= string
.match(pattern
);
70 expectedmatch
= Array(string
, 'Stupid', 'phrase, with six - (short) words'); //NO space in front of 'phrase'
74 // let's add an extra back-reference this time - three instead of two -
75 status
= inSection(5);
76 pattern
= /(\S
+)?( ?)(.*)/; //single space before second ? character
77 string
= 'Stupid phrase, with six - (short) words';
78 actualmatch
= string
.match(pattern
);
79 expectedmatch
= Array(string
, 'Stupid', cnSingleSpace
, 'phrase, with six - (short) words');
82 status
= inSection(6);
83 pattern
= /^(\S
+)?( ?)(B
+)$/; //single space before second ? character
85 actualmatch
= string
.match(pattern
);
86 expectedmatch
= Array(string
, 'AAABB', cnEmptyString
, 'B');
89 status
= inSection(7);
90 pattern
= /(\S+)?(!?)(.*)/;
91 string
= 'WOW !!! !!!';
92 actualmatch
= string
.match(pattern
);
93 expectedmatch
= Array(string
, 'WOW', cnEmptyString
, ' !!! !!!');
96 status
= inSection(8);
97 pattern
= /(.+)?(!?)(!+)/;
98 string
= 'WOW !!! !!!';
99 actualmatch
= string
.match(pattern
);
100 expectedmatch
= Array(string
, 'WOW !!! !!', cnEmptyString
, '!');
105 //-----------------------------------------------------------------------------
107 //-----------------------------------------------------------------------------
113 statusmessages
[i
] = status
;
114 patterns
[i
] = pattern
;
116 actualmatches
[i
] = actualmatch
;
117 expectedmatches
[i
] = expectedmatch
;
125 printBugNumber (bug
);
126 printStatus (summary
);
127 testRegExp(statusmessages
, patterns
, strings
, actualmatches
, expectedmatches
);