]> Sergey Matveev's repositories - vim-lsp.git/blob - test/markdown_tests.vim
22f34c4a1eab28a8861d97e4d05fdfc70baa7fbf
[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       ],
18       # Expected text
19       [
20         'First level heading',
21         '',
22         'Second level heading',
23         '',
24         'Third level heading'
25       ],
26       # Expected text properties
27       [
28         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 19}],
29         [],
30         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 20}],
31         [],
32         [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 19}]
33       ]
34     ],
35     [
36       # Bold text style
37       # Input text
38       [
39         'This **word** should be bold',
40         '',
41         '**This line should be bold**',
42         '',
43         'This __word__ should be bold',
44         '',
45         '__This line should be bold__'
46       ],
47       # Expected text
48       [
49         'This word should be bold',
50         '',
51         'This line should be bold',
52         '',
53         'This word should be bold',
54         '',
55         'This line should be bold'
56       ],
57       # Expected text properties
58       [
59         [{'col': 6, 'type': 'LspMarkdownBold', 'length': 4}],
60         [],
61         [{'col': 1, 'type': 'LspMarkdownBold', 'length': 24}],
62         [],
63         [{'col': 6, 'type': 'LspMarkdownBold', 'length': 4}],
64         [],
65         [{'col': 1, 'type': 'LspMarkdownBold', 'length': 24}]
66       ]
67     ],
68     [
69       # Italic text style
70       # Input text
71       [
72         'This *word* should be italic',
73         '',
74         '*This line should be italic*',
75         '',
76         'This _word_ should be italic',
77         '',
78         '_This line should be italic_'
79       ],
80       # Expected text
81       [
82         'This word should be italic',
83         '',
84         'This line should be italic',
85         '',
86         'This word should be italic',
87         '',
88         'This line should be italic'
89       ],
90       # Expected text properties
91       [
92         [{'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}],
93         [],
94         [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 26}],
95         [],
96         [{'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}],
97         [],
98         [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 26}]
99       ],
100     ],
101     [
102       # strikethrough text style
103       # Input text
104       [
105         'This ~word~ should be strikethrough',
106         '',
107         '~This line should be strikethrough~'
108       ],
109       # Expected text
110       [
111         'This word should be strikethrough',
112         '',
113         'This line should be strikethrough'
114       ],
115       # Expected text properties
116       [
117         [{'col': 6, 'type': 'LspMarkdownStrikeThrough', 'length': 4}],
118         [],
119         [{'col': 1, 'type': 'LspMarkdownStrikeThrough', 'length': 33}]
120       ]
121     ],
122     [
123       # bold and nested italic text style
124       # Input text
125       [
126         '**This _word_ should be bold and italic**',
127       ],
128       # Expected text
129       [
130         'This word should be bold and italic',
131       ],
132       # Expected text properties
133       [
134         [
135           {'col': 1, 'type': 'LspMarkdownBold', 'length': 35},
136           {'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}
137         ]
138       ]
139     ],
140     [
141       # all bold and italic text style
142       # Input text
143       [
144         '***This line should be all bold and italic***',
145       ],
146       # Expected text
147       [
148         'This line should be all bold and italic',
149       ],
150       # Expected text properties
151       [
152         [
153           {'col': 1, 'type': 'LspMarkdownItalic', 'length': 39},
154           {'col': 1, 'type': 'LspMarkdownBold', 'length': 39}
155         ]
156       ]
157     ],
158     [
159       # quoted text
160       # FIXME: The text is not quoted
161       # Input text
162       [
163         'Text that is not quoted',
164         '> quoted text'
165       ],
166       # Expected text
167       [
168         'Text that is not quoted',
169         '',
170         'quoted text'
171       ],
172       # Expected text properties
173       [
174         [], [], []
175       ]
176     ]
177   ]
178
179   var doc: dict<list<any>>
180   var text_result: list<string>
181   var props_result: list<list<dict<any>>>
182   for t in tests
183     doc = md.ParseMarkdown(t[0])
184     text_result = doc.content->deepcopy()->map((_, v) => v.text)
185     props_result = doc.content->deepcopy()->map((_, v) => v.props)
186     assert_equal(t[1], text_result, t[0]->string())
187     assert_equal(t[2], props_result, t[0]->string())
188   endfor
189 enddef
190
191 # Only here to because the test runner needs it
192 def g:StartLangServer(): bool
193   return true
194 enddef
195
196 # vim: shiftwidth=2 softtabstop=2 noexpandtab