]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* ***** BEGIN LICENSE BLOCK ***** |
2 | * Version: NPL 1.1/GPL 2.0/LGPL 2.1 | |
3 | * | |
4 | * The contents of this file are subject to the Netscape Public License | |
5 | * Version 1.1 (the "License"); you may not use this file except in | |
6 | * compliance with the License. You may obtain a copy of the License at | |
7 | * http://www.mozilla.org/NPL/ | |
8 | * | |
9 | * Software distributed under the License is distributed on an "AS IS" basis, | |
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
11 | * for the specific language governing rights and limitations under the | |
12 | * License. | |
13 | * | |
14 | * The Original Code is JavaScript Engine testing utilities. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Netscape Communications Corp. | |
17 | * Portions created by the Initial Developer are Copyright (C) 2002 | |
18 | * the Initial Developer. All Rights Reserved. | |
19 | * | |
20 | * Contributor(s): desale@netscape.com, pschwartau@netscape.com | |
21 | * | |
22 | * Alternatively, the contents of this file may be used under the terms of | |
23 | * either the GNU General Public License Version 2 or later (the "GPL"), or | |
24 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), | |
25 | * in which case the provisions of the GPL or the LGPL are applicable instead | |
26 | * of those above. If you wish to allow use of your version of this file only | |
27 | * under the terms of either the GPL or the LGPL, and not to allow others to | |
28 | * use your version of this file under the terms of the NPL, indicate your | |
29 | * decision by deleting the provisions above and replace them with the notice | |
30 | * and other provisions required by the GPL or the LGPL. If you do not delete | |
31 | * the provisions above, a recipient may use your version of this file under | |
32 | * the terms of any one of the NPL, the GPL or the LGPL. | |
33 | * | |
34 | * ***** END LICENSE BLOCK ***** | |
35 | * | |
36 | * | |
37 | * Date: 13 Sep 2002 | |
38 | * SUMMARY: Testing F.toString() | |
39 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=168347 | |
40 | * | |
41 | */ | |
42 | //----------------------------------------------------------------------------- | |
43 | var UBound = 0; | |
44 | var bug = 168347; | |
45 | var summary = "Testing F.toString()"; | |
46 | var status = ''; | |
47 | var statusitems = []; | |
48 | var actual = ''; | |
49 | var actualvalues = []; | |
50 | var expect= ''; | |
51 | var expectedvalues = []; | |
52 | var FtoString = ''; | |
53 | var sFunc = ''; | |
54 | ||
55 | sFunc += 'function F()'; | |
56 | sFunc += '{'; | |
57 | sFunc += ' var f = arguments.callee;'; | |
58 | sFunc += ' f.i = 0;'; | |
59 | sFunc += ''; | |
60 | sFunc += ' try'; | |
61 | sFunc += ' {'; | |
62 | sFunc += ' f.i = f.i + 1;'; | |
63 | sFunc += ' print("i = i+1 succeeded \ti = " + f.i);'; | |
64 | sFunc += ' }'; | |
65 | sFunc += ' catch(e)'; | |
66 | sFunc += ' {'; | |
67 | sFunc += ' print("i = i+1 failed with " + e + "\ti = " + f.i);'; | |
68 | sFunc += ' }'; | |
69 | sFunc += ''; | |
70 | sFunc += ' try'; | |
71 | sFunc += ' {'; | |
72 | sFunc += ' ++f.i;'; | |
73 | sFunc += ' print("++i succeeded \t\ti = " + f.i);'; | |
74 | sFunc += ' }'; | |
75 | sFunc += ' catch(e)'; | |
76 | sFunc += ' {'; | |
77 | sFunc += ' print("++i failed with " + e + "\ti = " + f.i);'; | |
78 | sFunc += ' }'; | |
79 | sFunc += ''; | |
80 | sFunc += ' try'; | |
81 | sFunc += ' {'; | |
82 | sFunc += ' f.i++;'; | |
83 | sFunc += ' print("i++ succeeded \t\ti = " + f.i);'; | |
84 | sFunc += ' }'; | |
85 | sFunc += ' catch(e)'; | |
86 | sFunc += ' {'; | |
87 | sFunc += ' print("i++ failed with " + e + "\ti = " + f.i);'; | |
88 | sFunc += ' }'; | |
89 | sFunc += ''; | |
90 | sFunc += ' try'; | |
91 | sFunc += ' {'; | |
92 | sFunc += ' --f.i;'; | |
93 | sFunc += ' print("--i succeeded \t\ti = " + f.i);'; | |
94 | sFunc += ' }'; | |
95 | sFunc += ' catch(e)'; | |
96 | sFunc += ' {'; | |
97 | sFunc += ' print("--i failed with " + e + "\ti = " + f.i);'; | |
98 | sFunc += ' }'; | |
99 | sFunc += ''; | |
100 | sFunc += ' try'; | |
101 | sFunc += ' {'; | |
102 | sFunc += ' f.i--;'; | |
103 | sFunc += ' print("i-- succeeded \t\ti = " + f.i);'; | |
104 | sFunc += ' }'; | |
105 | sFunc += ' catch(e)'; | |
106 | sFunc += ' {'; | |
107 | sFunc += ' print("i-- failed with " + e + "\ti = " + f.i);'; | |
108 | sFunc += ' }'; | |
109 | sFunc += '}'; | |
110 | ||
111 | ||
112 | /* | |
113 | * Use sFunc to define the function F. The test | |
114 | * then rests on comparing F.toString() to sFunc. | |
115 | */ | |
116 | eval(sFunc); | |
117 | ||
118 | ||
119 | /* | |
120 | * There are trivial whitespace differences between F.toString() | |
121 | * and sFunc. So strip out whitespace before comparing them - | |
122 | */ | |
123 | sFunc = stripWhite(sFunc); | |
124 | FtoString = stripWhite(F.toString()); | |
125 | ||
126 | ||
127 | /* | |
128 | * Break comparison into sections to make any failures | |
129 | * easier for the developer to track down - | |
130 | */ | |
131 | status = inSection(1); | |
132 | actual = FtoString.substring(0,100); | |
133 | expect = sFunc.substring(0,100); | |
134 | addThis(); | |
135 | ||
136 | status = inSection(2); | |
137 | actual = FtoString.substring(100,200); | |
138 | expect = sFunc.substring(100,200); | |
139 | addThis(); | |
140 | ||
141 | status = inSection(3); | |
142 | actual = FtoString.substring(200,300); | |
143 | expect = sFunc.substring(200,300); | |
144 | addThis(); | |
145 | ||
146 | status = inSection(4); | |
147 | actual = FtoString.substring(300,400); | |
148 | expect = sFunc.substring(300,400); | |
149 | addThis(); | |
150 | ||
151 | status = inSection(5); | |
152 | actual = FtoString.substring(400,500); | |
153 | expect = sFunc.substring(400,500); | |
154 | addThis(); | |
155 | ||
156 | status = inSection(6); | |
157 | actual = FtoString.substring(500,600); | |
158 | expect = sFunc.substring(500,600); | |
159 | addThis(); | |
160 | ||
161 | status = inSection(7); | |
162 | actual = FtoString.substring(600,700); | |
163 | expect = sFunc.substring(600,700); | |
164 | addThis(); | |
165 | ||
166 | status = inSection(8); | |
167 | actual = FtoString.substring(700,800); | |
168 | expect = sFunc.substring(700,800); | |
169 | addThis(); | |
170 | ||
171 | status = inSection(9); | |
172 | actual = FtoString.substring(800,900); | |
173 | expect = sFunc.substring(800,900); | |
174 | addThis(); | |
175 | ||
176 | ||
177 | ||
178 | //----------------------------------------------------------------------------- | |
179 | test(); | |
180 | //----------------------------------------------------------------------------- | |
181 | ||
182 | ||
183 | ||
184 | function addThis() | |
185 | { | |
186 | statusitems[UBound] = status; | |
187 | actualvalues[UBound] = actual; | |
188 | expectedvalues[UBound] = expect; | |
189 | UBound++; | |
190 | } | |
191 | ||
192 | /* | |
193 | * Remove any whitespace characters; also | |
194 | * any escaped tabs or escaped newlines. | |
195 | */ | |
196 | function stripWhite(str) | |
197 | { | |
198 | var re = /\s|\\t|\\n/g; | |
199 | return str.replace(re, ''); | |
200 | } | |
201 | ||
202 | ||
203 | function test() | |
204 | { | |
205 | enterFunc('test'); | |
206 | printBugNumber(bug); | |
207 | printStatus(summary); | |
208 | ||
209 | for (var i=0; i<UBound; i++) | |
210 | { | |
211 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); | |
212 | } | |
213 | ||
214 | exitFunc ('test'); | |
215 | } |