diff --git a/.github/workflows/vim.yml b/.github/workflows/vim.yml index 61eafd6..0cda98c 100644 --- a/.github/workflows/vim.yml +++ b/.github/workflows/vim.yml @@ -36,3 +36,9 @@ jobs: - name: 'Run test' run: | bash ./test/vader/run + + - name: 'Run new tests' + env: + MYVIM: vim -T dumb --not-a-term -n + run: | + cd ./test/new && make -j1 diff --git a/autoload/matchup/test.vim b/autoload/matchup/test.vim new file mode 100644 index 0000000..769ec70 --- /dev/null +++ b/autoload/matchup/test.vim @@ -0,0 +1,52 @@ +" vim match-up - even better matching +" +" Maintainer: Andy Massimino +" Email: a@normed.space +" + +function! matchup#test#assert(condition) abort " {{{1 + if a:condition | return 1 | endif + + call s:fail() +endfunction + +" }}}1 +function! matchup#test#assert_equal(expect, observe) abort " {{{1 + if a:expect ==# a:observe | return 1 | endif + + call s:fail([ + \ 'expect: ' . string(a:expect), + \ 'observe: ' . string(a:observe), + \]) +endfunction + +" }}}1 +function! matchup#test#assert_match(x, regex) abort " {{{1 + if a:x =~# a:regex | return 1 | endif + + call s:fail([ + \ 'x = ' . string(a:x), + \ 'regex = ' . a:regex, + \]) +endfunction + +" }}}1 + +function! s:fail(...) abort " {{{1 + echo 'Assertion failed!' + + if a:0 > 0 && !empty(a:1) + if type(a:1) == v:t_string + echo a:1 + else + for line in a:1 + echo line + endfor + endif + endif + echon "\n" + + cquit +endfunction + +" }}}1 diff --git a/test/new/Makefile b/test/new/Makefile new file mode 100644 index 0000000..1290b9d --- /dev/null +++ b/test/new/Makefile @@ -0,0 +1,31 @@ +MYVIM ?= nvim --headless +MAKEFLAGS+=--no-print-directory + +TESTS := $(wildcard test-*) + +.PHONY: test $(TESTS) + +test: $(TESTS) + +sysinfo: + @echo "**** SYSTEM INFORMATION ****" + @-git log -1 + @-$(MYVIM) --version + @echo "**** SYSTEM INFORMATION ****" + +$(TESTS): + $(MAKE) -C $@ + +coverage: htmlcov/index.html + +htmlcov/index.html: env /tmp/vim-profile.txt + . env/bin/activate + covimerage write_coverage /tmp/vim-profile.txt --source ../../autoload --source ../../plugin + coverage report -m + coverage html + +env: env/pyvenv.cfg + +env/pyvenv.cfg: + python3 -m venv env + bash -c 'source env/bin/activate; pip install "click<8.0.0" covimerage' diff --git a/test/new/common/bootstrap.vim b/test/new/common/bootstrap.vim new file mode 100644 index 0000000..1690469 --- /dev/null +++ b/test/new/common/bootstrap.vim @@ -0,0 +1,16 @@ +set packpath-=~/.vim packpath-=~/.vim/after +set packpath-=~/.config/nvim packpath-=~/.config/nvim/after +let &rtp = '../../..,' . &rtp +let &rtp = &rtp . ',../../../after' + +profile start /tmp/vim-profile.txt +profile! file */matchup/*.vim + +filetype plugin indent on +syntax enable + +let g:matchup_override_vimtex = 1 + +runtime! plugin/matchup.vim + +nnoremap q :qall! diff --git a/test/new/test-delim/Makefile b/test/new/test-delim/Makefile new file mode 100644 index 0000000..e52fd6d --- /dev/null +++ b/test/new/test-delim/Makefile @@ -0,0 +1,9 @@ +.PHONY: test + +MYVIM ?= nvim --headless + +INMAKE := 1 +export INMAKE + +test: + @$(MYVIM) -u test.vim diff --git a/test/new/test-delim/test.tex b/test/new/test-delim/test.tex new file mode 100644 index 0000000..2756da1 --- /dev/null +++ b/test/new/test-delim/test.tex @@ -0,0 +1,12 @@ +\[ +\begin{gathered} +First equation \\ +Second equation \\[1ex] +Third and last equation +\end{gathered} +\] + +\begin{a} + \begin{b} + \end{c} +\end{d} diff --git a/test/new/test-delim/test.vim b/test/new/test-delim/test.vim new file mode 100644 index 0000000..5ccefa5 --- /dev/null +++ b/test/new/test-delim/test.vim @@ -0,0 +1,21 @@ +set nocompatible +source ../common/bootstrap.vim + +let g:tex_flavor = "latex" + +silent edit test.tex + +call matchup#perf#timeout_start(0) + +normal! 7G +let s:current = matchup#delim#get_current('all', 'both') +let s:corresponding = matchup#delim#get_matching(s:current) +call matchup#test#assert_equal(1, s:corresponding[0].lnum) + +normal! 9G +let s:current = matchup#delim#get_current('all', 'both') +let s:corresponding = matchup#delim#get_matching(s:current) +call matchup#test#assert_equal(9, s:current.lnum) +call matchup#test#assert_equal(1, len(s:corresponding)) + +quit!