Something went wrong. Try again.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536import { test } from 'node:test';import assert from 'node:assert/strict';import { parseCSS, serializeCSS, parseStyleAttr, serializeStyleAttr, fontFaces } from '../web/lib/cssparse.js';
test('parses rules, comments, at-rules and nesting', () => { const s = parseCSS('/* hi */ .a, .b { fill: red; stroke: blue !important } @font-face{font-family:"X";src:url(data:font/woff2;base64,AA)} @media (min-width:1px){ g{opacity:.5} } @import url(x.css);'); assert.deepEqual(s.rules.map(r => r.type), ['comment', 'rule', 'at', 'at', 'at']); assert.equal(s.rules[1].selector, '.a, .b'); assert.deepEqual(s.rules[1].decls, [{ name: 'fill', value: 'red', important: false }, { name: 'stroke', value: 'blue', important: true }]); assert.equal(s.rules[2].name, 'font-face'); assert.equal(s.rules[3].rules[0].selector, 'g'); assert.equal(s.rules[4].raw, null);});
test('semicolons inside url() and strings do not split declarations', () => { const s = parseCSS('a { background: url("data:x;base64,;;"); content: ";" }'); assert.equal(s.rules[0].decls.length, 2); assert.equal(s.rules[0].decls[0].value, 'url("data:x;base64,;;")');});
test('serialize is stable', () => { const text = '.card {\n fill: #2a2f45;\n stroke-width: 2;\n}\n'; assert.equal(serializeCSS(parseCSS(text)), text);});
test('style attribute helpers', () => { const decls = parseStyleAttr('fill: red; opacity:.5 !important;'); assert.deepEqual(decls, [{ name: 'fill', value: 'red', important: false }, { name: 'opacity', value: '.5', important: true }]); assert.equal(serializeStyleAttr(decls), 'fill: red; opacity: .5 !important');});
test('fontFaces finds embedded faces', () => { const faces = fontFaces(parseCSS('@font-face { font-family: "Inter"; font-weight: 700; src: url(a.woff2) } @media print { @font-face { font-family: B; src: url(b) } }')); assert.deepEqual(faces.map(f => [f.family, f.weight]), [['Inter', '700'], ['B', '400']]);});