import { describe, expect, it } from "bun:test"; import { extractEmail } from "../sequence/reply-matcher.js"; describe("extractEmail", () => { it("extracts from plain email", () => { expect(extractEmail("user@example.com")).toBe("user@example.com"); }); it("extracts from angle-bracketed email", () => { expect(extractEmail("")).toBe("user@example.com"); }); it('extracts from "Name " format', () => { expect(extractEmail('"John Doe" ')).toBe( "john@example.com", ); }); it("picks actual mailbox over display-name fragment with @", () => { expect(extractEmail('"Acme " ')).toBe( "owner@example.com", ); }); it("strips parenthetical comments before segment extraction", () => { // The parenthetical comment contains an angle-bracketed address; // without stripping comments first, the code would pick ops@example.com. expect( extractEmail('"Owner" (team )'), ).toBe("owner@example.com"); }); it("handles parenthetical comment with no angle brackets", () => { expect(extractEmail("owner@example.com (Owner Name)")).toBe( "owner@example.com", ); }); it("lowercases the result", () => { expect(extractEmail("USER@EXAMPLE.COM")).toBe("user@example.com"); }); it("returns undefined for empty string", () => { expect(extractEmail("")).toBeUndefined(); }); it("returns undefined for string with no email", () => { expect(extractEmail("not an email")).toBeUndefined(); }); });