Debian Codegraph @

rhino/testsrc/tests/lc3/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 var completed = false;
5 var testcases;
6
7 SECTION = "";
8 VERSION = "";
9 TITLE = "";
10
11 BUGNUMBER="";
12 var EXCLUDE = "";
13
14 var GLOBAL = "[object global]";
15 var TT = "";
16 var TT_ = "";
17 var BR = "";
18 var NBSP = " ";
19 var CR = "\n";
20 var FONT = "";
21 var FONT_ = "";
22 var FONT_RED = "";
23 var FONT_GREEN = "";
24 var B = "";
25 var B_ = ""
26 var H2 = "";
27 var H2_ = "";
28 var HR = "";
29
30 // version("130");
31
32 var PASSED = " PASSED!"
33 var FAILED = " FAILED! expected: ";
34
35 function test() {
36 for ( tc=0; tc < testcases.length; tc++ ) {
37 testcases[tc].passed = writeTestCaseResult(
38 testcases[tc].expect,
39 testcases[tc].actual,
40 testcases[tc].description +" = "+
41 testcases[tc].actual );
42
43 testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value ";
44 }
45 stopTest();
46 return ( testcases );
47 }
48
49 function TestCase( d, e, a ) {
50 this.name = SECTION;
51 this.description = d;
52 this.expect = e;
53 this.actual = a;
54 this.passed = true;
55 this.reason = "";
56 this.bugnumber = BUGNUMBER;
57
58 this.passed = getTestCaseResult( this.expect, this.actual );
59 }
60
61 function startTest() {
62 testcases = new Array();
63 tc = 0;
64
65 // JavaScript 1.3 is supposed to be compliant ecma version 1.0
66 if ( VERSION == "JS1_4" ) {
67 version( 140 );
68 }
69 if ( VERSION == "ECMA_1" ) {
70 version ( "130" );
71 }
72 if ( VERSION == "JS1_3" ) {
73 version ( "130" );
74 }
75 if ( VERSION == "JS1_2" ) {
76 version ( "120" );
77 }
78 if ( VERSION == "JS1_1" ) {
79 version ( "110" );
80 }
81
82 writeHeaderToLog( SECTION + " "+ TITLE);
83
84 // verify that DataTypeClass is on the CLASSPATH
85
86 DT = Packages.com.netscape.javascript.qa.liveconnect.DataTypeClass;
87
88 if ( typeof DT != "function" ) {
89 throw "Test Exception: "+
90 "com.netscape.javascript.qa.liveconnect.DataTypeClass "+
91 "is not on the CLASSPATH";
92 }
93 }
94
95 function getTestCaseResult( expect, actual ) {
96 // because ( NaN == NaN ) always returns false, need to do
97 // a special compare to see if we got the right result.
98 if ( actual != actual ) {
99 if ( typeof actual == "object" ) {
100 actual = "NaN object";
101 } else {
102 actual = "NaN number";
103 }
104 }
105 if ( expect != expect ) {
106 if ( typeof expect == "object" ) {
107 expect = "NaN object";
108 } else {
109 expect = "NaN number";
110 }
111 }
112
113 var passed = ( expect == actual ) ? true : false;
114
115 // if both objects are numbers
116 // need to replace w/ IEEE standard for rounding
117 if ( !passed
118 && typeof(actual) == "number"
119 && typeof(expect) == "number"
120 ) {
121 if ( Math.abs(actual-expect) < 0.0000001 ) {
122 passed = true;
123 }
124 }
125
126 // verify type is the same
127 if ( typeof(expect) != typeof(actual) ) {
128 passed = false;
129 }
130
131 return passed;
132 }
133 function writeTestCaseResult( expect, actual, string ) {
134 var passed = getTestCaseResult( expect, actual );
135 writeFormattedResult( expect, actual, string, passed );
136 return passed;
137 }
138 function writeFormattedResult( expect, actual, string, passed ) {
139 var s = TT + string ;
140
141 for ( k = 0;
142 k < (60 - string.length >= 0 ? 60 - string.length : 5) ;
143 k++ ) {
144 // s += NBSP;
145 }
146
147 s += B ;
148 s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ;
149
150 print( s + FONT_ + B_ + TT_ );
151
152 return passed;
153 }
154
155 function writeHeaderToLog( string ) {
156 print( H2 + string + H2_ );
157 }
158 function stopTest()
159 {
160
161 var sizeTag = "<#TEST CASES SIZE>";
162 var doneTag = "<#TEST CASES DONE>";
163 var beginTag = "<#TEST CASE ";
164 var endTag = ">";
165
166 print(sizeTag);
167 print(testcases.length);
168 for (tc = 0; tc < testcases.length; tc++)
169 {
170 print(beginTag + 'PASSED' + endTag);
171 print(testcases[tc].passed);
172 print(beginTag + 'NAME' + endTag);
173 print(testcases[tc].name);
174 print(beginTag + 'EXPECTED' + endTag);
175 print(testcases[tc].expect);
176 print(beginTag + 'ACTUAL' + endTag);
177 print(testcases[tc].actual);
178 print(beginTag + 'DESCRIPTION' + endTag);
179 print(testcases[tc].description);
180 print(beginTag + 'REASON' + endTag);
181 print(( testcases[tc].passed ) ? "" : "wrong value ");
182 print(beginTag + 'BUGNUMBER' + endTag);
183 print( BUGNUMBER );
184 }
185 print(doneTag);
186
187 print( HR );
188 gc();
189 }
190 function getFailedCases() {
191 for ( var i = 0; i < testcases.length; i++ ) {
192 if ( ! testcases[i].passed ) {
193 print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect );
194 }
195 }
196 }