Exemplo n.º 1
0
def test_binary_integer_ops(a, b, op_str, op_lambda):
    code = "c = a {} b".format(op_str)

    if op_str in "/%" and b == 0:
        with pytest.raises(DivisionByZeroException):
            run(code, a=a, b=b)
    else:
        out = run(code, a=a, b=b)
        assert out["c"] == op_lambda(a, b)
Exemplo n.º 2
0
def test_func_accessing_global_scope():
    b = {}
    e = run("x=0 func test() { return x + 2} a = test()")
    assert e == {"x": 0, "a": 2}
Exemplo n.º 3
0
def test_func_call_without_assign():
    b = {}
    e = run("x=0 func test() { x = 2} test()")
    assert e == {"x": 2}
Exemplo n.º 4
0
def test_func_scope_overlapping_global():
    b = {}
    e = run("x=0 func test(x) { x = x + 1} test(2)")
    assert e == {"x": 3}
Exemplo n.º 5
0
def test_normal_for():
    e = run("x = 0 for i = 0; i < 10; i = i + 1 {x = x + 1}")
    assert e == {"x": 10, "i": 10}
Exemplo n.º 6
0
def test_infinite_for_loop():
    with pytest.raises(ExecutionCountExceededException):
        run("x = 0 for ;1; {x = x + 1}", max_op_count=1000)
Exemplo n.º 7
0
def test_for_with_empty_statements():
    e = run("x = 0 for ;x < 10; {x = x + 1}")
    assert e == {"x": 10}
Exemplo n.º 8
0
def test_newlines():
    e = run("\n" * 8)
    assert e == {}
Exemplo n.º 9
0
def test_empty():
    e = run("")
    assert e == {}
Exemplo n.º 10
0
def test_trailing_newlines():
    e = run("a=2" + "\n" * 8)
    assert e["a"] == 2
Exemplo n.º 11
0
def test_op_not_or(a, b):
    end = run("c = not (a or b)", a=a, b=b)
    assert end["c"] == (not (a or b))
Exemplo n.º 12
0
def test_op_not(a):
    end = run("b = not a", a=a)
    assert end["b"] == (not a)
Exemplo n.º 13
0
def test_binary_logical_ops(a, b, op_str, op_lambda):
    code = "c = a {} b".format(op_str)
    out = run(code, a=a, b=b)
    assert out["c"] == op_lambda(a, b)
Exemplo n.º 14
0
def test_array_consts(a):
    end = run("a={}".format(a))
    assert end["a"] == a