diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 784dd11..902c861 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,3 +26,11 @@ jobs: run: ./test/run.sh env: SVELTE_TEST_EDITORS: ${{ matrix.neovim && 'nvim' || 'vim' }} + + shared: + name: shared cases with vim-vue-plugin + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check shared cases + run: ./test/shared.sh diff --git a/.gitignore b/.gitignore index 137ca65..ac7a121 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ test.svelte .idea test/deps/ doc/tags +test/other/ diff --git a/README.md b/README.md index 2feafce..5fbe57e 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,8 @@ Each case is a `.svelte` file in [test/cases](test/cases), with an optional `.vi Tests also run on GitHub Actions for each push and pull request, with Vim 8.2.0000, the latest Vim, Neovim 0.9.5 and the latest Neovim. +Cases named `shared-*` are for scenarios also in [vim-vue-plugin][3], which handles blocks in the same way. `./test/shared.sh` lists shared cases in only one of them, as a warning on GitHub Actions, so a fix in one plugin can be checked in the other. + ## See also - [vim-svelte-theme][11] svelte syntax color diff --git a/indent/svelte.vim b/indent/svelte.vim index 4403ec1..67daee5 100644 --- a/indent/svelte.vim +++ b/indent/svelte.vim @@ -23,7 +23,10 @@ let s:svelte_tag_end = '\v^\<\/(script|style)' let s:template_tag = '\v^\s*\<\/?template' " https://developer.mozilla.org/en-US/docs/Glossary/Empty_element let s:empty_tagname = '(area|base|br|col|embed|hr|input|img|keygen|link|meta|param|source|track|wbr)' -let s:empty_tag = '\v\C\<'.s:empty_tagname.'[^/]*\>' +" Empty tag ending with '>' but not '/>'. '>' in {...} like {(e) => f(e)} or +" in quotes doesn't end the tag +let s:empty_tag = '\v\C\<'.s:empty_tagname + \ .'>(\{[^}]*\}|"[^"]*"|''[^'']*''|[^\>{"''/]|/(\>)@!)*\>' let s:empty_tag_start = '\v\<'.s:empty_tagname.'[^\>]*$' let s:empty_tag_end = '\v^\s*[^\<\>\/]*\>\s*' let s:tag_start = '^<$' diff --git a/test/cases/lang-attr.vim b/test/cases/lang-attr.vim deleted file mode 100644 index caa0e70..0000000 --- a/test/cases/lang-attr.vim +++ /dev/null @@ -1,7 +0,0 @@ -" lang attribute in single quotes or without quotes -let g:vim_svelte_plugin_use_sass = 1 - -function! Check() - call ExpectBlock('let count', 'script', 'typescript', 'typescriptSvelteScript') - call ExpectBlock('$a: 1px', 'style', 'scss', 'cssScssSvelteStyle') -endfunction diff --git a/test/cases/shared-empty-tag.svelte b/test/cases/shared-empty-tag.svelte new file mode 100644 index 0000000..f8f731c --- /dev/null +++ b/test/cases/shared-empty-tag.svelte @@ -0,0 +1,10 @@ +
x
+ +y
+
+ z
+ b ? 'a' : 'b'}> +w
+{count}
+ + diff --git a/test/cases/shared-lang-attr.vim b/test/cases/shared-lang-attr.vim new file mode 100644 index 0000000..2d4674e --- /dev/null +++ b/test/cases/shared-lang-attr.vim @@ -0,0 +1,9 @@ +" lang attribute in single quotes or without quotes, and lang="typescript" +let g:vim_svelte_plugin_use_sass = 1 + +function! Check() + call ExpectBlock('let count', 'script', 'typescript', 'typescriptSvelteScript') + call ExpectBlock('let a', 'script', 'typescript', 'typescriptSvelteScript') + call ExpectBlock('let b', 'script', 'typescript', 'typescriptSvelteScript') + call ExpectBlock('$a: 1px', 'style', 'scss', 'cssScssSvelteStyle') +endfunction diff --git a/test/cases/multiline-tag.svelte b/test/cases/shared-multiline-tag.svelte similarity index 100% rename from test/cases/multiline-tag.svelte rename to test/cases/shared-multiline-tag.svelte diff --git a/test/cases/multiline-tag.vim b/test/cases/shared-multiline-tag.vim similarity index 100% rename from test/cases/multiline-tag.vim rename to test/cases/shared-multiline-tag.vim diff --git a/test/cases/custom-lang.svelte b/test/cases/shared-no-syntax-file.svelte similarity index 100% rename from test/cases/custom-lang.svelte rename to test/cases/shared-no-syntax-file.svelte diff --git a/test/cases/custom-lang.vim b/test/cases/shared-no-syntax-file.vim similarity index 100% rename from test/cases/custom-lang.vim rename to test/cases/shared-no-syntax-file.vim diff --git a/test/cases/shiftwidth-zero.svelte b/test/cases/shared-shiftwidth-zero.svelte similarity index 100% rename from test/cases/shiftwidth-zero.svelte rename to test/cases/shared-shiftwidth-zero.svelte diff --git a/test/cases/shiftwidth-zero.vim b/test/cases/shared-shiftwidth-zero.vim similarity index 100% rename from test/cases/shiftwidth-zero.vim rename to test/cases/shared-shiftwidth-zero.vim diff --git a/test/cases/lang-attr.svelte b/test/cases/shared-syntax-merge.svelte similarity index 55% rename from test/cases/lang-attr.svelte rename to test/cases/shared-syntax-merge.svelte index 0e0e3ef..f304ab8 100644 --- a/test/cases/lang-attr.svelte +++ b/test/cases/shared-syntax-merge.svelte @@ -1,9 +1,11 @@ -{count}
- diff --git a/test/cases/shared-syntax-merge.vim b/test/cases/shared-syntax-merge.vim new file mode 100644 index 0000000..7a7895a --- /dev/null +++ b/test/cases/shared-syntax-merge.vim @@ -0,0 +1,10 @@ +" Each key of syntax replaces the default of the same key, so style keeps +" css +let g:vim_svelte_plugin_config = {'syntax': {'script': ['typescript']}} +let g:test_flatten = 1 + +function! Check() + call ExpectBlock('let count', 'script', 'typescript', 'typescriptSvelteScript') + call ExpectBlock('{count}', 'template', 'html', 'htmlSvelteTemplate') + call ExpectBlock('color: red', 'style', 'css', 'cssSvelteStyle') +endfunction diff --git a/test/cases/shared-undo.svelte b/test/cases/shared-undo.svelte new file mode 100644 index 0000000..d87d760 --- /dev/null +++ b/test/cases/shared-undo.svelte @@ -0,0 +1 @@ +Hello
diff --git a/test/cases/shared-undo.vim b/test/cases/shared-undo.vim new file mode 100644 index 0000000..e5a91fd --- /dev/null +++ b/test/cases/shared-undo.vim @@ -0,0 +1,17 @@ +" Undo settings when filetype changes +let g:vim_svelte_plugin_config = {'foldexpr': 1} +packadd matchit + +function! Check() + call ExpectEqual(&l:foldmethod, 'expr', 'foldmethod') + call ExpectEqual(&l:indentexpr, 'GetSvelteIndent()', 'indentexpr') + call ExpectEqual(exists('b:match_words'), 1, 'b:match_words') + setlocal filetype=text + call ExpectEqual(&l:foldmethod, 'manual', 'foldmethod after undo') + call ExpectEqual(&l:indentexpr, '', 'indentexpr after undo') + call ExpectEqual(exists('b:match_words'), 0, 'b:match_words after undo') + call ExpectEqual(exists('b:syng_str'), 0, 'b:syng_str after undo') + if !has('nvim') + call ExpectEqual(&l:matchpairs, &g:matchpairs, 'matchpairs after undo') + endif +endfunction diff --git a/test/shared.sh b/test/shared.sh new file mode 100755 index 0000000..2518ab6 --- /dev/null +++ b/test/shared.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# List shared-* test cases missing in either vim-svelte-plugin or +# vim-vue-plugin. Both plugins work in the same way for blocks, so a case for +# a scenario in one plugin should be in the other with the same name. Only +# warn, as the other plugin may be updated later +# ./test/shared.sh +cd "$(dirname "$0")/.." || exit 1 +other=vim-vue-plugin + +dir=test/other/$other +rm -rf "$dir" +git clone -q --depth 1 "https://github.com/leafOfTree/$other" "$dir" || exit 0 + +list() { + ls "$1"/test/cases/shared-*.vim 2>/dev/null | sed 's#.*/##; s#\.vim$##' | sort +} +list . > test/other/mine +list "$dir" > test/other/theirs + +missing=0 +for name in $(comm -23 test/other/mine test/other/theirs); do + echo "::warning::$name is not in $other" + missing=1 +done +for name in $(comm -13 test/other/mine test/other/theirs); do + echo "::warning::$name in $other is not here" + missing=1 +done +[ $missing -eq 0 ] && echo "Shared cases are the same as $other" +exit 0