1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/tests/js1_4/jsref.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,166 @@ 1.4 +var completed = false; 1.5 +var testcases; 1.6 + 1.7 +var BUGNUMBER=""; 1.8 +var EXCLUDE = ""; 1.9 + 1.10 +var TT = ""; 1.11 +var TT_ = ""; 1.12 +var BR = ""; 1.13 +var NBSP = " "; 1.14 +var CR = "\n"; 1.15 +var FONT = ""; 1.16 +var FONT_ = ""; 1.17 +var FONT_RED = ""; 1.18 +var FONT_GREEN = ""; 1.19 +var B = ""; 1.20 +var B_ = "" 1.21 +var H2 = ""; 1.22 +var H2_ = ""; 1.23 +var HR = ""; 1.24 + 1.25 +var PASSED = " PASSED!" 1.26 +var FAILED = " FAILED! expected: "; 1.27 + 1.28 +version( 140 ); 1.29 +function test() { 1.30 + for ( tc=0; tc < testcases.length; tc++ ) { 1.31 + testcases[tc].passed = writeTestCaseResult( 1.32 + testcases[tc].expect, 1.33 + testcases[tc].actual, 1.34 + testcases[tc].description +" = "+ 1.35 + testcases[tc].actual ); 1.36 + 1.37 + testcases[tc].reason += ( testcases[tc].passed ) ? "" : "wrong value "; 1.38 + } 1.39 + stopTest(); 1.40 + return ( testcases ); 1.41 +} 1.42 +function TestCase( n, d, e, a ) { 1.43 + this.name = n; 1.44 + this.description = d; 1.45 + this.expect = e; 1.46 + this.actual = a; 1.47 + this.passed = true; 1.48 + this.reason = ""; 1.49 + this.bugnumber = BUGNUMBER; 1.50 + 1.51 + this.passed = getTestCaseResult( this.expect, this.actual ); 1.52 +} 1.53 +function startTest() { 1.54 +/* 1.55 + // JavaScript 1.3 is supposed to be compliant ecma version 1.0 1.56 + if ( VERSION == "ECMA_1" ) { 1.57 + version ( "130" ); 1.58 + } 1.59 + if ( VERSION == "JS_1.3" ) { 1.60 + version ( "130" ); 1.61 + } 1.62 + if ( VERSION == "JS_1.2" ) { 1.63 + version ( "120" ); 1.64 + } 1.65 + if ( VERSION == "JS_1.1" ) { 1.66 + version ( "110" ); 1.67 + } 1.68 + // for ecma version 2.0, we will leave the javascript version to 1.69 + // the default ( for now ). 1.70 +*/ 1.71 +} 1.72 +function getTestCaseResult( expect, actual ) { 1.73 + // because ( NaN == NaN ) always returns false, need to do 1.74 + // a special compare to see if we got the right result. 1.75 + if ( actual != actual ) { 1.76 + if ( typeof actual == "object" ) { 1.77 + actual = "NaN object"; 1.78 + } else { 1.79 + actual = "NaN number"; 1.80 + } 1.81 + } 1.82 + if ( expect != expect ) { 1.83 + if ( typeof expect == "object" ) { 1.84 + expect = "NaN object"; 1.85 + } else { 1.86 + expect = "NaN number"; 1.87 + } 1.88 + } 1.89 + 1.90 + var passed = ( expect == actual ) ? true : false; 1.91 + 1.92 + // if both objects are numbers, give a little leeway for rounding. 1.93 + if ( !passed 1.94 + && typeof(actual) == "number" 1.95 + && typeof(expect) == "number" 1.96 + ) { 1.97 + if ( Math.abs(actual-expect) < 0.0000001 ) { 1.98 + passed = true; 1.99 + } 1.100 + } 1.101 + 1.102 + // verify type is the same 1.103 + if ( typeof(expect) != typeof(actual) ) { 1.104 + passed = false; 1.105 + } 1.106 + 1.107 + return passed; 1.108 +} 1.109 +function writeTestCaseResult( expect, actual, string ) { 1.110 + var passed = getTestCaseResult( expect, actual ); 1.111 + writeFormattedResult( expect, actual, string, passed ); 1.112 + return passed; 1.113 +} 1.114 +function writeFormattedResult( expect, actual, string, passed ) { 1.115 + var s = TT + string ; 1.116 + 1.117 + for ( k = 0; 1.118 + k < (60 - string.length >= 0 ? 60 - string.length : 5) ; 1.119 + k++ ) { 1.120 +// s += NBSP; 1.121 + } 1.122 + 1.123 + s += B ; 1.124 + s += ( passed ) ? FONT_GREEN + NBSP + PASSED : FONT_RED + NBSP + FAILED + expect + TT_ ; 1.125 + 1.126 + print( s + FONT_ + B_ + TT_ ); 1.127 + 1.128 + return passed; 1.129 +} 1.130 + 1.131 +function writeHeaderToLog( string ) { 1.132 + print( H2 + string + H2_ ); 1.133 +} 1.134 +function stopTest() { 1.135 + var sizeTag = "<#TEST CASES SIZE>"; 1.136 + var doneTag = "<#TEST CASES DONE>"; 1.137 + var beginTag = "<#TEST CASE "; 1.138 + var endTag = ">"; 1.139 + 1.140 + print(sizeTag); 1.141 + print(testcases.length); 1.142 + for (tc = 0; tc < testcases.length; tc++) 1.143 + { 1.144 + print(beginTag + 'PASSED' + endTag); 1.145 + print(testcases[tc].passed); 1.146 + print(beginTag + 'NAME' + endTag); 1.147 + print(testcases[tc].name); 1.148 + print(beginTag + 'EXPECTED' + endTag); 1.149 + print(testcases[tc].expect); 1.150 + print(beginTag + 'ACTUAL' + endTag); 1.151 + print(testcases[tc].actual); 1.152 + print(beginTag + 'DESCRIPTION' + endTag); 1.153 + print(testcases[tc].description); 1.154 + print(beginTag + 'REASON' + endTag); 1.155 + print(( testcases[tc].passed ) ? "" : "wrong value "); 1.156 + print(beginTag + 'BUGNUMBER' + endTag); 1.157 + print( BUGNUMBER ); 1.158 + 1.159 + } 1.160 + print(doneTag); 1.161 + gc(); 1.162 +} 1.163 +function getFailedCases() { 1.164 + for ( var i = 0; i < testcases.length; i++ ) { 1.165 + if ( ! testcases[i].passed ) { 1.166 + print( testcases[i].description +" = " +testcases[i].actual +" expected: "+ testcases[i].expect ); 1.167 + } 1.168 + } 1.169 +}