def test_as_root_as_single_column():
    q = query_ast_visitor()
    node = ast.parse('1/1')
    value_obj = crep.cpp_value('i', gc_scope_top_level(), ctyp.terminal('int'))
    sequence = crep.cpp_sequence(
        value_obj,
        crep.cpp_value('i', gc_scope_top_level(), ctyp.terminal('int')),
        gc_scope_top_level())
    node.rep = sequence  # type: ignore
    as_root = q.get_as_ROOT(node)

    assert isinstance(as_root, rh.cpp_ttree_rep)
def test_as_root_as_dict():
    q = query_ast_visitor()
    node = ast.parse('1/1')
    dict_obj = crep.cpp_dict(
        {
            ast.Constant(value='hi'):
            crep.cpp_value('i', gc_scope_top_level(), ctyp.terminal('int'))
        }, gc_scope_top_level())
    sequence = crep.cpp_sequence(
        dict_obj,  # type: ignore
        crep.cpp_value('i', gc_scope_top_level(), ctyp.terminal('int')),
        gc_scope_top_level())
    node.rep = sequence  # type: ignore
    as_root = q.get_as_ROOT(node)

    assert isinstance(as_root, rh.cpp_ttree_rep)
def test_as_root_rep_already_set():
    q = query_ast_visitor()
    node = ast.parse('1/1')
    v = rh.cpp_ttree_rep('junk', 'dude', gc_scope_top_level())
    node.rep = v  # type: ignore

    assert v is q.get_as_ROOT(node)
Example #4
0
def test_sequence_type():
    tc = gc_scope_top_level()
    s_value = crep.cpp_value('0.0', tc, ctyp.terminal('int', False))
    i_value = crep.cpp_value('1.0', tc, ctyp.terminal('object', False))

    seq = crep.cpp_sequence(s_value, i_value, tc)

    assert seq.sequence_value().cpp_type().type == 'int'
Example #5
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)
Example #6
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)
Example #7
0
def test_variable_type_update():
    tc = gc_scope_top_level()
    expr = "a"
    ctype = ctyp.terminal('int', False)

    v = crep.cpp_variable(expr, tc, ctype)
    v.update_type(ctyp.terminal('float', False))

    assert v.cpp_type().type == 'float'
Example #8
0
def test_variable_type__with_initial_update():
    tc = gc_scope_top_level()
    expr = "a"
    c_type = ctyp.terminal('int', False)
    c_init = crep.cpp_value('0.0', tc, ctyp.terminal('int', False))

    v = crep.cpp_variable(expr, tc, c_type, c_init)
    v.update_type(ctyp.terminal('float', False))

    assert v.cpp_type().type == 'float'
    assert v.initial_value().cpp_type().type == 'float'
def test_subscript():
    q = query_ast_visitor()
    our_a = ast.Name(id='a')
    our_a.rep = crep.cpp_collection('jets', gc_scope_top_level(),
                                    ctyp.collection('int'))  # type: ignore
    node = ast_parse_with_replacement('a[10]', {
        'a': our_a
    }).body[0].value  # type: ignore
    as_root = q.get_rep(node)

    assert isinstance(as_root, crep.cpp_value)
    assert as_root.cpp_type() == 'int'
    assert as_root.as_cpp() == 'jets.at(10)'
Example #10
0
def test_top_level_starts_with_top_level():
    top1 = gc_scope_top_level()
    top2 = gc_scope_top_level()

    assert top1.starts_with(top2)