HEX
Server: Apache/2.4.41 (Ubuntu)
System: Linux ip-172-31-42-149 5.15.0-1084-aws #91~20.04.1-Ubuntu SMP Fri May 2 07:00:04 UTC 2025 aarch64
User: ubuntu (1000)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //home/ubuntu/neovim/test/functional/plugin/ccomplete_spec.lua
local t = require('test.testutil')
local n = require('test.functional.testnvim')()

local clear = n.clear
local command = n.command
local eq = t.eq
local eval = n.eval
local feed = n.feed
local write_file = t.write_file

describe('ccomplete#Complete', function()
  setup(function()
    -- Realistic tags generated from neovim source tree using `ctags -R *`
    write_file(
      'Xtags',
      [[
augroup_del	src/nvim/autocmd.c	/^void augroup_del(char *name, bool stupid_legacy_mode)$/;"	f	typeref:typename:void
augroup_exists	src/nvim/autocmd.c	/^bool augroup_exists(const char *name)$/;"	f	typeref:typename:bool
augroup_find	src/nvim/autocmd.c	/^int augroup_find(const char *name)$/;"	f	typeref:typename:int
aupat_get_buflocal_nr	src/nvim/autocmd.c	/^int aupat_get_buflocal_nr(char *pat, int patlen)$/;"	f	typeref:typename:int
aupat_is_buflocal	src/nvim/autocmd.c	/^bool aupat_is_buflocal(char *pat, int patlen)$/;"	f	typeref:typename:bool
expand_get_augroup_name	src/nvim/autocmd.c	/^char *expand_get_augroup_name(expand_T *xp, int idx)$/;"	f	typeref:typename:char *
expand_get_event_name	src/nvim/autocmd.c	/^char *expand_get_event_name(expand_T *xp, int idx)$/;"	f	typeref:typename:char *
]]
    )
  end)

  before_each(function()
    clear()
    command('set tags=Xtags')
  end)

  teardown(function()
    os.remove('Xtags')
  end)

  it('can complete from Xtags', function()
    local completed = eval('ccomplete#Complete(0, "a")')
    eq(5, #completed)
    eq('augroup_del(', completed[1].word)
    eq('f', completed[1].kind)

    local aupat = eval('ccomplete#Complete(0, "aupat")')
    eq(2, #aupat)
    eq('aupat_get_buflocal_nr(', aupat[1].word)
    eq('f', aupat[1].kind)
  end)

  it('does not error when returning no matches', function()
    local completed = eval('ccomplete#Complete(0, "doesnotmatch")')
    eq({}, completed)
  end)

  it('can find the beginning of a word for C', function()
    command('set filetype=c')
    feed('i  int something = augroup')
    local result = eval('ccomplete#Complete(1, "")')
    eq(#'  int something = ', result)

    local completed = eval('ccomplete#Complete(0, "augroup")')
    eq(3, #completed)
  end)
end)