import { describe, expect, test } from "bun:test";
import { formatPatchSeries } from "./patch-format";
const commit = (sha: string, message: string) => ({
sha,
message,
authorName: "Ada Lovelace",
authorEmail: "ada@example.com",
authoredAt: Date.UTC(2026, 9, 12, 8, 30, 0),
});
describe("formatPatchSeries", () => {
test("a single commit is a git format-patch message git am accepts", () => {
const text = formatPatchSeries([
{ commit: commit("a".repeat(40), "Fix parser\n\nHandles empty input.\n"), patch: "diff --git a/x b/x\n" },
]);
expect(text).toBe(
[
`From ${"a".repeat(40)} Mon Sep 17 00:00:00 2001`,
"From: Ada Lovelace <ada@example.com>",
"Date: Mon, 12 Oct 2026 08:30:00 +0000",
"Subject: [PATCH] Fix parser",
"",
"Handles empty input.",
"---",
"diff --git a/x b/x",
"-- ",
"gitfor",
"",
].join("\n"),
);
});
test("series are numbered and subjects without bodies go straight to the diff", () => {
const text = formatPatchSeries([
{ commit: commit("a".repeat(40), "One"), patch: "diff one" },
{ commit: commit("b".repeat(40), "Two"), patch: "diff two\n" },
]);
expect(text).toContain("Subject: [PATCH 1/2] One\n\n---\ndiff one\n");
expect(text).toContain("Subject: [PATCH 2/2] Two\n\n---\ndiff two\n");