X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/09cde69fdffe2721434392036f98dc241177f5a1..a606686934b4028c29dca8e9dae6b2e188cee9c5:/telegram_markdown_test.go diff --git a/telegram_markdown_test.go b/telegram_markdown_test.go index e2a2530..98b1f75 100644 --- a/telegram_markdown_test.go +++ b/telegram_markdown_test.go @@ -239,3 +239,74 @@ func TestMarkdownEntities(t *testing.T) { }) } } + +func TestEscapeTags(t *testing.T) { + testCases := []struct { + name string + markdown string + escaped string + }{ + { + name: "tag in prose shows as text", + markdown: "Use a
tag for the rest.", + escaped: "Use a <details> tag for the rest.", + }, + { + name: "tag in inline code stays as written", + markdown: "Use `
` and `` a.", + escaped: "Use `
` and `` a.", + }, + { + name: "tag in a code block stays as written", + markdown: "

\n\n```html\n

&\n```\n\n

", + escaped: "<p>\n\n```html\n

&\n```\n\n<p>", + }, + { + name: "code block that does not close stays as written", + markdown: "a \n```\n
", + escaped: "a <b>\n```\n
", + }, + { + name: "tag in a table cell shows as text", + markdown: "| Tag | Use |\n|-----|-----|\n|
| `
` |", + escaped: "| Tag | Use |\n|-----|-----|\n| <br> | `
` |", + }, + { + name: "autolink shows as text", + markdown: "See .", + escaped: "See <https://example.com>.", + }, + { + name: "entity in prose shows as written", + markdown: "Write < or & for R&D.", + escaped: "Write &lt; or &amp; for R&D.", + }, + { + name: "backslash before a bracket gets no special case", + markdown: `a \ and \&c`, + escaped: `a \<b> and \&c`, + }, + { + name: "backtick after a backslash opens no code", + markdown: "a \\`\\` c", + escaped: "a \\`<b>\\` c", + }, + { + name: "backtick run that opens no code stays as text", + markdown: "a ``b` ", + escaped: "a ``b` <c>", + }, + { + name: "dollar, pipe, and equals signs stay as written", + markdown: "$5 or $10, a || b, ==c==", + escaped: "$5 or $10, a || b, ==c==", + }, + } + + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + require.Equal(t, tc.escaped, telegramEscapeTags(tc.markdown)) + require.Equal(t, tc.markdown, telegramUnescapeTags(tc.escaped)) + }) + } +}