Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/regress-209919.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 *
8 * Date: 19 June 2003
9 * SUMMARY: Testing regexp submatches with quantifiers
10 *
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=209919
12 *
13 */
14 //-----------------------------------------------------------------------------
15 var gTestfile = 'regress-209919.js';
16 var i = 0;
17 var BUGNUMBER = 209919;
18 var summary = 'Testing regexp submatches with quantifiers';
19 var status = '';
20 var statusmessages = new Array();
21 var pattern = '';
22 var patterns = new Array();
23 var string = '';
24 var strings = new Array();
25 var actualmatch = '';
26 var actualmatches = new Array();
27 var expectedmatch = '';
28 var expectedmatches = new Array();
29
30
31 /*
32 * Waldemar: "ECMA-262 15.10.2.5, third algorithm, step 2.1 states that
33 * once the minimum repeat count (which is 0 for *, 1 for +, etc.) has
34 * been satisfied, an atom being repeated must not match the empty string."
35 *
36 * In this example, the minimum repeat count is 0, so the last thing the
37 * capturing parens is permitted to contain is the 'a'. It may NOT go on
38 * to capture the '' at the $ position of 'a', even though '' satifies
39 * the condition b*
40 *
41 */
42 status = inSection(1);
43 string = 'a';
44 pattern = /(a|b*)*/;
45 actualmatch = string.match(pattern);
46 expectedmatch = Array(string, 'a');
47 addThis();
48
49
50 /*
51 * In this example, the minimum repeat count is 5, so the capturing parens
52 * captures the 'a', then goes on to capture the '' at the $ position of 'a'
53 * 4 times before it has to stop. Therefore the last thing it contains is ''.
54 */
55 status = inSection(2);
56 string = 'a';
57 pattern = /(a|b*){5,}/;
58 actualmatch = string.match(pattern);
59 expectedmatch = Array(string, '');
60 addThis();
61
62
63 /*
64 * Reduction of the above examples to contain only the condition b*
65 * inside the capturing parens. This can be even harder to grasp!
66 *
67 * The global match is the '' at the ^ position of 'a', but the parens
68 * is NOT permitted to capture it since the minimum repeat count is 0!
69 */
70 status = inSection(3);
71 string = 'a';
72 pattern = /(b*)*/;
73 actualmatch = string.match(pattern);
74 expectedmatch = Array('', undefined);
75 addThis();
76
77
78 /*
79 * Here we have used the + quantifier (repeat count 1) outside the parens.
80 * Therefore the parens must capture at least once before stopping, so it
81 * does capture the '' this time -
82 */
83 status = inSection(4);
84 string = 'a';
85 pattern = /(b*)+/;
86 actualmatch = string.match(pattern);
87 expectedmatch = Array('', '');
88 addThis();
89
90
91 /*
92 * More complex examples -
93 */
94 pattern = /^\-?(\d{1,}|\.{0,})*(\,\d{1,})?$/;
95
96 status = inSection(5);
97 string = '100.00';
98 actualmatch = string.match(pattern);
99 expectedmatch = Array(string, '00', undefined);
100 addThis();
101
102 status = inSection(6);
103 string = '100,00';
104 actualmatch = string.match(pattern);
105 expectedmatch = Array(string, '100', ',00');
106 addThis();
107
108 status = inSection(7);
109 string = '1.000,00';
110 actualmatch = string.match(pattern);
111 expectedmatch = Array(string, '000', ',00');
112 addThis();
113
114
115
116
117 //-----------------------------------------------------------------------------
118 test();
119 //-----------------------------------------------------------------------------
120
121
122
123 function addThis()
124 {
125 statusmessages[i] = status;
126 patterns[i] = pattern;
127 strings[i] = string;
128 actualmatches[i] = actualmatch;
129 expectedmatches[i] = expectedmatch;
130 i++;
131 }
132
133
134 function test()
135 {
136 enterFunc ('test');
137 printBugNumber(BUGNUMBER);
138 printStatus (summary);
139 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
140 exitFunc ('test');
141 }