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