Add autocomplete test

Fixes #23 Write tests for autocompletion
This commit is contained in:
baabelfish 2016-03-17 01:00:16 +02:00
commit 10bd41db5a
3 changed files with 40 additions and 4 deletions

View file

@ -27,14 +27,14 @@ endfunction
function! omni#nimsuggest(file, l, c)
let completions = []
let tempfile = util#WriteMemfile()
let query = "sug " . a:file . ";" . tempfile . ":" . a:l . ":" . a:c
let jobcmdstr = g:nvim_nim_exec_nimsuggest . " --threads:on --colors:off --compileOnly --experimental --v2 --stdin " . a:file
let fullcmd = 'echo -e "' . query . '"|' . jobcmdstr
let completions_raw = util#FilterCompletions(split(system(fullcmd), "\n"))
for line in completions_raw
call add(completions, omni#item(util#ParseV2(line)))
let parsed = util#ParseV2(line)
call add(completions, omni#item(parsed))
endfor
return completions
@ -49,9 +49,27 @@ function! omni#modulesuggest(file, l, c)
return completions
endfunction
function! s:findStart()
let pos = col(".")
let cline = getline(".")
while pos > 1
let ch = char2nr(cline[pos - 2])
if !((48 <= ch && ch <= 57)
\ || (65 <= ch && ch <= 90)
\ || (97 <= ch && ch <= 122)
\ || ch == 95)
break
endif
let pos = pos - 1
endwhile
return pos - 1
endfunction
function! omni#nim(findstart, base)
if a:findstart && empty(a:base)
return col('.')
return s:findStart()
endif
let completions = []

View file

@ -0,0 +1,12 @@
Given nim:
5.
Execute:
set buftype=
saveas! autocomplete.nim
Do:
A\<c-x>\<c-o>\<c-n>\<esc>
Expect:
5.alloc

View file

@ -7,9 +7,15 @@ Given nim:
Execute:
set buftype=""
saveas! vader_workbench.nim
w!
norm G^
NimDefinition
Then:
AssertEqual 2, line(".")
Do:
G^
\<c-]>
Then:
AssertEqual 2, line(".")