Debian Codegraph @

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