diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-24 05:39:06 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-24 05:39:06 -0400 |
| commit | a98dc772708f33e90aaeb4572a13bf22d065a022 (patch) | |
| tree | e8c3682b2c82b5840999b3ad49a2ec947c9a38dd /scripts/theme-studio/test_generate.py | |
| parent | 11767454d306518997d06207f9fe792f7482ac50 (diff) | |
| download | dotemacs-a98dc772708f33e90aaeb4572a13bf22d065a022.tar.gz dotemacs-a98dc772708f33e90aaeb4572a13bf22d065a022.zip | |
feat(theme-studio): capture the nerd-icons filetype legend (phase 1)
Add build-nerd-icons-legend.el, which resolves the curated v1 legend rows (glyph + owner color face per filetype) from the live nerd-icons alists and dumps them to nerd-icons-legend.json, a committed artifact like package-inventory.json. generate.py gains load_nerd_icons_legend, which validates the artifact and returns None — with a warning — when it is absent, malformed, empty, or missing a field, so the page can fall back to the generic nerd-icons app rather than error. Data only; the bespoke preview that renders it lands next.
Claude-Session: https://claude.ai/code/session_01BqrdWUo9GcznYX2pZr76gZ
Diffstat (limited to 'scripts/theme-studio/test_generate.py')
| -rw-r--r-- | scripts/theme-studio/test_generate.py | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/theme-studio/test_generate.py b/scripts/theme-studio/test_generate.py index 974fca68a..7ff207e43 100644 --- a/scripts/theme-studio/test_generate.py +++ b/scripts/theme-studio/test_generate.py @@ -597,5 +597,50 @@ class GeneratedDefaults(unittest.TestCase): self.assertEqual(generate.SYNTAX["str"]["slant"], "italic") +class NerdIconsLegend(unittest.TestCase): + """The committed nerd-icons-legend.json artifact and the loader fallback.""" + + def _write(self, content): + path = os.path.join(tempfile.mkdtemp(), "nerd-icons-legend.json") + with open(path, "w") as out: + out.write(content) + return path + + def test_committed_artifact_has_valid_rows(self): + rows = generate.load_nerd_icons_legend() + self.assertIsNotNone(rows, "committed nerd-icons-legend.json should load") + self.assertTrue(rows) + for row in rows: + for field in generate.NERD_ICONS_LEGEND_FIELDS: + self.assertIsInstance(row.get(field), str) + self.assertTrue(row[field]) + self.assertTrue(row["face"].startswith("nerd-icons-")) + self.assertIn(row["category"], ("extension", "dir", "command", "buffer")) + + def test_absent_artifact_falls_back_to_none(self): + with redirect_stdout(io.StringIO()) as out: + self.assertIsNone(generate.load_nerd_icons_legend("/no/such/legend.json")) + self.assertIn("absent", out.getvalue()) + + def test_malformed_artifact_falls_back_to_none(self): + path = self._write("{not json") + with redirect_stdout(io.StringIO()) as out: + self.assertIsNone(generate.load_nerd_icons_legend(path)) + self.assertIn("malformed", out.getvalue()) + + def test_empty_artifact_falls_back_to_none(self): + path = self._write("[]") + with redirect_stdout(io.StringIO()) as out: + self.assertIsNone(generate.load_nerd_icons_legend(path)) + self.assertIn("empty", out.getvalue()) + + def test_row_missing_a_field_falls_back_to_none(self): + path = self._write(json.dumps([{"key": "ext:el", "label": "init.el", + "face": "nerd-icons-purple", "category": "extension"}])) + with redirect_stdout(io.StringIO()) as out: + self.assertIsNone(generate.load_nerd_icons_legend(path)) + self.assertIn("invalid", out.getvalue()) + + if __name__ == "__main__": unittest.main() |
