summaryrefslogtreecommitdiff
path: root/test/completion
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2018-07-16 17:57:07 +0100
committerw0rp <devw0rp@gmail.com>2018-07-16 17:57:07 +0100
commit37df1f8ceb97f19f4576c00c8146aad3a5a8a648 (patch)
treeb87047d5132f27ea15136ec6dec2f9e9751e0120 /test/completion
parentaa54c10bae015bddff02eecd88866c0cad007664 (diff)
downloadale-37df1f8ceb97f19f4576c00c8146aad3a5a8a648.zip
#1700 - Stop handling completion results if you leave insert mode
Diffstat (limited to 'test/completion')
-rw-r--r--test/completion/test_completion_events.vader42
-rw-r--r--test/completion/test_lsp_completion_messages.vader10
2 files changed, 52 insertions, 0 deletions
diff --git a/test/completion/test_completion_events.vader b/test/completion/test_completion_events.vader
index 96182013..504d79c2 100644
--- a/test/completion/test_completion_events.vader
+++ b/test/completion/test_completion_events.vader
@@ -8,6 +8,7 @@ Before:
let g:ale_completion_enabled = 1
let g:get_completions_called = 0
let g:feedkeys_calls = []
+ let g:fake_mode = 'i'
let &l:completeopt = 'menu,menuone,preview,noselect,noinsert'
@@ -17,6 +18,11 @@ Before:
call add(g:feedkeys_calls, [a:string, a:mode])
endfunction
+ " Pretend we're in insert mode for most tests.
+ function! ale#util#Mode(...) abort
+ return g:fake_mode
+ endfunction
+
function! CheckCompletionCalled(expect_success) abort
let g:get_completions_called = 0
@@ -35,6 +41,7 @@ Before:
After:
Restore
+ unlet! g:fake_mode
unlet! g:get_completions_called
unlet! b:ale_old_omnifunc
unlet! b:ale_old_completopt
@@ -49,6 +56,12 @@ After:
" This stops the tests from failing randomly.
call ale#completion#StopTimer()
+ " Reset the function. The runtime command below should fix this, but doesn't
+ " seem to fix it.
+ function! ale#util#Mode(...) abort
+ return call('mode', a:000)
+ endfunction
+
runtime autoload/ale/completion.vim
runtime autoload/ale/util.vim
@@ -78,6 +91,22 @@ Execute(ale#completion#GetCompletions should not be called when the cursor posit
Assert !g:get_completions_called
+Execute(ale#completion#GetCompletions should not be called if you switch to normal mode):
+ let &l:completeopt = 'menu,preview'
+ let g:fake_mode = 'n'
+
+ " We just want to check if the function is called.
+ function! ale#completion#GetCompletions()
+ let g:get_completions_called = 1
+ endfunction
+
+ let g:ale_completion_delay = 0
+ call ale#completion#Queue()
+
+ sleep 1m
+
+ Assert !g:get_completions_called
+
Execute(Completion should not be done shortly after the CompleteDone function):
call CheckCompletionCalled(1)
call ale#completion#Done()
@@ -128,6 +157,19 @@ Execute(ale#completion#Show() should make the correct feedkeys() call):
AssertEqual [["\<C-x>\<C-o>", 'n']], g:feedkeys_calls
+Execute(ale#completion#Show() shouldn't do anything if you switch back to normal mode):
+ let &l:completeopt = 'menu,preview'
+ let g:fake_mode = 'n'
+
+ call ale#completion#Show('Response', 'Parser')
+
+ AssertEqual 'menu,preview', &l:completeopt
+ Assert !exists('b:ale_old_omnifunc')
+ Assert !exists('b:ale_old_completopt')
+ Assert !exists('b:ale_completion_response')
+ Assert !exists('b:ale_completion_parser')
+ AssertEqual [], g:feedkeys_calls
+
Execute(ale#completion#Show() should set up the response and parser):
call ale#completion#Show('Response', 'Parser')
diff --git a/test/completion/test_lsp_completion_messages.vader b/test/completion/test_lsp_completion_messages.vader
index e5aac176..00a174dc 100644
--- a/test/completion/test_lsp_completion_messages.vader
+++ b/test/completion/test_lsp_completion_messages.vader
@@ -30,6 +30,11 @@ Before:
\}
endfunction
+ " Pretend we're in insert mode for most tests.
+ function! ale#util#Mode(...) abort
+ return 'i'
+ endfunction
+
" Replace the Send function for LSP, so we can monitor calls to it.
function! ale#lsp#Send(conn_id, message, ...) abort
call add(g:message_list, a:message)
@@ -49,6 +54,11 @@ After:
unlet! b:ale_linters
unlet! b:ale_tsserver_completion_names
+ " Reset the function.
+ function! ale#util#Mode(...) abort
+ return call('mode', a:000)
+ endfunction
+
call ale#lsp#RemoveConnectionWithID(347)
call ale#test#RestoreDirectory()
call ale#linter#Reset()