35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { lineDiff } from "../../src/format/diff";
|
|
import { formatSvgSource } from "../../src/format/formatter";
|
|
|
|
describe("explicit formatting and source diff", () => {
|
|
it("formats only when explicitly requested and retains CRLF style", () => {
|
|
const source =
|
|
'<svg xmlns="http://www.w3.org/2000/svg" z="2" a="1">\r\n<g><title>A & B</title></g>\r\n</svg>';
|
|
const formatted = formatSvgSource(source);
|
|
expect(formatted).toContain("\r\n <g>\r\n <title>A & B</title>");
|
|
expect(formatted).toContain(' a="1" z="2"');
|
|
expect(formatted.endsWith("\r\n")).toBe(true);
|
|
});
|
|
|
|
it("refuses to format malformed XML", () => {
|
|
expect(() => formatSvgSource("<svg><g")).toThrow(/well-formed/u);
|
|
});
|
|
|
|
it("produces stable line additions, removals and context", () => {
|
|
expect(lineDiff("a\nb\nc", "a\nx\nc")).toEqual([
|
|
{ kind: "same", text: "a", oldLine: 1, newLine: 1 },
|
|
{ kind: "add", text: "x", newLine: 2 },
|
|
{ kind: "remove", text: "b", oldLine: 2 },
|
|
{ kind: "same", text: "c", oldLine: 3, newLine: 3 },
|
|
]);
|
|
});
|
|
|
|
it("falls back to bounded summaries for large comparisons", () => {
|
|
expect(lineDiff("a\nb\nc", "d\ne\nf", 2)).toEqual([
|
|
{ kind: "remove", text: "3 lines (5 characters)", oldLine: 1 },
|
|
{ kind: "add", text: "3 lines (5 characters)", newLine: 1 },
|
|
]);
|
|
});
|
|
});
|