]> git.giacomolli.uk - onechat/blobdiff - telegram_markdown_test.go
Keep time limits with their operations
[onechat] / telegram_markdown_test.go
index e2a253056e251b8877c6972c229d7b808f85061e..98b1f75758f02f157f49b86802cd3366ee807846 100644 (file)
@@ -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 <details> tag for the rest.",
+                       escaped:  "Use a &lt;details> tag for the rest.",
+               },
+               {
+                       name:     "tag in inline code stays as written",
+                       markdown: "Use `<details>` and `` a<b && c ``, not <b>.",
+                       escaped:  "Use `<details>` and `` a<b && c ``, not &lt;b>.",
+               },
+               {
+                       name:     "tag in a code block stays as written",
+                       markdown: "<p>\n\n```html\n<details>&amp;\n```\n\n<p>",
+                       escaped:  "&lt;p>\n\n```html\n<details>&amp;\n```\n\n&lt;p>",
+               },
+               {
+                       name:     "code block that does not close stays as written",
+                       markdown: "a <b>\n```\n<details>",
+                       escaped:  "a &lt;b>\n```\n<details>",
+               },
+               {
+                       name:     "tag in a table cell shows as text",
+                       markdown: "| Tag | Use |\n|-----|-----|\n| <br> | `<br>` |",
+                       escaped:  "| Tag | Use |\n|-----|-----|\n| &lt;br> | `<br>` |",
+               },
+               {
+                       name:     "autolink shows as text",
+                       markdown: "See <https://example.com>.",
+                       escaped:  "See &lt;https://example.com>.",
+               },
+               {
+                       name:     "entity in prose shows as written",
+                       markdown: "Write &lt; or &amp; for R&D.",
+                       escaped:  "Write &amp;lt; or &amp;amp; for R&amp;D.",
+               },
+               {
+                       name:     "backslash before a bracket gets no special case",
+                       markdown: `a \<b> and \&c`,
+                       escaped:  `a \&lt;b> and \&amp;c`,
+               },
+               {
+                       name:     "backtick after a backslash opens no code",
+                       markdown: "a \\`<b>\\` c",
+                       escaped:  "a \\`&lt;b>\\` c",
+               },
+               {
+                       name:     "backtick run that opens no code stays as text",
+                       markdown: "a ``b` <c>",
+                       escaped:  "a ``b` &lt;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))
+               })
+       }
+}