예제 #1
0
def test_snippet_context_subcontext():
    ctx = CodeSnippetContext()
    ctx.add("foo", "dummy")
    sub = ctx.subcontext("foo")
    sub.add("bar", "dummy")
    ctx.add("baz", "dummy")
    assert "foo" in ctx
    assert "bar" in ctx
    assert ctx.top_level_snippets() == {"foo", "baz"}
    assert ctx.natural_order() == ["baz", "bar", "foo"]
예제 #2
0
 def ts_repr(self, ctx: CodeSnippetContext):
     if self.name:
         interface_name = to_pascal(self.name) if self.translate_name else self.name
         if interface_name not in ctx:
             subctx = ctx.subcontext(interface_name)
             code = self._render_ts_interface(interface_name, subctx)
             ctx.add(interface_name, code)
         return interface_name
     else:
         return self._render_ts_interface(None, ctx)