コード例 #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
ファイル: test_func.py プロジェクト: derpferd/little-python
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
ファイル: test_func.py プロジェクト: derpferd/little-python
def test_func_call_without_assign():
    b = {}
    e = run("x=0 func test() { x = 2} test()")
    assert e == {"x": 2}
コード例 #4
0
ファイル: test_func.py プロジェクト: derpferd/little-python
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
ファイル: test_edges.py プロジェクト: derpferd/little-python
def test_newlines():
    e = run("\n" * 8)
    assert e == {}
コード例 #9
0
ファイル: test_edges.py プロジェクト: derpferd/little-python
def test_empty():
    e = run("")
    assert e == {}
コード例 #10
0
ファイル: test_edges.py プロジェクト: derpferd/little-python
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
ファイル: test_const.py プロジェクト: derpferd/little-python
def test_array_consts(a):
    end = run("a={}".format(a))
    assert end["a"] == a