aboutsummaryrefslogtreecommitdiff
path: root/scripts/theme-studio/test-columns.mjs
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-06-15 19:19:38 -0500
committerCraig Jennings <c@cjennings.net>2026-06-15 19:19:38 -0500
commit7e7b871fe4f8daff724c3df37feb5572464532c1 (patch)
tree3dcfb0e760a22b460bc1188a9b6d7a6b5433a5a3 /scripts/theme-studio/test-columns.mjs
parent5ab506d9b65a0d043c08690b86976b1f97889eaf (diff)
downloaddotemacs-7e7b871fe4f8daff724c3df37feb5572464532c1.tar.gz
dotemacs-7e7b871fe4f8daff724c3df37feb5572464532c1.zip
feat(theme-studio): flag unused palette tiles and columns
I added usedPaletteHexes, a reverse lookup over the syntax, ui, and package assignments (plus the ground endpoints) that resolves each reference to a hex. renderPalette outlines a tile whose color is referenced nowhere and outlines a whole column when none of its colors are used, so dead colors stand out for pruning before a theme ships. The check is biased safe: an unresolvable reference marks nothing, so a color that is actually used is never flagged. Node tests cover the lookup. A #unusedtest gate covers the tile and column flags.
Diffstat (limited to 'scripts/theme-studio/test-columns.mjs')
-rw-r--r--scripts/theme-studio/test-columns.mjs17
1 files changed, 16 insertions, 1 deletions
diff --git a/scripts/theme-studio/test-columns.mjs b/scripts/theme-studio/test-columns.mjs
index c7e0e5160..ba949cea4 100644
--- a/scripts/theme-studio/test-columns.mjs
+++ b/scripts/theme-studio/test-columns.mjs
@@ -5,7 +5,7 @@
import { test } from 'node:test';
import assert from 'node:assert/strict';
-import { columnsFromPalette, regenColumn, groundRoleOfEntry, rankByLightness, stepRepointPlan, sortColumns } from './app-core.js';
+import { columnsFromPalette, usedPaletteHexes, regenColumn, groundRoleOfEntry, rankByLightness, stepRepointPlan, sortColumns } from './app-core.js';
const columnOf = (columns, name) => columns.find(f => f.members.some(m => m.name === name));
@@ -222,3 +222,18 @@ test('regenColumn: Boundary - a near-black bg yields no duplicate pure-black til
test('regenColumn: Boundary - no ground falls back to the black/white span', () => {
assert.equal(regenColumn('#67809c', 2).members.length, 5);
});
+
+// --- usedPaletteHexes (unused-tile flagging) --------------------------------
+test('usedPaletteHexes: Normal - records ground, syntax-by-hex, ui-by-name, pkg box color', () => {
+ const palette = [['#101010','bg','ground'],['#f0f0f0','fg','ground'],['#67809c','blue','blue'],['#aa3344','red','red'],['#123456','teal','teal']];
+ const used = usedPaletteHexes(palette, { kw: { fg: '#67809c' } }, { region: { bg: 'red' } }, { magit: { m: { box: { color: '#aa3344' } } } }, { bg: '#101010', fg: '#f0f0f0' });
+ assert.ok(used.has('#101010') && used.has('#f0f0f0'), 'ground endpoints are always used');
+ assert.ok(used.has('#67809c'), 'a syntax hex reference is recorded');
+ assert.ok(used.has('#aa3344'), 'a ui name reference resolves to its hex');
+ assert.ok(!used.has('#123456'), 'an unreferenced color is absent');
+});
+
+test('usedPaletteHexes: Boundary - empty maps leave only the ground endpoints', () => {
+ const used = usedPaletteHexes([['#101010','bg','ground'],['#f0f0f0','fg','ground']], {}, {}, {}, { bg: '#101010', fg: '#f0f0f0' });
+ assert.deepEqual([...used].sort(), ['#101010', '#f0f0f0']);
+});