Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/regress-87231.js

raw symbols SCIP
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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: 22 June 2001
8 *
9 * SUMMARY: Regression test for Bugzilla bug 87231:
10 * "Regular expression /(A)?(A.*)/ picks 'A' twice"
11 *
12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=87231
13 * Key case:
14 *
15 * pattern = /^(A)?(A.*)$/;
16 * string = 'A';
17 * expectedmatch = Array('A', '', 'A');
18 *
19 *
20 * We expect the 1st subexpression (A)? NOT to consume the single 'A'.
21 * Recall that "?" means "match 0 or 1 times". Here, it should NOT do
22 * greedy matching: it should match 0 times instead of 1. This allows
23 * the 2nd subexpression to make the only match it can: the single 'A'.
24 * Such "altruism" is the only way there can be a successful global match...
25 */
26 //-----------------------------------------------------------------------------
27 var gTestfile = 'regress-87231.js';
28 var i = 0;
29 var BUGNUMBER = 87231;
30 var cnEmptyString = '';
31 var summary = 'Testing regular expression /(A)?(A.*)/';
32 var status = '';
33 var statusmessages = new Array();
34 var pattern = '';
35 var patterns = new Array();
36 var string = '';
37 var strings = new Array();
38 var actualmatch = '';
39 var actualmatches = new Array();
40 var expectedmatch = '';
41 var expectedmatches = new Array();
42
43
44 pattern = /^(A)?(A.*)$/;
45 status = inSection(1);
46 string = 'AAA';
47 actualmatch = string.match(pattern);
48 expectedmatch = Array('AAA', 'A', 'AA');
49 addThis();
50
51 status = inSection(2);
52 string = 'AA';
53 actualmatch = string.match(pattern);
54 expectedmatch = Array('AA', 'A', 'A');
55 addThis();
56
57 status = inSection(3);
58 string = 'A';
59 actualmatch = string.match(pattern);
60 expectedmatch = Array('A', undefined, 'A'); // 'altruistic' case: see above
61 addThis();
62
63
64 pattern = /(A)?(A.*)/;
65 var strL = 'zxcasd;fl\\\ ^';
66 var strR = 'aaAAaaaf;lrlrzs';
67
68 status = inSection(4);
69 string = strL + 'AAA' + strR;
70 actualmatch = string.match(pattern);
71 expectedmatch = Array('AAA' + strR, 'A', 'AA' + strR);
72 addThis();
73
74 status = inSection(5);
75 string = strL + 'AA' + strR;
76 actualmatch = string.match(pattern);
77 expectedmatch = Array('AA' + strR, 'A', 'A' + strR);
78 addThis();
79
80 status = inSection(6);
81 string = strL + 'A' + strR;
82 actualmatch = string.match(pattern);
83 expectedmatch = Array('A' + strR, undefined, 'A' + strR); // 'altruistic' case: see above
84 addThis();
85
86
87
88 //-------------------------------------------------------------------------------------------------
89 test();
90 //-------------------------------------------------------------------------------------------------
91
92
93
94 function addThis()
95 {
96 statusmessages[i] = status;
97 patterns[i] = pattern;
98 strings[i] = string;
99 actualmatches[i] = actualmatch;
100 expectedmatches[i] = expectedmatch;
101 i++;
102 }
103
104
105 function test()
106 {
107 enterFunc ('test');
108 printBugNumber(BUGNUMBER);
109 printStatus (summary);
110 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
111 exitFunc ('test');
112 }