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