1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'latex') == -1
" vimtex - LaTeX plugin for Vim
"
" Maintainer: Karl Yngve Lervåg
" Email: karl.yngve@gmail.com
"
function! vimtex#test#assert(condition) abort " {{{1
if a:condition | return 1 | endif
call s:fail()
endfunction
" }}}1
function! vimtex#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! vimtex#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! vimtex#test#completion(context, ...) abort " {{{1
let l:base = a:0 > 0 ? a:1 : ''
try
silent execute 'normal GO' . a:context . "\<c-x>\<c-o>"
silent normal! u
return vimtex#complete#omnifunc(0, l:base)
catch /.*/
call s:fail(v:exception)
endtry
endfunction
" }}}1
function! vimtex#test#keys(keys, context, expected) abort " {{{1
normal! gg0dG
call append(1, a:context)
normal! ggdd
let l:fail_msg = ['keys: ' . a:keys]
let l:fail_msg += ['context:']
let l:fail_msg += map(copy(a:context), '" " . v:val')
let l:fail_msg += ['expected:']
let l:fail_msg += map(copy(a:expected), '" " . v:val')
try
silent execute 'normal' a:keys
catch
let l:fail_msg += ['error:']
let l:fail_msg += [' ' . v:exception]
call s:fail(l:fail_msg)
endtry
let l:result = getline(1, line('$'))
if l:result ==# a:expected | return 1 | endif
let l:fail_msg += ['result:']
let l:fail_msg += map(l:result, '" " . v:val')
call s:fail(l:fail_msg)
endfunction
" }}}1
function! s:fail(...) abort " {{{1
echo 'Assertion failed!'
if a:0 > 0 && !empty(a:1)
if type(a:1) == type('')
echo a:1
else
for line in a:1
echo line
endfor
endif
endif
echon "\n"
cquit
endfunction
" }}}1
endif
|