js/src/tests/js1_3/jsref.js

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

mercurial