]>
git.saurik.com Git - apple/javascriptcore.git/blob - tests/mozilla/js1_2/jsref.js
1 /* The contents of this file are subject to the Netscape Public
2 * License Version 1.1 (the "License"); you may not use this file
3 * except in compliance with the License. You may obtain a copy of
4 * the License at http://www.mozilla.org/NPL/
6 * Software distributed under the License is distributed on an "AS
7 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
8 * implied. See the License for the specific language governing
9 * rights and limitations under the License.
11 * The Original Code is Mozilla Communicator client code, released March
14 * The Initial Developer of the Original Code is Netscape Communications
15 * Corporation. Portions created by Netscape are
16 * Copyright (C) 1998 Netscape Communications Corporation. All
22 var completed
= false;
34 var GLOBAL
= "[object global]";
35 var PASSED
= " PASSED!"
36 var FAILED
= " FAILED! expected: ";
42 * change this for date tests if you're not in PST
46 /* wrapper for test cas constructor that doesn't require the SECTION
50 function AddTestCase( description
, expect
, actual
) {
51 testcases
[tc
++] = new TestCase( SECTION
, description
, expect
, actual
);
53 function TestCase( n
, d
, e
, a
) {
60 this.bugnumber
= BUGNUMBER
;
62 this.passed
= getTestCaseResult( this.expect
, this.actual
);
64 function startTest() {
67 // for ecma version 2.0, we will leave the javascript version to
68 // the default ( for now ).
69 // print out bugnumber
72 writeLineToLog ("BUGNUMBER: " + BUGNUMBER
);
75 testcases
= new Array();
80 for ( tc
=0; tc
< testcases
.length
; tc
++ ) {
81 testcases
[tc
].passed
= writeTestCaseResult(
84 testcases
[tc
].description
+" = "+
85 testcases
[tc
].actual
);
87 testcases
[tc
].reason
+= ( testcases
[tc
].passed
) ? "" : "wrong value ";
92 function getTestCaseResult( expect
, actual
) {
93 // because ( NaN == NaN ) always returns false, need to do
94 // a special compare to see if we got the right result.
95 if ( actual
!= actual
) {
96 if ( typeof actual
== "object" ) {
97 actual
= "NaN object";
99 actual
= "NaN number";
102 if ( expect
!= expect
) {
103 if ( typeof expect
== "object" ) {
104 expect
= "NaN object";
106 expect
= "NaN number";
110 var passed
= ( expect
== actual
) ? true : false;
112 // if both objects are numbers, give a little leeway for rounding.
114 && typeof(actual
) == "number"
115 && typeof(expect
) == "number"
117 if ( Math
.abs(actual
-expect
) < 0.0000001 ) {
122 // verify type is the same
123 if ( typeof(expect
) != typeof(actual
) ) {
130 * Begin printing functions. These functions use the shell's
131 * print function. When running tests in the browser, these
132 * functions, override these functions with functions that use
136 function writeTestCaseResult( expect
, actual
, string
) {
137 var passed
= getTestCaseResult( expect
, actual
);
138 writeFormattedResult( expect
, actual
, string
, passed
);
141 function writeFormattedResult( expect
, actual
, string
, passed
) {
143 s
+= ( passed
) ? PASSED : FAILED
+ expect
;
147 function writeLineToLog( string
) {
150 function writeHeaderToLog( string
) {
153 /* end of print functions */
156 function stopTest() {
157 var sizeTag
= "<#TEST CASES SIZE>";
158 var doneTag
= "<#TEST CASES DONE>";
159 var beginTag
= "<#TEST CASE ";
163 print(testcases
.length
);
164 for (tc
= 0; tc
< testcases
.length
; tc
++)
166 print(beginTag
+ 'PASSED' + endTag
);
167 print(testcases
[tc
].passed
);
168 print(beginTag
+ 'NAME' + endTag
);
169 print(testcases
[tc
].name
);
170 print(beginTag
+ 'EXPECTED' + endTag
);
171 print(testcases
[tc
].expect
);
172 print(beginTag
+ 'ACTUAL' + endTag
);
173 print(testcases
[tc
].actual
);
174 print(beginTag
+ 'DESCRIPTION' + endTag
);
175 print(testcases
[tc
].description
);
176 print(beginTag
+ 'REASON' + endTag
);
177 print(( testcases
[tc
].passed
) ? "" : "wrong value ");
178 print(beginTag
+ 'BUGNUMBER' + endTag
);
185 function getFailedCases() {
186 for ( var i
= 0; i
< testcases
.length
; i
++ ) {
187 if ( ! testcases
[i
].passed
) {
188 print( testcases
[i
].description
+" = " +testcases
[i
].actual
+" expected: "+ testcases
[i
].expect
);
192 function err( msg
, page
, line
) {
193 testcases
[tc
].actual
= "error";
194 testcases
[tc
].reason
= msg
;
195 writeTestCaseResult( testcases
[tc
].expect
,
196 testcases
[tc
].actual
,
197 testcases
[tc
].description
+" = "+ testcases
[tc
].actual
+
198 ": " + testcases
[tc
].reason
);
202 function Enumerate ( o
) {
205 print( p
+": " + o
[p
] );
208 function GetContext() {
209 return Packages
.com
.netscape
.javascript
.Context
.getCurrentContext();
211 function OptLevel( i
) {
213 var cx
= GetContext();
214 cx
.setOptimizationLevel(i
);