js/src/tests/js1_3/jsref.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial