3 # Unit tests for the Github Flavored Markdown parser
5 import '../autoload/lsp/markdown.vim' as md
7 # Test for different markdowns
9 var tests: list<list<list<any>>> = [
14 '# First level heading',
15 '## Second level heading',
16 '### Third level heading',
17 '# Heading with leading and trailing whitespaces ',
18 'Multiline setext heading ',
21 'Multiline setext heading\',
27 'First level heading',
29 'Second level heading',
31 'Third level heading',
33 'Heading with leading and trailing whitespaces',
35 'Multiline setext heading',
38 'Multiline setext heading',
41 # Expected text properties
43 [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 19}],
45 [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 20}],
47 [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 19}],
49 [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 45}],
51 [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 24}],
52 [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 10}],
54 [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 24}],
55 [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 10}],
62 'This **word** should be bold',
64 '**This line should be bold**',
66 'This __word__ should be bold',
68 '__This line should be bold__'
72 'This word should be bold',
74 'This line should be bold',
76 'This word should be bold',
78 'This line should be bold'
80 # Expected text properties
82 [{'col': 6, 'type': 'LspMarkdownBold', 'length': 4}],
84 [{'col': 1, 'type': 'LspMarkdownBold', 'length': 24}],
86 [{'col': 6, 'type': 'LspMarkdownBold', 'length': 4}],
88 [{'col': 1, 'type': 'LspMarkdownBold', 'length': 24}]
95 'This *word* should be italic',
97 '*This line should be italic*',
99 'This _word_ should be italic',
101 '_This line should be italic_'
105 'This word should be italic',
107 'This line should be italic',
109 'This word should be italic',
111 'This line should be italic'
113 # Expected text properties
115 [{'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}],
117 [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 26}],
119 [{'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}],
121 [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 26}]
125 # strikethrough text style
128 'This ~word~ should be strikethrough',
130 '~This line should be strikethrough~'
134 'This word should be strikethrough',
136 'This line should be strikethrough'
138 # Expected text properties
140 [{'col': 6, 'type': 'LspMarkdownStrikeThrough', 'length': 4}],
142 [{'col': 1, 'type': 'LspMarkdownStrikeThrough', 'length': 33}]
146 # bold and nested italic text style
149 '**This _word_ should be bold and italic**',
153 'This word should be bold and italic',
155 # Expected text properties
158 {'col': 1, 'type': 'LspMarkdownBold', 'length': 35},
159 {'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}
164 # all bold and italic text style
167 '***This line should be all bold and italic***',
171 'This line should be all bold and italic',
173 # Expected text properties
176 {'col': 1, 'type': 'LspMarkdownItalic', 'length': 39},
177 {'col': 1, 'type': 'LspMarkdownBold', 'length': 39}
183 # FIXME: The text is not quoted
186 'Text that is not quoted',
191 'Text that is not quoted',
195 # Expected text properties
204 'This paragraph contains ',
207 'This paragraph contains ',
208 'an hard line break',
210 'This paragraph contains an emphasis _before_\',
211 'an hard line break',
213 'This paragraph contains an emphasis ',
214 '_after_ an hard line break',
216 'This paragraph _contains\',
217 'an emphasis_ with an hard line break in the middle',
219 '→ This paragraph contains an hard line break ',
220 'and starts with the multibyte character "\u2192"',
226 '` inside code spans'
230 'This paragraph contains a soft line break',
232 'This paragraph contains',
233 'an hard line break',
235 'This paragraph contains an emphasis before',
236 'an hard line break',
238 'This paragraph contains an emphasis',
239 'after an hard line break',
241 'This paragraph contains',
242 'an emphasis with an hard line break in the middle',
244 '→ This paragraph contains an hard line break',
245 'and starts with the multibyte character "\u2192"',
247 'Line breaks do\ not occur inside code spans'
249 # Expected text properties
256 [{'col': 37, 'type': 'LspMarkdownItalic', 'length': 6}],
260 [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 5}],
262 [{'col': 16, 'type': 'LspMarkdownItalic', 'length': 8}],
263 [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 11}],
268 [{'col': 13, 'type': 'LspMarkdownCode', 'length': 15}]
273 var doc: dict<list<any>>
274 var text_result: list<string>
275 var props_result: list<list<dict<any>>>
277 doc = md.ParseMarkdown(t[0])
278 text_result = doc.content->deepcopy()->map((_, v) => v.text)
279 props_result = doc.content->deepcopy()->map((_, v) => v.props)
280 assert_equal(t[1], text_result, t[0]->string())
281 assert_equal(t[2], props_result, t[0]->string())
285 # Only here to because the test runner needs it
286 def g:StartLangServer(): bool
290 # vim: tabstop=8 shiftwidth=2 softtabstop=2 noexpandtab