Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ test.svelte
.idea
test/deps/
doc/tags
test/other/
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion indent/svelte.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '^<$'
Expand Down
7 changes: 0 additions & 7 deletions test/cases/lang-attr.vim

This file was deleted.

10 changes: 10 additions & 0 deletions test/cases/shared-empty-tag.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<div>
<input bind:value={name} on:input={(e) => update(e)} />
<p>x</p>
<input type="text">
<p>y</p>
<img src="a.png" alt="a" />
<p>z</p>
<input class={a > b ? 'a' : 'b'}>
<p>w</p>
</div>
7 changes: 7 additions & 0 deletions test/cases/shared-empty-tag.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
" Empty tags like <input> with or without '/>', and '>' in attribute
" expressions
let g:test_flatten = 1

function! Check()
call ExpectIndentEachLine()
endfunction
15 changes: 15 additions & 0 deletions test/cases/shared-initial-indent.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
let a = 1;
</script>

<style lang="scss">
p {
color: red;
}
</style>

<style>
p {
color: blue;
}
</style>
10 changes: 10 additions & 0 deletions test/cases/shared-initial-indent.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
" initial_indent by tag.syntax, not for other syntax in the same tag
let g:vim_svelte_plugin_config = {
\ 'syntax': {'style': ['css', 'scss']},
\ 'initial_indent': ['style.scss'],
\}
let g:test_flatten = 1

function! Check()
call ExpectIndentEachLine()
endfunction
17 changes: 17 additions & 0 deletions test/cases/shared-lang-attr.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<script lang='ts'>
let count: number = 0;
</script>

<script lang=ts>
let a: number = 1;
</script>

<script lang="typescript">
let b: number = 2;
</script>

<p>{count}</p>

<style lang=scss>
$a: 1px;
</style>
9 changes: 9 additions & 0 deletions test/cases/shared-lang-attr.vim
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script lang='ts'>
<script>
let count: number = 0;
</script>

<p>{count}</p>

<style lang=scss>
$a: 1px;
<style>
p {
color: red;
}
</style>
10 changes: 10 additions & 0 deletions test/cases/shared-syntax-merge.vim
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/cases/shared-undo.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Hello</p>
17 changes: 17 additions & 0 deletions test/cases/shared-undo.vim
Original file line number Diff line number Diff line change
@@ -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
30 changes: 30 additions & 0 deletions test/shared.sh
Original file line number Diff line number Diff line change
@@ -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
Loading