6 "github.com/stretchr/testify/require"
9 func TestMarkdownEntities(t *testing.T) {
10 testCases := []struct {
17 name: "double asterisks give bold",
18 markdown: "a **b** c",
20 entities: []botEntity{
29 name: "double underscores give bold",
32 entities: []botEntity{
41 name: "single asterisk gives italic",
42 markdown: "an *odd* word",
44 entities: []botEntity{
53 name: "single underscore gives italic",
54 markdown: "an _odd_ word",
56 entities: []botEntity{
65 name: "double tildes give strikethrough",
66 markdown: "~~old~~ new",
68 entities: []botEntity{
70 Type: "strikethrough",
77 name: "backticks give inline code with no entity inside",
78 markdown: "run `go **test**` now",
79 text: "run go **test** now",
80 entities: []botEntity{
89 name: "double backticks hold a backtick",
90 markdown: "``a ` b``",
92 entities: []botEntity{
101 name: "link gives a text link",
102 markdown: "see [the docs](https://example.com/a_b) here",
103 text: "see the docs here",
104 entities: []botEntity{
109 URL: "https://example.com/a_b",
114 name: "bold inside a link nests",
115 markdown: "[a **b** c](https://example.com)",
117 entities: []botEntity{
122 URL: "https://example.com",
132 name: "code block with a language gives pre with the language",
133 markdown: "Commit:\n```text\nFix the **bug**\n\nBody\n```\nDone.",
134 text: "Commit:\nFix the **bug**\n\nBody\nDone.",
135 entities: []botEntity{
145 name: "code block without a language gives pre",
146 markdown: "```\nls -l\n```",
148 entities: []botEntity{
157 name: "heading becomes bold with its inline marks",
158 markdown: "## The `plan`\nnext",
159 text: "The plan\nnext",
160 entities: []botEntity{
174 name: "list, quote and table stay as text",
175 markdown: "- one\n* two\n1. three\n> quote\n| a | b |\n|---|---|",
176 text: "- one\n* two\n1. three\n> quote\n| a | b |\n|---|---|",
179 name: "asterisk of a list item with italic later stays",
180 markdown: "* item with *stress*",
181 text: "* item with stress",
182 entities: []botEntity{
191 name: "unclosed marks stay as text",
192 markdown: "**open, `tick, [link](, ~~gone and *star",
193 text: "**open, `tick, [link](, ~~gone and *star",
196 name: "unclosed code fence stays as text",
197 markdown: "```go\nfmt.Println()",
198 text: "```go\nfmt.Println()",
201 name: "snake case words stay as text",
202 markdown: "set snake_case_words and max_tokens_count",
203 text: "set snake_case_words and max_tokens_count",
206 name: "multiplication stays as text",
207 markdown: "2 * 3 * 4",
211 name: "mark does not cross a line break",
212 markdown: "**a\nb**",
216 name: "backslash makes a mark plain",
217 markdown: `\*not italic\* and C:\Users`,
218 text: `*not italic* and C:\Users`,
221 name: "character outside the BMP moves the offset by two",
222 markdown: "\U0001F600 **b**",
223 text: "\U0001F600 b",
224 entities: []botEntity{
234 for _, tc := range testCases {
235 t.Run(tc.name, func(t *testing.T) {
236 text, entities := markdownEntities(tc.markdown)
237 require.Equal(t, tc.text, text)
238 require.Equal(t, tc.entities, entities)