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