예제 #1
0
def test_global_or_local():
    a = scope.Scope()
    b = scope.Scope(a)
    c = scope.Scope(b)
    assert a.is_global()
    assert not b.is_global()
    assert not c.is_global()
예제 #2
0
def test_shadowing():
    outer = scope.Scope()
    outer.add_global_declaration(new_token("x"), scope.TupleType(1), None)
    inner = scope.Scope(outer)
    inner.add_global_declaration(new_token("x"), scope.TupleType(2), None)
    assert outer.lookup(new_token("x")) == (scope.TupleType(1), None)
    assert inner.lookup(new_token("x")) == (scope.TupleType(2), None)
예제 #3
0
def test_redeclared_error():
    s = scope.Scope()
    s.add_global_declaration(new_token("x"), scope.TupleType(1), None)
    with pytest.raises(scope.ScopeError):
        s.add_global_declaration(new_token("x"), scope.TupleType(1),
                                 None)  # Same type and slot.
    with pytest.raises(scope.ScopeError):
        s.add_global_declaration(
            new_token("x"), scope.TupleType(2),
            None)  # Different type and slot.  Still an error.
예제 #4
0
def test_undeclared_error():
    s = scope.Scope()
    with pytest.raises(scope.ScopeError):
        s.lookup(new_token("x"))
예제 #5
0
def test_global_tuple_lookup():
    s = scope.Scope()
    s.add_global_declaration(new_token("x"), scope.TupleType(1), "x_slot")
    s.add_global_declaration(new_token("y"), scope.TupleType(2), "y_slot")
    assert s.lookup(new_token("x")) == (scope.TupleType(1), "x_slot")
    assert s.lookup(new_token("y")) == (scope.TupleType(2), "y_slot")