While writing tests for my completion plugin (MUcomplete), I have
encountered some difficulty related to testing the auto-completion
functionality, which I try to reproduce below without my plugin, using
only core Vim commands.

I am not sure I have found the culprit yet, but I would appreciate if
someone could help me figure out the results of the following tests:

fun! s:act_on_pumvisible()
  if pumvisible()
    return "\<c-p>"
  else
    return "X"
  endif
endf

let s:char_pressed = 0

fun! s:act_on_textchangedi()
  if s:char_pressed
    let s:char_pressed = 0
    call feedkeys("\<c-x>\<c-n>", 'i')
  endif
endf

fun! Test_FOO_test_autocomplete_h_ctrlp()
  set completeopt=menu,noselect
  new
  autocmd! InsertCharPre <buffer> let s:char_pressed = (v:char ==# 'h')
  autocmd! TextChangedI <buffer> call <sid>act_on_textchangedi()
  call setline(1,  ['hoard', 'hoax', 'hoarse', ''])
  let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax', 'hoax']
  call cursor(4,1)
  call test_override("char_avail", 1)
  call feedkeys("Ah\<c-p>\<c-p>\<c-y>\<esc>", 'tx')
  call feedkeys("oho\<c-p>\<c-p>\<c-y>\<esc>", 'tx')
  call assert_equal(l:expected, getline(1,'$'))
  call test_override("char_avail", 0)
  bwipe!
  set completeopt&
endf


fun! Test_FOO_test_autocomplete_o_ctrlp()
  set completeopt=menu,noselect
  new
  autocmd! InsertCharPre <buffer> let s:char_pressed = (v:char ==# 'o')
  autocmd! TextChangedI <buffer> call <sid>act_on_textchangedi()
  call setline(1,  ['hoard', 'hoax', 'hoarse', ''])
  let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax']
  call cursor(4,1)
  call test_override("char_avail", 1)
  call feedkeys("Aho\<c-p>\<c-p>\<c-y>\<esc>", 'tx')
  call assert_equal(l:expected, getline(1,'$'))
  call test_override("char_avail", 0)
  bwipe!
  set completeopt&
endf

fun! Test_FOO_test_complete_h_tab()
  set completeopt=menu,noselect
  new
  imap <expr> <buffer> <tab> <sid>act_on_pumvisible()
  autocmd! InsertCharPre <buffer> let s:char_pressed = (v:char ==# 'h')
  autocmd! TextChangedI <buffer> call <sid>act_on_textchangedi()
  call setline(1,  ['hoard', 'hoax', 'hoarse', ''])
  let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax']
  call cursor(4,1)
  call test_override("char_avail", 1)
  call feedkeys("Ah\<tab>\<tab>\<c-y>\<esc>", 'tx')
  call feedkeys("oho\<tab>\<tab>\<c-y>\<esc>", 'tx')
  call assert_equal(l:expected, getline(1,'$'))
  call test_override("char_avail", 0)
  bwipe!
  set completeopt&
endf

fun! Test_FOO_test_complete_o_tab()
  set completeopt=menu,noselect
  new
  imap <expr> <buffer> <tab> <sid>act_on_pumvisible()
  autocmd! InsertCharPre <buffer> let s:char_pressed = (v:char ==# 'o')
  autocmd! TextChangedI <buffer> call <sid>act_on_textchangedi()
  call setline(1,  ['hoard', 'hoax', 'hoarse', ''])
  let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax']
  call cursor(4,1)
  call test_override("char_avail", 1)
  call feedkeys("Aho\<tab>\<tab>\<c-y>\<esc>", 'tx')
  call assert_equal(l:expected, getline(1,'$'))
  call test_override("char_avail", 0)
  bwipe!
  set completeopt&
endf

fun! Test_FOO_test_complete_ho_tab()
  set completeopt=menu,noselect
  new
  imap <expr> <buffer> <tab> <sid>act_on_pumvisible()
  autocmd! InsertCharPre <buffer> let s:char_pressed = (v:char ==# 'h')
  autocmd! TextChangedI <buffer> call <sid>act_on_textchangedi()
  call setline(1,  ['hoard', 'hoax', 'hoarse', ''])
  let l:expected = ['hoard', 'hoax', 'hoarse', 'hoax']
  call cursor(4,1)
  call test_override("char_avail", 1)
  call feedkeys("Aho\<tab>\<tab>\<c-y>\<esc>", 'tx')
  call assert_equal(l:expected, getline(1,'$'))
  call test_override("char_avail", 0)
  bwipe!
  set completeopt&
endf

The result is:


Test_FOO_test_autocomplete_h_ctrlp()… ok
Test_FOO_test_autocomplete_o_ctrlp()… ok
Test_FOO_test_complete_h_tab()… FAILED
Test_FOO_test_complete_ho_tab()… ok
Test_FOO_test_complete_o_tab()… FAILED

Run 5 tests
2 tests failed

Test_FOO_test_complete_h_tab()
function RunBabyRun[8]..RunTheTest[4]..Test_FOO_test_complete_h_tab line 12: Expected ['hoard', 'hoax', 'hoarse', 'hoax'] but got ['hoard', 'hoax', 'hoarse', 'hXXr', 'hoax']
Test_FOO_test_complete_o_tab()
function RunBabyRun[8]..RunTheTest[4]..Test_FOO_test_complete_o_tab line 11: Expected ['hoard', 'hoax', 'hoarse', 'hoax'] but got ['hoard', 'hoax', 'hoarse', 'hoXXs']

For the life of me (pun intended), I don't understand why those two
tests fail... Any idea?

Thanks,
Life.





--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to vim_use+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to