Пример #1
0
def test_get_rep_works_and_doesnt():
    g = generated_code()
    statement.iftest("true")
    g.set_rep("dude", 5)
    assert 5 == g.get_rep("dude")
    g.pop_scope()
    assert None is g.get_rep("dude")
Пример #2
0
def test_nothing_else_starts_with_top_level_scope():
    top = gc_scope_top_level()
    g = generated_code()
    s1 = statement.iftest("true")
    g.add_statement(s1)
    scope_1 = g.current_scope()

    assert not top.starts_with(scope_1)
Пример #3
0
def test_everything_starts_with_top_level_scope():
    top = gc_scope_top_level()
    g = generated_code()
    s1 = statement.iftest("true")
    g.add_statement(s1)
    scope_1 = g.current_scope()

    assert scope_1.starts_with(top)
Пример #4
0
def test_get_rep_hidden():
    g = generated_code()
    g.set_rep("dude", 5)
    s1 = statement.iftest("true")
    g.add_statement(s1)
    g.set_rep("dude", 10)
    assert 10 == g.get_rep("dude")
    g.pop_scope()
    assert 5 == g.get_rep("dude")
Пример #5
0
def test_insert_two_levels():
    s1 = statement.iftest("true")
    s2 = statement.set_var("v1", "true")
    g = generated_code()

    g.add_statement(s1)
    g.add_statement(s2)

    assert 1 == len(s1._statements)
Пример #6
0
def test_deepest_scope_equal():
    g = generated_code()
    s1 = statement.iftest("true")
    statement.set_var("v1", "true")
    g.add_statement(s1)
    scope_1 = g.current_scope()

    v1 = crep.cpp_value("v1", scope_1, ctyp.terminal('int'))
    v2 = crep.cpp_value("v2", scope_1, ctyp.terminal('int'))

    assert v1 == deepest_scope(v1, v2)
    assert v2 == deepest_scope(v2, v1)
Пример #7
0
def test_deepest_scope_one_greater():
    g = generated_code()
    s1 = statement.iftest("true")
    s2 = statement.iftest("true")
    g.add_statement(s1)
    scope_1 = g.current_scope()
    g.add_statement(s2)
    scope_2 = g.current_scope()

    v1 = crep.cpp_value("v1", scope_1, ctyp.terminal('int'))
    v2 = crep.cpp_value("v2", scope_2, ctyp.terminal('int'))

    assert v2 == deepest_scope(v1, v2)
    assert v2 == deepest_scope(v2, v1)
Пример #8
0
def test_insert_in_middle():
    s1 = statement.iftest("true")
    s2 = statement.set_var("v1", "true")
    g = generated_code()

    g.add_statement(s1)
    g.add_statement(s2)

    s3 = statement.iftest("fork")
    g.add_statement(s3, below=s1)

    assert 1 == len(s1._statements)
    assert 1 == len(s3._statements)

    assert s1._statements[0] is s3
    assert s3._statements[0] is s2
Пример #9
0
def test_get_rep_when_set_level_up():
    g = generated_code()
    g.set_rep("dude", 5)
    s1 = statement.iftest("true")
    g.add_statement(s1)
    assert 5 == g.get_rep("dude")
Пример #10
0
def test_get_rep_when_set():
    g = generated_code()
    g.set_rep("dude", 5)
    assert 5 == g.get_rep("dude")
Пример #11
0
def test_get_rep_null():
    g = generated_code()
    assert None is g.get_rep("hi")
Пример #12
0
def test_nothing():
    g = generated_code()
    assert 0 == len(g.class_declaration_code())
    assert 2 == len(dummy_emitter().process(g.emit_query_code).Lines)