aboutsummaryrefslogtreecommitdiff
path: root/test/functional/legacy/076_completefunc_spec.lua
blob: 8af3be003e6958c2bf3efe6faad4d6496658a0c1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
-- Tests for completefunc/omnifunc.

local helpers = require('test.functional.helpers')
local feed, insert, source = helpers.feed, helpers.insert, helpers.source
local clear, expect, execute = helpers.clear, helpers.expect, helpers.execute

describe('completefunc', function()
  setup(clear)

  it('is working', function()
    insert([=[
      +++
      one
      two
      three]=])

    -- Test that nothing happens if the 'completefunc' opens
    -- a new window (no completion, no crash).
    source([=[
      function! DummyCompleteOne(findstart, base)
        if a:findstart
          return 0
        else
          wincmd n
          return ['onedef', 'oneDEF']
        endif
      endfunction
      setlocal completefunc=DummyCompleteOne
      /^one
    ]=])
    feed('A<C-X><C-U><C-N><esc>')
    execute('q!')
    source([=[
      function! DummyCompleteTwo(findstart, base)
        if a:findstart
          wincmd n
          return 0
        else
          return ['twodef', 'twoDEF']
        endif
      endfunction
      setlocal completefunc=DummyCompleteTwo
      /^two
    ]=])
    feed('A<C-X><C-U><C-N><esc>')
    execute('q!')
    -- Test that 'completefunc' works when it's OK.
    source([=[
      function! DummyCompleteThree(findstart, base)
        if a:findstart
          return 0
        else
          return ['threedef', 'threeDEF']
        endif
      endfunction
      setlocal completefunc=DummyCompleteThree
      /^three
    ]=])
    feed('A<C-X><C-U><C-N><esc>')

    -- Assert buffer contents.
    expect([=[
      +++
      
      two
      threeDEF]=])
  end)
end)