mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-08-20 05:21:44 +10:00
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:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user