Debian Codegraph @

rhino/testsrc/tests/js1_5/Regress/regress-168347.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: 13 Sep 2002
9 * SUMMARY: Testing F.toString()
10 * See http://bugzilla.mozilla.org/show_bug.cgi?id=168347
11 *
12 */
13 //-----------------------------------------------------------------------------
14 var gTestfile = 'regress-168347.js';
15 var UBound = 0;
16 var BUGNUMBER = 168347;
17 var summary = "Testing F.toString()";
18 var status = '';
19 var statusitems = [];
20 var actual = '';
21 var actualvalues = [];
22 var expect= '';
23 var expectedvalues = [];
24 var FtoString = '';
25 var sFunc = '';
26
27 sFunc += 'function F()';
28 sFunc += '{';
29 sFunc += ' var f = arguments.callee;';
30 sFunc += ' f.i = 0;';
31 sFunc += '';
32 sFunc += ' try';
33 sFunc += ' {';
34 sFunc += ' f.i = f.i + 1;';
35 sFunc += ' print("i = i+1 succeeded \ti = " + f.i);';
36 sFunc += ' }';
37 sFunc += ' catch(e)';
38 sFunc += ' {';
39 sFunc += ' print("i = i+1 failed with " + e + "\ti = " + f.i);';
40 sFunc += ' }';
41 sFunc += '';
42 sFunc += ' try';
43 sFunc += ' {';
44 sFunc += ' ++f.i;';
45 sFunc += ' print("++i succeeded \t\ti = " + f.i);';
46 sFunc += ' }';
47 sFunc += ' catch(e)';
48 sFunc += ' {';
49 sFunc += ' print("++i failed with " + e + "\ti = " + f.i);';
50 sFunc += ' }';
51 sFunc += '';
52 sFunc += ' try';
53 sFunc += ' {';
54 sFunc += ' f.i++;';
55 sFunc += ' print("i++ succeeded \t\ti = " + f.i);';
56 sFunc += ' }';
57 sFunc += ' catch(e)';
58 sFunc += ' {';
59 sFunc += ' print("i++ failed with " + e + "\ti = " + f.i);';
60 sFunc += ' }';
61 sFunc += '';
62 sFunc += ' try';
63 sFunc += ' {';
64 sFunc += ' --f.i;';
65 sFunc += ' print("--i succeeded \t\ti = " + f.i);';
66 sFunc += ' }';
67 sFunc += ' catch(e)';
68 sFunc += ' {';
69 sFunc += ' print("--i failed with " + e + "\ti = " + f.i);';
70 sFunc += ' }';
71 sFunc += '';
72 sFunc += ' try';
73 sFunc += ' {';
74 sFunc += ' f.i--;';
75 sFunc += ' print("i-- succeeded \t\ti = " + f.i);';
76 sFunc += ' }';
77 sFunc += ' catch(e)';
78 sFunc += ' {';
79 sFunc += ' print("i-- failed with " + e + "\ti = " + f.i);';
80 sFunc += ' }';
81 sFunc += '}';
82
83
84 /*
85 * Use sFunc to define the function F. The test
86 * then rests on comparing F.toString() to sFunc.
87 */
88 eval(sFunc);
89
90
91 /*
92 * There are trivial whitespace differences between F.toString()
93 * and sFunc. So strip out whitespace before comparing them -
94 */
95 sFunc = stripWhite(sFunc);
96 FtoString = stripWhite(F.toString());
97
98
99 /*
100 * Break comparison into sections to make any failures
101 * easier for the developer to track down -
102 */
103 status = inSection(1);
104 actual = FtoString.substring(0,100);
105 expect = sFunc.substring(0,100);
106 addThis();
107
108 status = inSection(2);
109 actual = FtoString.substring(100,200);
110 expect = sFunc.substring(100,200);
111 addThis();
112
113 status = inSection(3);
114 actual = FtoString.substring(200,300);
115 expect = sFunc.substring(200,300);
116 addThis();
117
118 status = inSection(4);
119 actual = FtoString.substring(300,400);
120 expect = sFunc.substring(300,400);
121 addThis();
122
123 status = inSection(5);
124 actual = FtoString.substring(400,500);
125 expect = sFunc.substring(400,500);
126 addThis();
127
128 status = inSection(6);
129 actual = FtoString.substring(500,600);
130 expect = sFunc.substring(500,600);
131 addThis();
132
133 status = inSection(7);
134 actual = FtoString.substring(600,700);
135 expect = sFunc.substring(600,700);
136 addThis();
137
138 status = inSection(8);
139 actual = FtoString.substring(700,800);
140 expect = sFunc.substring(700,800);
141 addThis();
142
143 status = inSection(9);
144 actual = FtoString.substring(800,900);
145 expect = sFunc.substring(800,900);
146 addThis();
147
148
149
150 //-----------------------------------------------------------------------------
151 test();
152 //-----------------------------------------------------------------------------
153
154
155
156 function addThis()
157 {
158 statusitems[UBound] = status;
159 actualvalues[UBound] = actual;
160 expectedvalues[UBound] = expect;
161 UBound++;
162 }
163
164 /*
165 * Remove any whitespace characters; also
166 * any escaped tabs or escaped newlines.
167 */
168 function stripWhite(str)
169 {
170 var re = /\s|\\t|\\n/g;
171 return str.replace(re, '');
172 }
173
174
175 function test()
176 {
177 enterFunc('test');
178 printBugNumber(BUGNUMBER);
179 printStatus(summary);
180
181 for (var i=0; i<UBound; i++)
182 {
183 reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]);
184 }
185
186 exitFunc ('test');
187 }