示例#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)
示例#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}
示例#3
0
def test_func_call_without_assign():
    b = {}
    e = run("x=0 func test() { x = 2} test()")
    assert e == {"x": 2}
示例#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}
示例#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}
示例#6
0
def test_infinite_for_loop():
    with pytest.raises(ExecutionCountExceededException):
        run("x = 0 for ;1; {x = x + 1}", max_op_count=1000)
示例#7
0
def test_for_with_empty_statements():
    e = run("x = 0 for ;x < 10; {x = x + 1}")
    assert e == {"x": 10}
示例#8
0
def test_newlines():
    e = run("\n" * 8)
    assert e == {}
示例#9
0
def test_empty():
    e = run("")
    assert e == {}
示例#10
0
def test_trailing_newlines():
    e = run("a=2" + "\n" * 8)
    assert e["a"] == 2
示例#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))
示例#12
0
def test_op_not(a):
    end = run("b = not a", a=a)
    assert end["b"] == (not a)
示例#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)
示例#14
0
def test_array_consts(a):
    end = run("a={}".format(a))
    assert end["a"] == a