Debian Codegraph @

rhino/testsrc/tests/js1_3/jsref.js

raw symbols SCIP
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5 var completed = false;
6 var testcases;
7
8 SECTION = "";
9 VERSION = "";
10
11 BUGNUMBER ="";
12 var EXCLUDE = "";
13
14 TZ_DIFF = -8;
15
16 var TT = "";
17 var TT_ = "";
18 var BR = "";
19 var NBSP = " ";
20 var CR = "\n";
21 var FONT = "";
22 var FONT_ = "";
23 var FONT_RED = "";
24 var FONT_GREEN = "";
25 var B = "";
26 var B_ = ""
27 var H2 = "";
28 var H2_ = "";
29 var HR = "";
30 var DEBUG = false;
31
32 version(130);
33
34 var PASSED = " PASSED!"
35 var FAILED = " FAILED! expected: ";
36
37 function test() {
38 for ( tc=0; tc < testcases.length; tc++ ) {
39 testcases[tc].passed = writeTestCaseResult(
40 testcases[tc].expect,
41 testcases[tc].actual,
42 testcases[tc].description +" = "+
43 testcases[tc].actual );
44
45 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
46 }
47 stopTest();
48 return ( testcases );
49 }
50
51 function TestCase( n, d, e, a ) {
52 this.name = n;
53 this.description = d;
54 this.expect = e;
55 this.actual = a;
56 this.passed = true;
57 this.reason = "";
58
59 this.bugnumber = BUGNUMBER;
60
61 this.passed = getTestCaseResult( this.expect, this.actual );
62 if ( DEBUG ) {
63 print( "added " + this.description );
64 }
65 }
66 function startTest() {
67 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
68 if ( VERSION == "ECMA_1" ) {
69 version ( "130" );
70 }
71 if ( VERSION == "JS_1.3" ) {
72 version ( "130" );
73 }
74 if ( VERSION == "JS_1.2" ) {
75 version ( "120" );
76 }
77 if ( VERSION == "JS_1.1" ) {
78 version ( "110" );
79 }
80 // for ecma version 2.0, we will leave the javascript version to
81 // the default ( for now ).
82 }
83 function getTestCaseResult( expect, actual ) {
84 // because ( NaN == NaN ) always returns false, need to do
85 // a special compare to see if we got the right result.
86 if ( actual != actual ) {
87 if ( typeof actual == "object" ) {
88 actual = "NaN object";
89 } else {
90 actual = "NaN number";
91 }
92 }
93 if ( expect != expect ) {
94 if ( typeof expect == "object" ) {
95 expect = "NaN object";
96 } else {
97 expect = "NaN number";
98 }
99 }
100
101 var passed = ( expect == actual ) ? true : false;
102
103 // if both objects are numbers
104 // need to replace w/ IEEE standard for rounding
105 if ( !passed
106 && typeof(actual) == "number"
107 && typeof(expect) == "number"
108 ) {
109 if ( Math.abs(actual-expect) < 0.0000001 ) {
110 passed = true;
111 }
112 }
113
114 // verify type is the same
115 if ( typeof(expect) != typeof(actual) ) {
116 passed = false;
117 }
118
119 return passed;
120 }
121 function writeTestCaseResult( expect, actual, string ) {
122 var passed = getTestCaseResult( expect, actual );
123 writeFormattedResult( expect, actual, string, passed );
124 return passed;
125 }
126 function writeFormattedResult( expect, actual, string, passed ) {
127 var s = TT + string ;
128
129 for ( k = 0;
130 k < (60 - string.length >= 0 ? 60 - string.length : 5) ;
131 k++ ) {
132 }
133
134 s += B ;
135 s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ;
136
137 print( s + FONT_ + B_ + TT_ );
138
139 return passed;
140 }
141
142 function writeHeaderToLog( string ) {
143 print( H2 + string + H2_ );
144 }
145 function stopTest()
146 {
147 var sizeTag = "<#TEST CASES SIZE>";
148 var doneTag = "<#TEST CASES DONE>";
149 var beginTag = "<#TEST CASE ";
150 var endTag = ">";
151
152 print(sizeTag);
153 print(testcases.length);
154 for (tc = 0; tc < testcases.length; tc++)
155 {
156 print(beginTag + 'PASSED' + endTag);
157 print(testcases[tc].passed);
158 print(beginTag + 'NAME' + endTag);
159 print(testcases[tc].name);
160 print(beginTag + 'EXPECTED' + endTag);
161 print(testcases[tc].expect);
162 print(beginTag + 'ACTUAL' + endTag);
163 print(testcases[tc].actual);
164 print(beginTag + 'DESCRIPTION' + endTag);
165 print(testcases[tc].description);
166 print(beginTag + 'REASON' + endTag);
167 print(( testcases[tc].passed ) ? "" : "wrong value ");
168 print(beginTag + 'BUGNUMBER' + endTag);
169 print( BUGNUMBER );
170 }
171 print(doneTag);
172
173 print( HR );
174 gc();
175 }
176 function getFailedCases() {
177 for ( var i = 0; i < testcases.length; i++ ) {
178 if ( ! testcases[i].passed ) {
179 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
180 }
181 }
182 }
183 function err( msg, page, line ) {
184 testcases[tc].actual = "error";
185 testcases[tc].reason = msg;
186 writeTestCaseResult( testcases[tc].expect,
187 testcases[tc].actual,
188 testcases[tc].description +" = "+ testcases[tc].actual +
189 ": " + testcases[tc].reason );
190 stopTest();
191 return true;
192 }
193
194 function Enumerate ( o ) {
195 var p;
196 for ( p in o ) {
197 print( p +": " + o[p] );
198 }
199 }