Skip to content

Commit cfee583

Browse files
vunguyentuanclaude
andcommitted
Add tests for OKLAB and OKLCH color format support
Adds comprehensive test coverage to verify the extension properly detects and handles modern CSS color formats (oklab/oklch) including alpha channel support. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 0ccd52d commit cfee583

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
:root {
2+
/* OKLAB colors */
3+
--oklab-red: oklab(0.628 0.225 0.126);
4+
--oklab-green: oklab(0.519 -0.14 0.108);
5+
--oklab-blue: oklab(0.452 -0.032 -0.312);
6+
--oklab-with-alpha: oklab(0.628 0.225 0.126 / 0.5);
7+
8+
/* OKLCH colors */
9+
--oklch-red: oklch(0.628 0.258 29.2);
10+
--oklch-green: oklch(0.519 0.177 142.5);
11+
--oklch-blue: oklch(0.452 0.313 264.1);
12+
--oklch-with-alpha: oklch(0.628 0.258 29.2 / 0.8);
13+
14+
/* Non-color values for comparison */
15+
--main-bg-color: brown;
16+
--h1: 26px;
17+
--h2: 22px;
18+
--h3: 18px;
19+
--text-base: 16px;
20+
--carousel-bg: var(--main-bg-color);
21+
}
22+
23+
.oklab-example {
24+
color: var(--oklab-red);
25+
background-color: var(--oklab-green);
26+
border-color: var(--oklab-blue);
27+
}
28+
29+
.oklch-example {
30+
color: var(--oklch-red);
31+
background-color: var(--oklch-green);
32+
border-color: var(--oklch-blue);
33+
}

packages/css-variables-language-server/src/tests/unit-tests/CSSVariableManager.test.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,53 @@ describe('CSS Variable Manager', () => {
5959
expect(allVars.get('--slate-50').symbol.value).toEqual('#f8fafc');
6060
});
6161
});
62+
63+
test('can parse and detect OKLAB and OKLCH colors', async () => {
64+
const cssManager = new CSSVariableManager();
65+
66+
await cssManager.parseAndSyncVariables([
67+
path.join(__dirname, '../fixtures/oklab-oklch-colors'),
68+
]);
69+
70+
const allVars = cssManager.getAll();
71+
72+
// Test OKLAB colors
73+
const oklabRed = allVars.get('--oklab-red');
74+
expect(oklabRed.symbol.value).toEqual('oklab(0.628 0.225 0.126)');
75+
expect(oklabRed.color).toBeDefined();
76+
77+
const oklabGreen = allVars.get('--oklab-green');
78+
expect(oklabGreen.symbol.value).toEqual('oklab(0.519 -0.14 0.108)');
79+
expect(oklabGreen.color).toBeDefined();
80+
81+
const oklabBlue = allVars.get('--oklab-blue');
82+
expect(oklabBlue.symbol.value).toEqual('oklab(0.452 -0.032 -0.312)');
83+
expect(oklabBlue.color).toBeDefined();
84+
85+
const oklabWithAlpha = allVars.get('--oklab-with-alpha');
86+
expect(oklabWithAlpha.symbol.value).toEqual('oklab(0.628 0.225 0.126 / 0.5)');
87+
expect(oklabWithAlpha.color).toBeDefined();
88+
89+
// Test OKLCH colors
90+
const oklchRed = allVars.get('--oklch-red');
91+
expect(oklchRed.symbol.value).toEqual('oklch(0.628 0.258 29.2)');
92+
expect(oklchRed.color).toBeDefined();
93+
94+
const oklchGreen = allVars.get('--oklch-green');
95+
expect(oklchGreen.symbol.value).toEqual('oklch(0.519 0.177 142.5)');
96+
expect(oklchGreen.color).toBeDefined();
97+
98+
const oklchBlue = allVars.get('--oklch-blue');
99+
expect(oklchBlue.symbol.value).toEqual('oklch(0.452 0.313 264.1)');
100+
expect(oklchBlue.color).toBeDefined();
101+
102+
const oklchWithAlpha = allVars.get('--oklch-with-alpha');
103+
expect(oklchWithAlpha.symbol.value).toEqual('oklch(0.628 0.258 29.2 / 0.8)');
104+
expect(oklchWithAlpha.color).toBeDefined();
105+
106+
// Verify non-color variables don't have color property
107+
const h1Var = allVars.get('--h1');
108+
expect(h1Var.symbol.value).toEqual('26px');
109+
expect(h1Var.color).toBeUndefined();
110+
});
62111
});

0 commit comments

Comments
 (0)