Debian Codegraph @

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