import { firstParagraph, flush } from "../firstParagraph";
describe("firstParagraph", () => {
it("returns the first paragraph as a single line", () => {
const lines = [" Hello", "world ", "", "Next paragraph"];
expect(firstParagraph(lines)).toBe("Hello world");
});
it("returns empty string when no content exists", () => {
const lines = ["", " ", ""];
expect(firstParagraph(lines)).toBe("");
});
it("uses the remaining buffer when no blank line exists", () => {
const lines = ["Leading line", "continued"];
expect(firstParagraph(lines)).toBe("Leading line continued");
});
});
describe("flush", () => {
it("appends the buffer contents as a paragraph", () => {
const buffer = ["Line one", "Line two"];
const paragraphs: string[] = [];
flush(buffer, paragraphs);
expect(paragraphs).toEqual(["Line one Line two"]);
});
it("does nothing when the buffer is empty", () => {
const paragraphs: string[] = [];
flush([], paragraphs);
expect(paragraphs).toEqual([]);
});
it("handles undefined buffer with default parameter", () => {
const paragraphs: string[] = [];
flush(undefined, paragraphs);
expect(paragraphs).toEqual([]);
});
});