import { describe, expect, it } from "vitest"; import { parseCsvPreview } from "./csv-preview"; describe("parseCsvPreview", () => { it("reads quoted fields, doubled quotes and CRLF rows", () => { expect(parseCsvPreview('name,note\r\n"Smith, Ann","said ""hi"""\r\nBo,\n')).toEqual({ rows: [ ["name", "note"], ["Smith, Ann", 'said "hi"'], ["Bo", ""], ], truncated: false, }); }); it("keeps a final row without a trailing newline and skips blank lines", () => { expect(parseCsvPreview("a,b\n\n1,2").rows).toEqual([ ["a", "b"], ["1", "2"], ]); }); it("keeps newlines inside quoted fields", () => { expect(parseCsvPreview('a\n"line 1\nline 2"').rows).toEqual([["a"], ["line 1\nline 2"]]); }); it("stops after the row limit", () => { const result = parseCsvPreview("1\n2\n3\n4\n", 2); expect(result).toEqual({ rows: [["1"], ["2"]], truncated: true }); }); });