Exemplo n.º 1
0
def test_symbol_str_string():
    sym = Symbol('foo', StringType.instance())
    assert str(sym) == "Symbol('foo', string)"
Exemplo n.º 2
0
 def string(self, tree):
     """
     Compiles a string tree.
     """
     assert tree.data == 'string'
     return base_symbol(StringType.instance())
Exemplo n.º 3
0
 def throw_statement(self, tree, scope):
     tree.expect(tree.entity is not None, 'throw_only_string')
     sym = self.resolver.entity(tree.entity)
     tree.entity.expect(sym.type() == StringType.instance(),
                        'throw_only_string')
Exemplo n.º 4
0
def test_symbol_str_ro_string():
    sym = Symbol('foo',
                 StringType.instance(),
                 storage_class=StorageClass.read())
    assert str(sym) == "Symbol('foo', string, ro)"
Exemplo n.º 5
0
def test_symbol_pretty_string():
    sym = Symbol('foo', StringType.instance())
    assert sym.pretty() == 'string'
Exemplo n.º 6
0
    single_fn = singleton(test_fn)
    assert single_fn() == 1
    assert single_fn() == 1
    assert c == 1


@mark.parametrize('type_,expected', [
    (BooleanType.instance(), 'boolean'),
    (IntType.instance(), 'int'),
    (FloatType.instance(), 'float'),
    (NoneType.instance(), 'none'),
    (AnyType.instance(), 'any'),
    (RegExpType.instance(), 'regexp'),
    (ListType(AnyType.instance()), 'List[any]'),
    (MapType(IntType.instance(), StringType.instance()), 'Map[int,string]'),
])
def test_boolean_str(type_, expected):
    assert str(type_) == expected


def test_none_eq():
    assert NoneType.instance() == NoneType.instance()
    assert NoneType.instance() != IntType.instance()
    assert NoneType.instance() != AnyType.instance()


def test_none_assign():
    assert not NoneType.instance().can_be_assigned(IntType.instance())
    assert not NoneType.instance().can_be_assigned(AnyType.instance())
Exemplo n.º 7
0
    assert single_fn() == 1
    assert c == 1


@mark.parametrize(
    "type_,expected",
    [
        (BooleanType.instance(), "boolean"),
        (IntType.instance(), "int"),
        (FloatType.instance(), "float"),
        (NoneType.instance(), "none"),
        (AnyType.instance(), "any"),
        (RegExpType.instance(), "regexp"),
        (ListType(AnyType.instance()), "List[any]"),
        (
            MapType(IntType.instance(), StringType.instance()),
            "Map[int,string]",
        ),
        (NullType.instance(), "null"),
    ],
)
def test_boolean_str(type_, expected):
    assert str(type_) == expected


def test_none_eq():
    assert NoneType.instance() == NoneType.instance()
    assert NoneType.instance() != IntType.instance()
    assert NoneType.instance() != AnyType.instance()

Exemplo n.º 8
0

def test_parse_end_error():
    with raises(AssertionError):
        parse_type_inner("foo[bar")


@mark.parametrize(
    "text,expected",
    [
        ("any", AnyType.instance()),
        ("boolean", BooleanType.instance()),
        ("float", FloatType.instance()),
        ("int", IntType.instance()),
        ("none", NoneType.instance()),
        ("string", StringType.instance()),
        ("time", TimeType.instance()),
        ("A", TypeSymbol("A")),
    ],
)
def test_parse_type_base(text, expected):
    t = parse_type(text)
    assert str(t) == str(expected)


@mark.parametrize(
    "text,expected_type,expected_symbols",
    [
        ("List[int]", ListGenericType, [IntType.instance()]),
        ("List[float]", ListGenericType, [FloatType.instance()]),
        (