Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2import { filePreviewDelimiter, parseDelimitedPreview } from "./delimitedPreview.ts";
3
4describe("delimited file previews", () => {
5 it("respects a specific MIME type before the extension", () => {
6 expect(filePreviewDelimiter({ name: "data.CSV", mimeType: "text/plain" })).toBe(",");
7 expect(filePreviewDelimiter({ name: "data.csv", mimeType: "application/pdf" })).toBeNull();
8 });
9 it("preserves quoted separators, escaped quotes, blank cells and line breaks", () => {
10 expect(
11 parseDelimitedPreview('\ufeffname,notes,empty\r\n"A, B","say ""hi""\nagain",\r\n', ","),
12 ).toEqual({
13 rows: [
14 ["name", "notes", "empty"],
15 ["A, B", 'say "hi"\nagain', ""],
16 ],
17 truncated: false,
18 });
19 expect(parseDelimitedPreview("one\ttwo\n\tthree", "\t").rows).toEqual([
20 ["one", "two"],
21 ["", "three"],
22 ]);
23 });
24 it("bounds rows, columns and cell length and reports partial content", () => {
25 const table = parseDelimitedPreview(
26 Array.from({ length: 101 }, () =>
27 Array.from({ length: 31 }, () => "x".repeat(2001)).join(","),
28 ).join("\n"),
29 ",",
30 );
31 expect(table.truncated).toBe(true);
32 expect(table.rows).toHaveLength(100);
33 expect(table.rows[0]).toHaveLength(30);
34 expect(table.rows[0]?.[0]).toHaveLength(2000);
35 expect(parseDelimitedPreview('a,"unfinished', ",").truncated).toBe(true);
36 });
37});