How to use the cobra.base.compile function in cobra

To help you get started, we’ve selected a few cobra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github niwinz / cobrascript / tests / test_basic.py View on Github external
def test_basic_op_mod():
    assert compile("3 // 2") == "Math.floor(3 / 2);"
github niwinz / cobrascript / tests / test_basic.py View on Github external
def test_simple_decorator():
    input = """
    @decorator
    def test(x, y):
        console.log("test")
    """

    expected = """
    var test;
    test = function(x, y) {
        console.log("test");
    };
    test = decorator(test);
    """
    compiled = compile(input)
    assert compiled == norm(expected)
github niwinz / cobrascript / tests / test_basic.py View on Github external
def test_decorator_with_params():
    input = """
    @decorator("test-param")
    def test(x, y):
        console.log("test")
    """

    expected = """
    var test;
    test = function(x, y) {
        console.log("test");
    };
    test = decorator("test-param")(test);
    """
    compiled = compile(input)
    print(compiled)
    assert compiled == norm(expected)
github niwinz / cobrascript / tests / test_basic.py View on Github external
else:
        console.log("test else")
    """

    expected = """
    var ref_0;
    ref_0 = true;
    while (my_var) {
        ref_0 = false;
        console.log("test");
    }
    if (ref_0) {
        console.log("test else");
    }
    """
    compiled = compile(input)
    print(compiled)
    assert compiled == norm(expected)
github niwinz / cobrascript / tests / test_basic.py View on Github external
def test_function_call_with_lambda_as_parameter():
    input = """
    x = jQuery(".span")
    x.on("click", lambda e: e.preventDefault())
    """

    expected = """
    var x;
    x = jQuery(".span");
    x.on("click", function(e) {
        e.preventDefault();
    });
    """

    assert compile(input) == norm(expected)
github niwinz / cobrascript / tests / test_basic.py View on Github external
def test_none_assignation():
    input = "x = None"
    expected = """
    var x;
    x = null;
    """
    assert compile(input) == norm(expected)
github niwinz / cobrascript / tests / test_basic.py View on Github external
else:
            return a + 2
    """

    expected = """
    var foo;
    foo = function(a) {
        if (a === null) {
            return null;
        } else {
            return a + 2;
        }
    };
    """

    assert compile(input) == norm(expected)
github niwinz / cobrascript / tests / test_basic.py View on Github external
def test_logic_is():
    assert compile("2 is 2") == "2 === 2;"
github niwinz / cobrascript / tests / test_basic.py View on Github external
def test_exceptions_raise():
    input = """
    raise "sample exception"
    """

    expected = """
    throw "sample exception";
    """
    compiled = compile(input)
    print(compiled)
    assert compiled == norm(expected)
github niwinz / cobrascript / tests / test_basic.py View on Github external
def test_new_import_and_try_overwrite():
    input = """
    import _new as new
    new = 2
    """

    with pytest.raises(RuntimeError):
        compiled = compile(input)