Example #1
0
def test_types_arrays():
    i = Integer()
    dims = [9, 10]
    a = Array(i, dims)
    assert a == a
    assert not (a != a)
    assert a == Array(i, dims)
    assert a == Array(Integer(), [9, 10])
    assert a != Array(Integer(), [9, 11])
    assert a != Array(Real(), [9, 10])
Example #2
0
def test_types():
    r = Real()
    i = Integer()
    assert r == r
    assert not (r != r)
    assert r == Real()

    assert i == i
    assert not (i != i)
    assert i == Integer()

    assert i != r
    assert not (i == r)
    assert not (i == Real())
    assert i != Real()

    assert r != i
    assert not (r == i)
    assert not (r == Integer())
    assert r != Integer()
Example #3
0
def test_type1():
    source = """\
module test
implicit none
contains

    subroutine sub1(a, b)
    integer, intent(in) :: a, b
    a = b
    end subroutine

end module
"""
    tree = src_to_ast(source)
    symbol_table = create_symbol_table(tree)
    annotate_tree(tree, symbol_table)
    assert tree.contains[0].body[0]._type == Integer()
Example #4
0
def test_variables1():
    source = """\
module test
implicit none
contains

    subroutine sub1(a, b)
    integer, intent(in) :: a
    real, intent(out) :: b
    b = a + 1
    end subroutine

end module
"""
    tree = src_to_ast(source)
    global_scope = create_symbol_table(tree)
    assert not global_scope.resolve("a", False)
    sym = tree.contains[0]._scope.resolve("a")
    assert sym["type"] == Integer()
    assert sym["name"] == "a"
    sym = tree.contains[0]._scope.resolve("b")
    assert sym["type"] == Real()
    assert sym["name"] == "b"
    assert not tree.contains[0]._scope.resolve("c", False)