import { describe, expect, it } from "vitest";
import { countCorpusLines, splitCorpusLines } from "./corpus-lines";

describe("corpus line segmentation", () => {
  it("preserves mixed separators and the trailing empty logical line", () => {
    const text = "one\r\ntwo\nthree\rfour\u2028five\u2029";
    const lines = splitCorpusLines(text);

    expect(lines).toEqual([
      { text: "one", ending: "\r\n" },
      { text: "two", ending: "\n" },
      { text: "three", ending: "\r" },
      { text: "four", ending: "\u2028" },
      { text: "five", ending: "\u2029" },
      { text: "", ending: "" },
    ]);
    expect(countCorpusLines(text)).toBe(lines.length);
    expect(lines.map((line) => line.text + line.ending).join("")).toBe(text);
  });

  it("treats an empty document as one empty line", () => {
    expect(splitCorpusLines("")).toEqual([{ text: "", ending: "" }]);
    expect(countCorpusLines("")).toBe(1);
  });
});
