test(stylesheet): correct the malformed declaration offset

The expected offset disagreed with its own line and column: line 2 column 17 is
offset 28, which is where `red` starts. Offset 31 pointed at `; }`. The sibling
UTF-16 case in the same file already used the correct arithmetic.

Anchors the offset to the source it must point at so it cannot drift again.
This commit is contained in:
Amruth Pillai
2026-08-17 22:19:52 +02:00
parent 7c7dbaf21d
commit 817d4ef971
+7 -3
View File
@@ -3,12 +3,16 @@ import { parseStylesheet } from "./parse";
describe("parseStylesheet", () => {
it("returns exact ranges for malformed declarations and keeps a recoverable parse tree", () => {
const result = parseStylesheet("@version 1;\nsection { color red; }\nitem { opacity: .5; }");
const source = "@version 1;\nsection { color red; }\nitem { opacity: .5; }";
const result = parseStylesheet(source);
expect(result.diagnostics[0]?.range).toEqual({
start: { line: 2, column: 17, offset: 31 },
end: { line: 2, column: 17, offset: 31 },
start: { line: 2, column: 17, offset: 28 },
end: { line: 2, column: 17, offset: 28 },
});
// Anchor the offset to the source it must point at, so a parser change that shifts it fails
// loudly instead of leaving line/column and offset disagreeing.
expect(source.slice(28, 31)).toBe("red");
expect(result.rules).toHaveLength(2);
});