|
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: 09 July 2002 |
|
9 * SUMMARY: RegExp conformance test |
|
10 * |
|
11 * These testcases are derived from the examples in the ECMA-262 Ed.3 spec |
|
12 * scattered through section 15.10.2. |
|
13 * |
|
14 */ |
|
15 //----------------------------------------------------------------------------- |
|
16 var i = 0; |
|
17 var BUGNUMBER = '(none)'; |
|
18 var summary = 'RegExp conformance test'; |
|
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 pattern = /a|ab/; |
|
33 string = 'abc'; |
|
34 actualmatch = string.match(pattern); |
|
35 expectedmatch = Array('a'); |
|
36 addThis(); |
|
37 |
|
38 status = inSection(2); |
|
39 pattern = /((a)|(ab))((c)|(bc))/; |
|
40 string = 'abc'; |
|
41 actualmatch = string.match(pattern); |
|
42 expectedmatch = Array('abc', 'a', 'a', undefined, 'bc', undefined, 'bc'); |
|
43 addThis(); |
|
44 |
|
45 status = inSection(3); |
|
46 pattern = /a[a-z]{2,4}/; |
|
47 string = 'abcdefghi'; |
|
48 actualmatch = string.match(pattern); |
|
49 expectedmatch = Array('abcde'); |
|
50 addThis(); |
|
51 |
|
52 status = inSection(4); |
|
53 pattern = /a[a-z]{2,4}?/; |
|
54 string = 'abcdefghi'; |
|
55 actualmatch = string.match(pattern); |
|
56 expectedmatch = Array('abc'); |
|
57 addThis(); |
|
58 |
|
59 status = inSection(5); |
|
60 pattern = /(aa|aabaac|ba|b|c)*/; |
|
61 string = 'aabaac'; |
|
62 actualmatch = string.match(pattern); |
|
63 expectedmatch = Array('aaba', 'ba'); |
|
64 addThis(); |
|
65 |
|
66 status = inSection(6); |
|
67 pattern = /^(a+)\1*,\1+$/; |
|
68 string = 'aaaaaaaaaa,aaaaaaaaaaaaaaa'; |
|
69 actualmatch = string.match(pattern); |
|
70 expectedmatch = Array('aaaaaaaaaa,aaaaaaaaaaaaaaa', 'aaaaa'); |
|
71 addThis(); |
|
72 |
|
73 status = inSection(7); |
|
74 pattern = /(z)((a+)?(b+)?(c))*/; |
|
75 string = 'zaacbbbcac'; |
|
76 actualmatch = string.match(pattern); |
|
77 expectedmatch = Array('zaacbbbcac', 'z', 'ac', 'a', undefined, 'c'); |
|
78 addThis(); |
|
79 |
|
80 status = inSection(8); |
|
81 pattern = /(a*)*/; |
|
82 string = 'b'; |
|
83 actualmatch = string.match(pattern); |
|
84 expectedmatch = Array('', undefined); |
|
85 addThis(); |
|
86 |
|
87 status = inSection(9); |
|
88 pattern = /(a*)b\1+/; |
|
89 string = 'baaaac'; |
|
90 actualmatch = string.match(pattern); |
|
91 expectedmatch = Array('b', ''); |
|
92 addThis(); |
|
93 |
|
94 status = inSection(10); |
|
95 pattern = /(?=(a+))/; |
|
96 string = 'baaabac'; |
|
97 actualmatch = string.match(pattern); |
|
98 expectedmatch = Array('', 'aaa'); |
|
99 addThis(); |
|
100 |
|
101 status = inSection(11); |
|
102 pattern = /(?=(a+))a*b\1/; |
|
103 string = 'baaabac'; |
|
104 actualmatch = string.match(pattern); |
|
105 expectedmatch = Array('aba', 'a'); |
|
106 addThis(); |
|
107 |
|
108 status = inSection(12); |
|
109 pattern = /(.*?)a(?!(a+)b\2c)\2(.*)/; |
|
110 string = 'baaabaac'; |
|
111 actualmatch = string.match(pattern); |
|
112 expectedmatch = Array('baaabaac', 'ba', undefined, 'abaac'); |
|
113 addThis(); |
|
114 |
|
115 status = inSection(13); |
|
116 pattern = /(?=(a+))/; |
|
117 string = 'baaabac'; |
|
118 actualmatch = string.match(pattern); |
|
119 expectedmatch = Array('', 'aaa'); |
|
120 addThis(); |
|
121 |
|
122 |
|
123 |
|
124 //------------------------------------------------------------------------------------------------- |
|
125 test(); |
|
126 //------------------------------------------------------------------------------------------------- |
|
127 |
|
128 |
|
129 function addThis() |
|
130 { |
|
131 statusmessages[i] = status; |
|
132 patterns[i] = pattern; |
|
133 strings[i] = string; |
|
134 actualmatches[i] = actualmatch; |
|
135 expectedmatches[i] = expectedmatch; |
|
136 i++; |
|
137 } |
|
138 |
|
139 |
|
140 function test() |
|
141 { |
|
142 enterFunc ('test'); |
|
143 printBugNumber(BUGNUMBER); |
|
144 printStatus (summary); |
|
145 testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); |
|
146 exitFunc ('test'); |
|
147 } |