import { describe, it, expect } from "vitest" import { escapeMarkdownV2, MARKDOWN_V2_SPECIAL_CHARS } from "../src/markdown.ts" describe("escapeMarkdownV2", () => { it("empty string → empty", () => { expect(escapeMarkdownV2("")).toBe("") }) it("string without special chars → unchanged", () => { expect(escapeMarkdownV2("hello world 123 abc")).toBe("hello world 123 abc") }) it("cyrillic → unchanged", () => { expect(escapeMarkdownV2("Привет мир")).toBe("Привет мир") }) it.each([...MARKDOWN_V2_SPECIAL_CHARS])("escapes single special char %j", (ch) => { expect(escapeMarkdownV2(ch)).toBe("\\" + ch) }) it("mix cyrillic + special chars: cyrillic untouched, special escaped", () => { // comma and space are NOT in the special set — stay as-is expect(escapeMarkdownV2("Привет, *мир*!")).toBe("Привет, \\*мир\\*\\!") }) it("all special chars at once", () => { const all = [...MARKDOWN_V2_SPECIAL_CHARS].join("") const expected = [...MARKDOWN_V2_SPECIAL_CHARS].map((c) => "\\" + c).join("") expect(escapeMarkdownV2(all)).toBe(expected) }) it("backtick is escaped", () => { expect(escapeMarkdownV2("`code`")).toBe("\\`code\\`") }) it("backslash is NOT in MARKDOWN_V2_SPECIAL_CHARS and passes through", () => { expect(MARKDOWN_V2_SPECIAL_CHARS as readonly string[]).not.toContain("\\") // input `\*` (2 chars): backslash stays, asterisk escaped → `\\*` (3 chars) expect(escapeMarkdownV2("\\*")).toBe("\\\\*") }) })