Esempio n. 1
0
    def test_deep_nested_tree_ts_repr(self):
        @dataclass
        class Baz:
            nano: int

        @dataclass
        class Bar:
            micro: list[Baz]

        @dataclass
        class Foo:
            my_field: Bar

        tree = Object.match(Foo)
        ctx = CodeSnippetContext()
        assert tree.ts_repr(ctx) == "Foo"

        assert "Foo" in ctx
        assert ctx.get_snippet("Foo") == """export interface Foo {
  myField: Bar;
}"""
        assert "Bar" in ctx
        assert ctx.get_snippet("Bar") == """export interface Bar {
  micro: Baz[];
}"""

        assert "Baz" in ctx
        assert ctx.get_snippet("Baz") == """export interface Baz {
  nano: number;
}"""

        assert ctx.topological_dependencies("Foo") == ["Baz", "Bar", "Foo"]
Esempio n. 2
0
    def test_object_ts_repr(self):
        ctx = CodeSnippetContext()

        @dataclass()
        class Foo:
            my_field: int
            other_field: str

        tree = Object.match(Foo)
        assert tree.ts_repr(ctx) == "Foo"
        assert ctx.top_level_snippets() == {"Foo"}
        assert ctx.get_snippet("Foo") == """export interface Foo {