ccomplete_spec.lua 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. local t = require('test.testutil')
  2. local n = require('test.functional.testnvim')()
  3. local clear = n.clear
  4. local command = n.command
  5. local eq = t.eq
  6. local eval = n.eval
  7. local feed = n.feed
  8. local write_file = t.write_file
  9. describe('ccomplete#Complete', function()
  10. setup(function()
  11. -- Realistic tags generated from neovim source tree using `ctags -R *`
  12. write_file(
  13. 'Xtags',
  14. [[
  15. augroup_del src/nvim/autocmd.c /^void augroup_del(char *name, bool stupid_legacy_mode)$/;" f typeref:typename:void
  16. augroup_exists src/nvim/autocmd.c /^bool augroup_exists(const char *name)$/;" f typeref:typename:bool
  17. augroup_find src/nvim/autocmd.c /^int augroup_find(const char *name)$/;" f typeref:typename:int
  18. aupat_get_buflocal_nr src/nvim/autocmd.c /^int aupat_get_buflocal_nr(char *pat, int patlen)$/;" f typeref:typename:int
  19. aupat_is_buflocal src/nvim/autocmd.c /^bool aupat_is_buflocal(char *pat, int patlen)$/;" f typeref:typename:bool
  20. expand_get_augroup_name src/nvim/autocmd.c /^char *expand_get_augroup_name(expand_T *xp, int idx)$/;" f typeref:typename:char *
  21. expand_get_event_name src/nvim/autocmd.c /^char *expand_get_event_name(expand_T *xp, int idx)$/;" f typeref:typename:char *
  22. ]]
  23. )
  24. end)
  25. before_each(function()
  26. clear()
  27. command('set tags=Xtags')
  28. end)
  29. teardown(function()
  30. os.remove('Xtags')
  31. end)
  32. it('can complete from Xtags', function()
  33. local completed = eval('ccomplete#Complete(0, "a")')
  34. eq(5, #completed)
  35. eq('augroup_del(', completed[1].word)
  36. eq('f', completed[1].kind)
  37. local aupat = eval('ccomplete#Complete(0, "aupat")')
  38. eq(2, #aupat)
  39. eq('aupat_get_buflocal_nr(', aupat[1].word)
  40. eq('f', aupat[1].kind)
  41. end)
  42. it('does not error when returning no matches', function()
  43. local completed = eval('ccomplete#Complete(0, "doesnotmatch")')
  44. eq({}, completed)
  45. end)
  46. it('can find the beginning of a word for C', function()
  47. command('set filetype=c')
  48. feed('i int something = augroup')
  49. local result = eval('ccomplete#Complete(1, "")')
  50. eq(#' int something = ', result)
  51. local completed = eval('ccomplete#Complete(0, "augroup")')
  52. eq(3, #completed)
  53. end)
  54. end)