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