diff --git a/CHANGES b/CHANGES index ab16d0e2..a98244d3 100644 --- a/CHANGES +++ b/CHANGES @@ -62,6 +62,13 @@ Both errors exit with status 2. `vt_snapshot`. The fixture is also available when the project explicitly loads the Syrupy and libvt plugin modules in `conftest.py`. +### Documentation + +#### Assert effective colors alongside screen goldens (#190) + +The {doc}`/topics/testing` guide shows how to resolve a cell's color +against the palette in its committed snapshot. + ### Development #### Design review and issue skills (#155) diff --git a/docs/topics/testing.md b/docs/topics/testing.md index 24217d26..05bb14d1 100644 --- a/docs/topics/testing.md +++ b/docs/topics/testing.md @@ -90,6 +90,37 @@ styles: r0[6..10]: fg=#ff8c00 ``` +### Assert a palette change + +A boxed golden records the cell's color token, such as `fg=red`. To test +a theme change, read the cell and its palette from the same committed +{class}`~libvt.terminal.Snapshot`. {meth}`~libvt.style.Appearance.resolve_rgb` +returns the color that the palette assigns to that token. + +```python +>>> from libvt import Snapshot, Terminal +>>> from libvt.testing import serialize_vt_snapshot +>>> def foreground(frame: Snapshot) -> tuple[int, int, int]: +... return frame.appearance.resolve_rgb( +... frame[0, 0].style.fg, default_rgb=frame.appearance.fg_rgb +... ) +>>> term = Terminal(rows=1, cols=5) +>>> term.feed(b"\x1b[31mBOARD") +>>> original = term.committed +>>> term.feed(b"\x1b]4;1;#16b3cd\x07") +>>> themed = term.committed +>>> serialize_vt_snapshot(themed) == serialize_vt_snapshot(original) +True +>>> foreground(original), foreground(themed) +((205, 0, 0), (22, 179, 205)) +>>> term.feed(b"\x1b]104;1\x07") +>>> foreground(term.committed) == foreground(original) +True +``` + +For a default-color change, assert `frame.appearance.fg_rgb` or +`frame.appearance.bg_rgb` directly. + ### Scrubbing dynamic values without breaking box borders Naive string replacement shifts right-hand `│` borders whenever a PID, port, or