import { expect, test } from "bun:test"; import { parseQueries } from "../src/generate.ts"; // The generator embeds each query's SQL as a string literal. It used to embed // whatever line endings the checkout happened to have, so on a CRLF checkout // every regenerated query differed from the committed one by `\n` -> `\r\n`. // A build therefore dirtied the working tree, and the churn buried real // changes in the same file. Line endings carry no meaning in SQL, so the // parser normalises them and generated output stays stable across platforms. test("query SQL is normalised to LF regardless of the checkout's line endings", () => { const lf = "-- name: GetOne :one\nSELECT a,\n b\nFROM t\nWHERE id = :id;\n"; const crlf = lf.replace(/\n/g, "\r\n"); const fromLf = parseQueries(lf); const fromCrlf = parseQueries(crlf); expect(fromCrlf).toEqual(fromLf); expect(fromCrlf[0]!.sql).not.toContain("\r"); // The SQL itself must still be intact, not merely stripped of carriage returns. expect(fromCrlf[0]!.sql).toContain("SELECT a,"); expect(fromCrlf[0]!.sql).toContain("WHERE id = :id"); }); test("a lone CR does not survive into the embedded SQL either", () => { const cr = "-- name: GetOne :one\rSELECT 1\r"; for (const q of parseQueries(cr)) expect(q.sql).not.toContain("\r"); });