def test_get_rep_works_and_doesnt(): g = generated_code() s1 = statement.iftest("true") g.set_rep("dude", 5) assert 5 is g.get_rep("dude") g.pop_scope() assert None is g.get_rep("dude")
def __init__(self): r''' Initialize the visitor. ''' # Tracks the output of the code. self._gc = generated_code() self._arg_stack = argument_stack() self._result = None
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)
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)
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 is g.get_rep("dude") g.pop_scope() assert 5 is g.get_rep("dude")
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)
def test_deepest_scope_equal(): g = generated_code() s1 = statement.iftest("true") s2 = 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)
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
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 is g.get_rep("dude")
def test_get_rep_when_set(): g = generated_code() g.set_rep("dude", 5) assert 5 is g.get_rep("dude")
def test_get_rep_null(): g = generated_code() assert None is g.get_rep("hi")
def test_nothing(): g = generated_code() assert 0 == len(g.class_declaration_code()) assert 2 == len(dummy_emitter().process(g.emit_query_code).Lines)