--- /dev/null
+vim9script
+
+# Unit tests for the Github Flavored Markdown parser
+
+import '../autoload/lsp/markdown.vim' as md
+
+# Test for different markdowns
+def g:Test_Markdown()
+ var tests: list<list<list<any>>> = [
+ [
+ # Different headings
+ # Input text
+ [
+ '# First level heading',
+ '## Second level heading',
+ '### Third level heading'
+ ],
+ # Expected text
+ [
+ 'First level heading',
+ '',
+ 'Second level heading',
+ '',
+ 'Third level heading'
+ ],
+ # Expected text properties
+ [
+ [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 19}],
+ [],
+ [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 20}],
+ [],
+ [{'col': 1, 'type': 'LspMarkdownHeading', 'length': 19}]
+ ]
+ ],
+ [
+ # Bold text style
+ # Input text
+ [
+ 'This **word** should be bold',
+ '',
+ '**This line should be bold**',
+ '',
+ 'This __word__ should be bold',
+ '',
+ '__This line should be bold__'
+ ],
+ # Expected text
+ [
+ 'This word should be bold',
+ '',
+ 'This line should be bold',
+ '',
+ 'This word should be bold',
+ '',
+ 'This line should be bold'
+ ],
+ # Expected text properties
+ [
+ [{'col': 6, 'type': 'LspMarkdownBold', 'length': 4}],
+ [],
+ [{'col': 1, 'type': 'LspMarkdownBold', 'length': 24}],
+ [],
+ [{'col': 6, 'type': 'LspMarkdownBold', 'length': 4}],
+ [],
+ [{'col': 1, 'type': 'LspMarkdownBold', 'length': 24}]
+ ]
+ ],
+ [
+ # Italic text style
+ # Input text
+ [
+ 'This *word* should be italic',
+ '',
+ '*This line should be italic*',
+ '',
+ 'This _word_ should be italic',
+ '',
+ '_This line should be italic_'
+ ],
+ # Expected text
+ [
+ 'This word should be italic',
+ '',
+ 'This line should be italic',
+ '',
+ 'This word should be italic',
+ '',
+ 'This line should be italic'
+ ],
+ # Expected text properties
+ [
+ [{'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}],
+ [],
+ [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 26}],
+ [],
+ [{'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}],
+ [],
+ [{'col': 1, 'type': 'LspMarkdownItalic', 'length': 26}]
+ ],
+ ],
+ [
+ # strikethrough text style
+ # Input text
+ [
+ 'This ~word~ should be strikethrough',
+ '',
+ '~This line should be strikethrough~'
+ ],
+ # Expected text
+ [
+ 'This word should be strikethrough',
+ '',
+ 'This line should be strikethrough'
+ ],
+ # Expected text properties
+ [
+ [{'col': 6, 'type': 'LspMarkdownStrikeThrough', 'length': 4}],
+ [],
+ [{'col': 1, 'type': 'LspMarkdownStrikeThrough', 'length': 33}]
+ ]
+ ],
+ [
+ # bold and nested italic text style
+ # Input text
+ [
+ '**This _word_ should be bold and italic**',
+ ],
+ # Expected text
+ [
+ 'This word should be bold and italic',
+ ],
+ # Expected text properties
+ [
+ [
+ {'col': 1, 'type': 'LspMarkdownBold', 'length': 35},
+ {'col': 6, 'type': 'LspMarkdownItalic', 'length': 4}
+ ]
+ ]
+ ],
+ [
+ # all bold and italic text style
+ # Input text
+ [
+ '***This line should be all bold and italic***',
+ ],
+ # Expected text
+ [
+ 'This line should be all bold and italic',
+ ],
+ # Expected text properties
+ [
+ [
+ {'col': 1, 'type': 'LspMarkdownItalic', 'length': 39},
+ {'col': 1, 'type': 'LspMarkdownBold', 'length': 39}
+ ]
+ ]
+ ],
+ [
+ # quoted text
+ # FIXME: The text is not quoted
+ # Input text
+ [
+ 'Text that is not quoted',
+ '> quoted text'
+ ],
+ # Expected text
+ [
+ 'Text that is not quoted',
+ '',
+ 'quoted text'
+ ],
+ # Expected text properties
+ [
+ [], [], []
+ ]
+ ]
+ ]
+
+ var doc: dict<list<any>>
+ var text_result: list<string>
+ var props_result: list<list<dict<any>>>
+ for t in tests
+ doc = md.ParseMarkdown(t[0])
+ text_result = doc.content->deepcopy()->map((_, v) => v.text)
+ props_result = doc.content->deepcopy()->map((_, v) => v.props)
+ assert_equal(t[1], text_result, t[0]->string())
+ assert_equal(t[2], props_result, t[0]->string())
+ endfor
+enddef
+
+# Only here to because the test runner needs it
+def g:StartLangServer(): bool
+ return true
+enddef
+
+# vim: shiftwidth=2 softtabstop=2 noexpandtab
# Script to run the unit-tests for the LSP Vim plugin
-VIMPRG=${VIMPRG:=$(which vim)}
+#VIMPRG=${VIMPRG:=$(which vim)}
+export VIMPRG=/home/yega/Documents/vim/vim9/vim/src/vim
+export VIMRUNTIME=/home/yega/Documents/vim/vim9/vim/runtime
if [ -z "$VIMPRG" ]; then
echo "ERROR: vim (\$VIMPRG) is not found in PATH"
exit 1
VIM_CMD="$VIMPRG -u NONE -U NONE -i NONE --noplugin -N --not-a-term"
-TESTS="clangd_tests.vim tsserver_tests.vim gopls_tests.vim not_lspserver_related_tests.vim"
+TESTS="clangd_tests.vim tsserver_tests.vim gopls_tests.vim not_lspserver_related_tests.vim markdown_tests.vim"
RunTestsInFile() {
- testfile=$1
- echo "Running tests in $testfile"
- $VIM_CMD -c "let g:TestName='$testfile'" -S runner.vim
+ testfile=$1
+ echo "Running tests in $testfile"
+ $VIM_CMD -c "let g:TestName='$testfile'" -S runner.vim
- if ! [ -f results.txt ]; then
- echo "ERROR: Test results file 'results.txt' is not found."
- exit 2
- fi
+ if ! [ -f results.txt ]; then
+ echo "ERROR: Test results file 'results.txt' is not found."
+ exit 2
+ fi
- cat results.txt
+ cat results.txt
- if grep -qw FAIL results.txt; then
- echo "ERROR: Some test(s) in $testfile failed."
- exit 3
- fi
+ if grep -qw FAIL results.txt; then
+ echo "ERROR: Some test(s) in $testfile failed."
+ exit 3
+ fi
- echo "SUCCESS: All the tests in $testfile passed."
- echo
+ echo "SUCCESS: All the tests in $testfile passed."
+ echo
}
for testfile in $TESTS
do
- RunTestsInFile $testfile
+ RunTestsInFile $testfile
done
for encoding in "utf-8" "utf-16" "utf-32"
do
- export LSP_OFFSET_ENCODING=$encoding
- echo "LSP offset encoding: $LSP_OFFSET_ENCODING"
- RunTestsInFile clangd_offsetencoding.vim
+ export LSP_OFFSET_ENCODING=$encoding
+ echo "LSP offset encoding: $LSP_OFFSET_ENCODING"
+ RunTestsInFile clangd_offsetencoding.vim
done
echo "SUCCESS: All the tests passed."
exit 0
+
+# vim: shiftwidth=2 softtabstop=2 noexpandtab