Example #1
0
def test_for_loop_str():
    node = ForLoop(
        Assign(t("="), Var(t("i")), Int(t("0"))),
        BinaryOp(t("<"), Var(t("i")), Int(t("10"))),
        Assign(t("="), Var(t("i")), BinaryOp(t("+"), Var(t("i")),
                                             Int(t("1")))),
        Block([Assign(t("="), Var(t("a")), Int(t("1")))]))
    assert str(node) == "for i = 0; i < 10; i = i + 1 {\n" + TAB + "a = 1\n}"
Example #2
0
def test_control_block_str():
    node = ControlBlock([
        If(BinaryOp(t("<"), Int(t("1")), Var(t("a"))),
           Block([Assign(t("="), Var(t("a")), Int(t("1")))])),
        If(BinaryOp(t("<"), Int(t("1")), Var(t("a"))),
           Block([Assign(t("="), Var(t("a")), Int(t("1")))]))
    ], Block([Assign(t("="), Var(t("a")), Int(t("1")))]))
    assert str(
        node
    ) == "if 1 < a {\n" + TAB + "a = 1\n} elif 1 < a {\n" + TAB + "a = 1\n} else {\n" + TAB + "a = 1\n}"
Example #3
0
def v(n):
    return Var(Token(TokenTypes.VAR, n))
Example #4
0
def test_if_str():
    node = If(BinaryOp(t("<"), Int(t("1")), Var(t("a"))),
              Block([Assign(t("="), Var(t("a")), Int(t("1")))]))
    assert str(node) == "if 1 < a {\n" + TAB + "a = 1\n}"
Example #5
0
def test_assign_str():
    node = Assign(t("="), Var(t("a")), Int(t("1")))
    assert str(node) == "a = 1"
Example #6
0
def test_block_str():
    node = Block([Assign(t("="), Var(t("a")), Int(t("1")))])
    assert str(node) == "{\n" + TAB + "a = 1\n}"
Example #7
0
def test_binaryop_str():
    node = BinaryOp(t("+"), Int(t("1")), Var(t("a")))
    assert str(node) == "1 + a"
Example #8
0
def test_binaryop_complex_str():
    node = BinaryOp(t("+"), BinaryOp(t("+"), Int(t("1")), Var(t("a"))),
                    Int(t("1")))
    assert str(node) == "(1 + a) + 1"
Example #9
0
def test_unaryop_str():
    node = UnaryOp(t("not"), Var(t("a")))
    assert str(node) == "not(a)"
Example #10
0
def test_var_str():
    node = Var(t("a"))
    assert str(node) == "a"
Example #11
0
def test_ast_eq_dif_types():
    assert Int(t("1")) != Var(t("1"))
Example #12
0
def test_control_block_eq_diff_type():
    assert ControlBlock([If([], Block())]) != Var(t("1"))
Example #13
0
def test_if_eq_diff_type():
    assert If([], Block()) != Var(t("1"))