예제 #1
0
파일: Scope.py 프로젝트: shaz13/storyscript
def test_scope_pretty_none(patch):
    scope = Scope()
    patch.object(Symbols, 'pretty', return_value='.symbols.')
    assert scope.pretty() == """Parent: None
Symbols:
.symbols."""
    Symbols.pretty.assert_called_with(indent='\t')
예제 #2
0
def test_scope_pretty_none(patch):
    scope = Scope()
    patch.object(Symbols, "pretty", return_value=".symbols.")
    assert (scope.pretty() == """Parent: None
Symbols:
.symbols.""")
    Symbols.pretty.assert_called_with(indent="\t")
예제 #3
0
    def build_current_scope(self, context):
        """
        Tries to build the current scope and extract its symbol table.
        """
        current_block = context.current_block(until_cursor_line=True)
        if len(current_block) == 0:
            return Scope()

        text = ""
        for block in context.lines_until_current_block():
            text += "\n".join(block)

        current_block_text = "\n".join(current_block[:-1])
        key = text + current_block_text

        if key in self.scope_cache:
            return self.scope_cache[key]
        else:
            scope = Scope()
            compiled_scope = self._build_current_scope(current_block_text,
                                                       current_block)
            if compiled_scope is not None:
                for symbol in compiled_scope.symbols():
                    if symbol.name() != CACHE_DUMMY_VAR:
                        scope.insert(symbol)
            self.scope_cache[text] = scope
            return scope
예제 #4
0
def test_scope_pretty(patch, magic):
    root_scope = ".parent."
    scope = Scope(parent=root_scope)
    patch.object(Symbols, "pretty", return_value=".symbols.")
    assert (scope.pretty() == """Parent: .parent.
Symbols:
.symbols.""")
    Symbols.pretty.assert_called_with(indent="\t")
예제 #5
0
파일: Scope.py 프로젝트: shaz13/storyscript
def test_scope_pretty(patch, magic):
    root_scope = '.parent.'
    scope = Scope(parent=root_scope)
    patch.object(Symbols, 'pretty', return_value='.symbols.')
    assert scope.pretty() == """Parent: .parent.
Symbols:
.symbols."""
    Symbols.pretty.assert_called_with(indent='\t')
예제 #6
0
파일: Scope.py 프로젝트: shaz13/storyscript
def test_scope_scopes_multiple():
    s1 = Scope()
    s2 = Scope(parent=s1)
    s3 = Scope(parent=s2)
    r = list(s3.scopes())
    assert len(r) == 3
    assert r[0] is s3
    assert r[1] is s2
    assert r[2] is s1
예제 #7
0
def test_scope_str_with_symbols(patch, magic):
    scope = Scope()
    s1 = magic()
    s1.name.return_value = "s1"
    s2 = magic()
    s2.name.return_value = "s2"
    patch.object(Scope, "symbols", return_value=[s1, s2])
    assert str(scope) == "Scope(s1,s2)"
예제 #8
0
파일: Api.py 프로젝트: wilzbach/storyscript
def test_api_loads_with_scope():
    """
    Ensures Api.load functions return errors
    """
    scope = Scope.root()
    symbol = Symbol("a", IntType.instance())
    scope.insert(symbol)
    story = Api.loads("foo = a", backend="semantic", scope=scope)
    story.check_success()
예제 #9
0
 def aggregate_scope_blocks(self, context):
     """
     Iterates over all non-current blocks and aggregates
     their symbol table into a combined symbol table.
     """
     scope = Scope.root()
     for block in self.other_blocks_compiled(context):
         scope.insert_scope(block.root_scope)
     return scope
예제 #10
0
def test_complete(magic):
    doc = Document(uri=".text.", text="a = $")
    pos = Position(0, 0)
    context = CompletionContext(ws=magic(), doc=doc, pos=pos)
    global_ = magic()
    global_.global_scope = Scope.root()
    current = CurrentScopeCache(global_=global_, hub=hub)
    current.update(context)
    assert [x.symbol.name() for x in current.complete("a")] == ["app"]
    assert [x.symbol.name() for x in current.complete("b")] == []
예제 #11
0
def test_complete(magic):
    doc = Document(uri=".text.", text="function foo\n  a = 1\n\nb = 0")
    pos = Position(3, 0)
    context = CompletionContext(ws=magic(), doc=doc, pos=pos)
    global_ = magic()
    global_.global_scope = Scope.root()
    glob = GlobalScopeCache(story_hub=hub)
    glob.update(context)
    assert [x.function.name() for x in glob.complete("f")] == ["foo"]
    assert [x.function.name() for x in glob.complete("b")] == []
예제 #12
0
def test_caching(magic):
    doc = Document(uri=".text.", text="function foo\n  a = 1\n\nb = 0")
    pos = Position(3, 0)
    context = CompletionContext(ws=magic(), doc=doc, pos=pos)
    global_ = magic()
    global_.global_scope = Scope.root()
    glob = GlobalScopeCache(story_hub=hub)
    glob.update(context)
    fns = [*glob.function_table.functions.keys()]
    assert fns == ["foo"]
예제 #13
0
def test_caching(magic):
    doc = Document(uri=".text.", text="a = $")
    pos = Position(0, 0)
    context = CompletionContext(ws=magic(), doc=doc, pos=pos)
    global_ = magic()
    global_.global_scope = Scope.root()
    current = CurrentScopeCache(global_=global_, hub=hub)
    current.update(context)
    symbols = [s.name() for s in current.current_scope.symbols()]
    assert symbols == ["app"]

    # test caching
    current.update(context)
    symbols = [s.name() for s in current.current_scope.symbols()]
    assert symbols == ["app"]
예제 #14
0
def test_scope_str(patch):
    scope = Scope()
    assert str(scope) == "Scope()"
예제 #15
0
def test_scope_str_root(patch):
    scope = Scope.root()
    assert str(scope) == "Scope(app)"
예제 #16
0
파일: Scope.py 프로젝트: shaz13/storyscript
def test_scope_scopes_single():
    s = Scope()
    r = list(s.scopes())
    assert len(r) == 1
    assert r[0] is s
예제 #17
0
파일: Scope.py 프로젝트: shaz13/storyscript
def test_scope_resolve_sucess(patch, magic):
    patch.object(Symbols, 'resolve', return_value=True)
    patch.object(Scope, 'scopes', return_value=[Scope(), Scope()])
    scope = Scope()
    assert scope.resolve('.p.') == Symbols.resolve()
    Symbols.resolve.call_count == 1
예제 #18
0
파일: Scope.py 프로젝트: shaz13/storyscript
def test_scope_resolve_fail(patch, magic):
    patch.object(Symbols, 'resolve', return_value=False)
    patch.object(Scope, 'scopes', return_value=[Scope(), Scope()])
    scope = Scope()
    assert scope.resolve('.p.') is None
    Symbols.resolve.call_count == 2
예제 #19
0
def test_scope_resolve_fail(patch, magic):
    patch.object(Symbols, "resolve", return_value=False)
    patch.object(Scope, "scopes", return_value=[Scope(), Scope()])
    scope = Scope()
    assert scope.resolve(".p.") is None
    Symbols.resolve.call_count == 2
예제 #20
0
def test_scope_resolve_sucess(patch, magic):
    patch.object(Symbols, "resolve", return_value=True)
    patch.object(Scope, "scopes", return_value=[Scope(), Scope()])
    scope = Scope()
    assert scope.resolve(".p.") == Symbols.resolve()
    Symbols.resolve.call_count == 1