]> Sergey Matveev's repositories - vim-lsp.git/blob - test/markdown_tests.vim
Rearrange workspaceConfiguration call
[vim-lsp.git] / test / markdown_tests.vim
1 vim9script
2
3 # Unit tests for the Github Flavored Markdown parser
4
5 import '../autoload/lsp/markdown.vim' as md
6
7 # Test for different markdowns
8 def g:Test_Markdown()
9   var tests: list<list<list<any>>> = [
10     [
11       # Different headings
12       # Input text
13       [
14         '# First level heading',
15         '## Second level heading',
16         '### Third level heading',
17         '#        Heading with leading and trailing whitespaces            ',
18         'Multiline setext heading  ',
19         'of level 1',
20         '===',
21         'Multiline setext heading\',
22         'of level 2',
23         '---'
24       ],
25       # Expected text
26       [
27         'First level heading',
28         '',
29         'Second level heading',
30         '',
31         'Third level heading',
32         '',
33         'Heading with leading and trailing whitespaces',
34         '',
35         'Multiline setext heading',
36         'of level 1',
37         '',
38         'Multiline setext heading',
39         'of level 2'
40       ],
41       # Expected text properties
42       [
43         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 19}],
44         [],
45         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 20}],
46         [],
47         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 19}],
48         [],
49         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 45}],
50         [],
51         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 24}],
52         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 10}],
53         [],
54         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 24}],
55         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 10}],
56       ]
57     ],
58     [
59       # Bold text style
60       # Input text
61       [
62         'This **word** should be bold',
63         '',
64         '**This line should be bold**',
65         '',
66         'This __word__ should be bold',
67         '',
68         '__This line should be bold__'
69       ],
70       # Expected text
71       [
72         'This word should be bold',
73         '',
74         'This line should be bold',
75         '',
76         'This word should be bold',
77         '',
78         'This line should be bold'
79       ],
80       # Expected text properties
81       [
82         [{'col': 6, 'type': 'LspMarkdownBold', 'length': 4}],
83         [],
84         [{'col': 1, 'type': 'LspMarkdownBold', 'length': 24}],
85         [],
86         [{'col': 6, 'type': 'LspMarkdownBold', 'length': 4}],
87         [],
88         [{'col': 1, 'type': 'LspMarkdownBold', 'length': 24}]
89       ]
90     ],
91     [
92       # Italic text style
93       # Input text
94       [
95         'This *word* should be italic',
96         '',
97         '*This line should be italic*',
98         '',
99         'This _word_ should be italic',
100         '',
101         '_This line should be italic_'
102       ],
103       # Expected text
104       [
105         'This word should be italic',
106         '',
107         'This line should be italic',
108         '',
109         'This word should be italic',
110         '',
111         'This line should be italic'
112       ],
113       # Expected text properties
114       [
115         [{'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}],
116         [],
117         [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 26}],
118         [],
119         [{'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}],
120         [],
121         [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 26}]
122       ],
123     ],
124     [
125       # strikethrough text style
126       # Input text
127       [
128         'This ~word~ should be strikethrough',
129         '',
130         '~This line should be strikethrough~'
131       ],
132       # Expected text
133       [
134         'This word should be strikethrough',
135         '',
136         'This line should be strikethrough'
137       ],
138       # Expected text properties
139       [
140         [{'col': 6, 'type': 'LspMarkdownStrikeThrough', 'length': 4}],
141         [],
142         [{'col': 1, 'type': 'LspMarkdownStrikeThrough', 'length': 33}]
143       ]
144     ],
145     [
146       # bold and nested italic text style
147       # Input text
148       [
149         '**This _word_ should be bold and italic**',
150       ],
151       # Expected text
152       [
153         'This word should be bold and italic',
154       ],
155       # Expected text properties
156       [
157         [
158           {'col': 1, 'type': 'LspMarkdownBold', 'length': 35},
159           {'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}
160         ]
161       ]
162     ],
163     [
164       # all bold and italic text style
165       # Input text
166       [
167         '***This line should be all bold and italic***',
168       ],
169       # Expected text
170       [
171         'This line should be all bold and italic',
172       ],
173       # Expected text properties
174       [
175         [
176           {'col': 1, 'type': 'LspMarkdownItalic', 'length': 39},
177           {'col': 1, 'type': 'LspMarkdownBold', 'length': 39}
178         ]
179       ]
180     ],
181     [
182       # quoted text
183       # FIXME: The text is not quoted
184       # Input text
185       [
186         'Text that is not quoted',
187         '> quoted text'
188       ],
189       # Expected text
190       [
191         'Text that is not quoted',
192         '',
193         'quoted text'
194       ],
195       # Expected text properties
196       [
197         [], [], []
198       ]
199     ],
200     [
201       # line breaks
202       # Input text
203       [
204         'This paragraph contains ',
205         'a soft line break',
206         '',
207         'This paragraph contains  ',
208         'an hard line break',
209         '',
210         'This paragraph contains an emphasis _before_\',
211         'an hard line break',
212         '',
213         'This paragraph contains an emphasis  ',
214         '_after_ an hard line break',
215         '',
216         'This paragraph _contains\',
217         'an emphasis_ with an hard line break in the middle',
218         '',
219         '→ This paragraph contains an hard line break  ',
220         'and starts with the multibyte character "\u2192"',
221         '',
222         'Line breaks `',
223         'do\',
224         'not  ',
225         'occur',
226         '` inside code spans'
227       ],
228       # Expected text
229       [
230         'This paragraph contains a soft line break',
231         '',
232         'This paragraph contains',
233         'an hard line break',
234         '',
235         'This paragraph contains an emphasis before',
236         'an hard line break',
237         '',
238         'This paragraph contains an emphasis',
239         'after an hard line break',
240         '',
241         'This paragraph contains',
242         'an emphasis with an hard line break in the middle',
243         '',
244         '→ This paragraph contains an hard line break',
245         'and starts with the multibyte character "\u2192"',
246         '',
247         'Line breaks do\ not   occur inside code spans'
248       ],
249       # Expected text properties
250       [
251         [],
252         [],
253         [],
254         [],
255         [],
256         [{'col': 37, 'type': 'LspMarkdownItalic', 'length': 6}],
257         [],
258         [],
259         [],
260         [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 5}],
261         [],
262         [{'col': 16, 'type': 'LspMarkdownItalic', 'length': 8}],
263         [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 11}],
264         [],
265         [],
266         [],
267         [],
268         [{'col': 13, 'type': 'LspMarkdownCode', 'length': 15}]
269       ]
270     ]
271   ]
272
273   var doc: dict<list<any>>
274   var text_result: list<string>
275   var props_result: list<list<dict<any>>>
276   for t in tests
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())
282   endfor
283 enddef
284
285 # Only here to because the test runner needs it
286 def g:StartLangServer(): bool
287   return true
288 enddef
289
290 # vim: tabstop=8 shiftwidth=2 softtabstop=2 noexpandtab