RegressionTests__JavaScriptTestClass.st
author Stefan Vogel <sv@exept.de>
Tue, 11 Jun 2019 10:34:41 +0200
changeset 2321 32ea6329f5ad
parent 2006 60c218197fb0
permissions -rw-r--r--
class: stx_goodies_regression class changed: #classNamesAndAttributes make classes autoloaded that stc cannot compile (yet)

public class RegressionTests::JavaScriptTestClass extends Object
{
}


/** category: testing **/

/**
    (new JavaScriptTestClass).testForLoop1()
 **/
function testForLoop1() {
    var sum = 0;
    
    for (var i=0; i<10; i++) {
        sum += i;
    }
    return sum;
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testForLoop2()
 **/
function testForLoop2() {
    for (; ; ) {
        return 0;
    }
    return 1;
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testForLoop3()
 **/
function testForLoop3() {
    var i = 0;
    
    for (; ; ) {
        if (i == 10) return 0;
        i++;
    }
    return 1;
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testInnerFunction1()
 **/
function testInnerFunction1() {
    function f(x) {
        if (x === 0) return 1;
        Transcript.showCR(x);
        return 0;
    }
    
    return f(1);
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testInnerFunction2()
 **/
function testInnerFunction2() {
    function f(x) {
        function g(x) {
            if (x === 0) return 1;
            Transcript.showCR(x);
            return 0;
        }
        
        if (x === 0) return g(1);
        Transcript.showCR(x);
        return g(0);
    }
    
    return f(1);
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testMap1()
 **/
function testMap1() {
    return [1,2,3].map( el => el ** 2 );
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testMap2()
 **/
function testMap2() {
    return [1,2,3].map( (el) => el ** 2 );
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testMap3()
 **/
function testMap3() {
    return [1,2,3].map( (el) => { return el ** 2; } );
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testMap4()
 **/
function testMap4() {
    function f(el) { return el ** 2; };
    
    return [1,2,3].map( f );
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testMap5()
 **/
function testMap5() {
    function f(el) { 
        return el ** 2; 
    }
    
    return [1,2,3].map( f );
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testMap6()
 **/
function testMap6() {
    var f = function (el) { return el ** 2; };
    
    return [1,2,3].map( f );
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testMap7()
 **/
function testMap7() {
    var f = el => el ** 2;
    
    return [1,2,3].map( f );
}

/** category: testing **/

/**
    (new JavaScriptTestClass).testMap8()
 **/
function testMap8() {
    var f = (el => el ** 2);
    
    return [1,2,3].map( f );
}


/** category: documentation **/

static function version_CVS() {
    return("$Header$");
}