예제 #1
0
def test_parameterization_propagation():
    symbols = get_symbols(SOURCE_FULL)
    generic_type = symbols[Identifier('Person')][Identifier(
        'favorite_numbers')].type
    parametrized_type = symbols[generic_type]
    assert parametrized_type.name == GenericIdentifier(
        Identifier('Pair'), (Identifier('number'), ))
예제 #2
0
def test_person_member_symbol_description():
    symbols = get_symbols(SOURCE_PERSON)
    person = symbol_map_sanity(symbols, 'Person',
                               ('name', 'age', 'location', 'walk_to',
                                'say_hello', 'shout', 'favorite_numbers'))

    validate_member(person[Identifier('name')], Identifier('text'), 0)
    validate_member(person[Identifier('location')], Identifier('Location'), 2)
예제 #3
0
def test_method_symbol_description():
    symbols = get_symbols(SOURCE_FULL)
    person, location, pair = symbols[Identifier('Person')], symbols[Identifier(
        'Location')], symbols[Identifier('Pair')]

    validate_method(person[Identifier('walk_to')], None, ['Location'], 1)
    validate_method(location[Identifier('distance')], 'number',
                    ['Location'] * 2, 1, True)
    validate_method(pair[Identifier('set_values')], 'T', ['T'] * 2, 1)
예제 #4
0
def test_descendant_retrieval():
    symbols = get_symbols(SOURCE_INHERITANCE)

    def get_names(name, *args):
        return {
            str(x.name)
            for x in symbols.descendants(symbols[Identifier(name)], *args)
        }

    assert get_names('A', False) == {'B1', 'B2', 'B3', 'C1', 'C2', 'C3'}
    assert get_names('B1') == {'B1', 'C1', 'C2'}
예제 #5
0
def get_parametrized():
    pair = get_symbols(SOURCE_PAIR)[Identifier('Pair')]

    return pair.parameterize({Identifier('T'): Identifier('number')})
예제 #6
0
thing Container2Child extends Container2
    

thing A
    does overloaded with Container1 container
    does overloaded with Container2 container
    does overloaded with Container2Child container
    does overloaded with Container1 c1, Container2 c2
    does overloaded with Container1 c1, Container2Child c2

'''

# TODO: verify no cast to base type!
# TODO: we probably don't want implicit casts to text

SYMBOLS = get_symbols(SOURCE_OVERLOADING)
CONTEXT = CompilationContext(SYMBOLS)
BASE = SYMBOLS.resolve(NamedAccess.auto('A.overloaded'))


def get_selection(*target_types):
    selector = BASE.element.selector(CONTEXT)

    for target_type in target_types:
        selector.constraint(Reference(Identifier(target_type)))

    return selector.disambiguate(None)


def verify_selection(target_type, expected_index, expected_match):
    target = get_selection(*target_type)
예제 #7
0
def test_pair_symbol_description():
    symbols = get_symbols(SOURCE_PAIR)
    pair = symbol_map_sanity(symbols, 'Pair',
                             ('lhs', 'rhs', 'parts', 'nested'))

    assert pair.generics == [Identifier('T')]
예제 #8
0
def test_location_member_symbol_description():
    symbols = get_symbols(SOURCE_LOCATION)
    symbol_map_sanity(symbols, 'Location', ('x', 'y'))
예제 #9
0
def test_mapper_existence():
    symbols = get_symbols(SOURCE_FULL)
    assert all(
        Identifier(x) in symbols for x in ('Location', 'Pair', 'Person'))