| 1 | import assert from "node:assert/strict"; |
| 2 | import test from "node:test"; |
| 3 | import { telegramMessageBody } from "../src/lib.mjs"; |
| 4 | |
| 5 | test("Telegram preserves adjacent links and balanced parentheses in URLs", () => { |
| 6 | const first = "https://example.invalid/one"; |
| 7 | const second = "https://example.invalid/two(a(b))"; |
| 8 | assert.deepEqual(telegramMessageBody(`[First](${first})[Second](${second}).`), { |
| 9 | text: `[First](${first})[Second](https://example.invalid/two(a(b\\)\\))\\.`, |
| 10 | parse_mode: "MarkdownV2", |
| 11 | }); |
| 12 | assert.deepEqual( |
| 13 | telegramMessageBody(`[First](${first}/my_path)[Second](${second}).`, { markdown: false }), |
| 14 | { |
| 15 | text: `First (${first}/my_path)Second (${second}).`, |
| 16 | }, |
| 17 | ); |
| 18 | assert.deepEqual( |
| 19 | telegramMessageBody(`[\`foo_bar\`](${first}/a_b) and [**bold** \`baz_qux\`](${second}).`, { markdown: false }), |
| 20 | { |
| 21 | text: `foo_bar (${first}/a_b) and bold baz_qux (${second}).`, |
| 22 | }, |
| 23 | ); |
| 24 | }); |
| 25 |