import { describe, expect, it } from "vitest";
import { parseCsvRows } from "./csv";

describe("parseCsvRows", () => {
  it("splits simple comma-separated rows", () => {
    expect(parseCsvRows("url,text,author\na,b,c")).toEqual([
      ["url", "text", "author"],
      ["a", "b", "c"],
    ]);
  });

  it("keeps commas inside quoted fields intact", () => {
    expect(parseCsvRows('u,"你好，世界",author')).toEqual([["u", "你好，世界", "author"]]);
  });

  it("unescapes doubled quotes inside a quoted field", () => {
    expect(parseCsvRows('u,"she said ""hi""",a')).toEqual([["u", 'she said "hi"', "a"]]);
  });

  it("drops blank lines", () => {
    expect(parseCsvRows("a,b\n\n\nc,d")).toEqual([
      ["a", "b"],
      ["c", "d"],
    ]);
  });

  it("returns an empty array for empty input", () => {
    expect(parseCsvRows("")).toEqual([]);
  });
});
