import dataclasses

import typtyp
from tests.common import HairColor


@dataclasses.dataclass
class Head:
    size: int
    hair_color: HairColor | None


@dataclasses.dataclass
class Person:
    head: Head
    name: str


def test_dataclass(snapshot):
    w = typtyp.World()
    # doc=None to avoid the silly docstrings generated by dataclasses
    w.add_many({"Person": Person, "Head": Head}, doc=None)
    w.add(HairColor)
    assert w.get_typescript() == snapshot
