import assert from "node:assert/strict" import test from "node:test" import { getUnsupportedPdfCharacterMessage } from "../src/utils/pdfCharacterError" test("reports unsupported characters with the document position and character offset", () => { // pdf-lib displays supplementary Unicode characters as a private-use glyph, // while the hexadecimal value still contains the original code point. const error = new Error('WinAnsi cannot encode "" (0x1f600)') const documentData = { rows: [ { pos: "1", text: "Montage" }, { pos: "2.3", descriptionText: "Gerät 😀 montieren" }, ], } assert.equal( getUnsupportedPdfCharacterMessage(error, documentData), "Das Zeichen „😀“ (Unicode U+1F600) wird in PDF-Dokumenten nicht unterstützt. Fundstelle: Position 2.3, Beschreibung, Zeichen 7. Bitte ersetze oder entferne das Zeichen." ) }) test("returns null for unrelated PDF errors", () => { assert.equal( getUnsupportedPdfCharacterMessage(new Error("Background PDF is invalid"), {}), null ) })