Debian Codegraph @

rhino/testsrc/tests/ecma_3/RegExp/regress-191479.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: 31 January 2003
9 * SUMMARY: Testing regular expressions of form /(x|y){n,}/
10 *
11 * See http://bugzilla.mozilla.org/show_bug.cgi?id=191479
12 *
13 */
14 //-----------------------------------------------------------------------------
15 var gTestfile = 'regress-191479.js';
16 var i = 0;
17 var BUGNUMBER = 191479;
18 var summary = 'Testing regular expressions of form /(x|y){n,}/';
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 status = inSection(1);
32 string = '12 3 45';
33 pattern = /(\d|\d\s){2,}/;
34 actualmatch = string.match(pattern);
35 expectedmatch = Array('12', '2');
36 addThis();
37
38 status = inSection(2);
39 string = '12 3 45';
40 pattern = /(\d|\d\s){4,}/;
41 actualmatch = string.match(pattern);
42 expectedmatch = Array(string, '5');
43 addThis();
44
45 status = inSection(3);
46 string = '12 3 45';
47 pattern = /(\d|\d\s)+/;
48 actualmatch = string.match(pattern);
49 expectedmatch = Array('12', '2');
50 addThis();
51
52 status = inSection(4);
53 string = '12 3 45';
54 pattern = /(\d\s?){4,}/;
55 actualmatch = string.match(pattern);
56 expectedmatch = Array(string, '5');
57 addThis();
58
59 /*
60 * Let's reverse the operands in Sections 1-3 above -
61 */
62 status = inSection(5);
63 string = '12 3 45';
64 pattern = /(\d\s|\d){2,}/;
65 actualmatch = string.match(pattern);
66 expectedmatch = Array(string, '5');
67 addThis();
68
69 status = inSection(6);
70 string = '12 3 45';
71 pattern = /(\d\s|\d){4,}/;
72 actualmatch = string.match(pattern);
73 expectedmatch = Array(string, '5');
74 addThis();
75
76 status = inSection(7);
77 string = '12 3 45';
78 pattern = /(\d\s|\d)+/;
79 actualmatch = string.match(pattern);
80 expectedmatch = Array(string, '5');
81 addThis();
82
83
84 /*
85 * Let's take all 7 sections above and make each quantifer non-greedy.
86 *
87 * This is done by appending ? to it. It doesn't change the meaning of
88 * the quantifier, but makes it non-greedy, which affects the results -
89 */
90 status = inSection(8);
91 string = '12 3 45';
92 pattern = /(\d|\d\s){2,}?/;
93 actualmatch = string.match(pattern);
94 expectedmatch = Array('12', '2');
95 addThis();
96
97 status = inSection(9);
98 string = '12 3 45';
99 pattern = /(\d|\d\s){4,}?/;
100 actualmatch = string.match(pattern);
101 expectedmatch = Array('12 3 4', '4');
102 addThis();
103
104 status = inSection(10);
105 string = '12 3 45';
106 pattern = /(\d|\d\s)+?/;
107 actualmatch = string.match(pattern);
108 expectedmatch = Array('1', '1');
109 addThis();
110
111 status = inSection(11);
112 string = '12 3 45';
113 pattern = /(\d\s?){4,}?/;
114 actualmatch = string.match(pattern);
115 expectedmatch = Array('12 3 4', '4');
116 addThis();
117
118 status = inSection(12);
119 string = '12 3 45';
120 pattern = /(\d\s|\d){2,}?/;
121 actualmatch = string.match(pattern);
122 expectedmatch = Array('12 ', '2 ');
123 addThis();
124
125 status = inSection(13);
126 string = '12 3 45';
127 pattern = /(\d\s|\d){4,}?/;
128 actualmatch = string.match(pattern);
129 expectedmatch = Array('12 3 4', '4');
130 addThis();
131
132 status = inSection(14);
133 string = '12 3 45';
134 pattern = /(\d\s|\d)+?/;
135 actualmatch = string.match(pattern);
136 expectedmatch = Array('1', '1');
137 addThis();
138
139
140
141 //-----------------------------------------------------------------------------
142 test();
143 //-----------------------------------------------------------------------------
144
145
146
147 function addThis()
148 {
149 statusmessages[i] = status;
150 patterns[i] = pattern;
151 strings[i] = string;
152 actualmatches[i] = actualmatch;
153 expectedmatches[i] = expectedmatch;
154 i++;
155 }
156
157
158 function test()
159 {
160 enterFunc ('test');
161 printBugNumber(BUGNUMBER);
162 printStatus (summary);
163 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches);
164 exitFunc ('test');
165 }