aboutsummaryrefslogtreecommitdiff
path: root/test/functional/autocmd/show_spec.lua
blob: 505bed834bc84dab9b7fe04bbe9fa4a1a997bf37 (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
local helpers = require('test.functional.helpers')(after_each)
local Screen = require('test.functional.ui.screen')

local clear = helpers.clear
local command = helpers.command
local dedent = helpers.dedent
local eq = helpers.eq
local funcs = helpers.funcs
local eval = helpers.eval
local exec = helpers.exec
local feed = helpers.feed

describe(":autocmd", function()
  before_each(function()
    clear({'-u', 'NONE'})
  end)

  it("should not segfault when you just do autocmd", function()
    command ":autocmd"
  end)

  it("should filter based on ++once", function()
    command "autocmd! BufEnter"
    command "autocmd BufEnter * :echo 'Hello'"
    command [[augroup TestingOne]]
    command [[  autocmd BufEnter * :echo "Line 1"]]
    command [[  autocmd BufEnter * :echo "Line 2"]]
    command [[augroup END]]

    eq(dedent([[

       --- Autocommands ---
       BufEnter
           *         :echo 'Hello'
       TestingOne  BufEnter
           *         :echo "Line 1"
                     :echo "Line 2"]]),
       funcs.execute('autocmd BufEnter'))
  end)

  it('should not show group information if interrupted', function()
    local screen = Screen.new(50, 6)
    screen:set_default_attr_ids({
      [1] = {bold = true, foreground = Screen.colors.Blue1},  -- NonText
      [2] = {bold = true, foreground = Screen.colors.SeaGreen},  -- MoreMsg
      [3] = {bold = true, foreground = Screen.colors.Magenta},  -- Title
    })
    screen:attach()
    exec([[
      set more
      autocmd! BufEnter
      augroup test_1
        autocmd BufEnter A echo 'A'
        autocmd BufEnter B echo 'B'
        autocmd BufEnter C echo 'C'
        autocmd BufEnter D echo 'D'
        autocmd BufEnter E echo 'E'
        autocmd BufEnter F echo 'F'
      augroup END
      autocmd! BufLeave
      augroup test_1
        autocmd BufLeave A echo 'A'
        autocmd BufLeave B echo 'B'
        autocmd BufLeave C echo 'C'
        autocmd BufLeave D echo 'D'
        autocmd BufLeave E echo 'E'
        autocmd BufLeave F echo 'F'
      augroup END
    ]])
    feed(':autocmd<CR>')
    screen:expect([[
      :autocmd                                          |
      {3:--- Autocommands ---}                              |
      {3:test_1}  {3:BufEnter}                                  |
          A         echo 'A'                            |
          B         echo 'B'                            |
      {2:-- More --}^                                        |
    ]])
    feed('q')
    screen:expect([[
      ^                                                  |
      {1:~                                                 }|
      {1:~                                                 }|
      {1:~                                                 }|
      {1:~                                                 }|
                                                        |
    ]])
  end)

  it('should not show group information for deleted pattern', function()
    exec([[
      autocmd! BufEnter
      augroup test_1
        autocmd BufEnter A echo 'A'
        autocmd BufEnter B echo 'B'
        autocmd BufEnter C echo 'C'
      augroup END
      augroup test_2
        autocmd BufEnter foo echo 'foo'
      augroup END
      augroup test_3
        autocmd BufEnter D echo 'D'
        autocmd BufEnter E echo 'E'
        autocmd BufEnter F echo 'F'
      augroup END

      func Func()
        autocmd! test_2 BufEnter
        let g:output = execute('autocmd BufEnter')
      endfunc

      autocmd User foo call Func()
      doautocmd User foo
    ]])
    eq(dedent([[

      --- Autocommands ---
      test_1  BufEnter
          A         echo 'A'
          B         echo 'B'
          C         echo 'C'
      test_3  BufEnter
          D         echo 'D'
          E         echo 'E'
          F         echo 'F']]), eval('g:output'))
  end)

  it('can filter by pattern #17973', function()
    exec([[
      autocmd! BufEnter
      autocmd! User
      augroup test_1
        autocmd BufEnter A echo "A1"
        autocmd BufEnter B echo "B1"
        autocmd User A echo "A1"
        autocmd User B echo "B1"
      augroup END
      augroup test_2
        autocmd BufEnter A echo "A2"
        autocmd BufEnter B echo "B2"
        autocmd User A echo "A2"
        autocmd User B echo "B2"
      augroup END
      augroup test_3
        autocmd BufEnter A echo "A3"
        autocmd BufEnter B echo "B3"
        autocmd User A echo "A3"
        autocmd User B echo "B3"
      augroup END
    ]])
    eq(dedent([[

      --- Autocommands ---
      test_1  User
          A         echo "A1"
      test_2  User
          A         echo "A2"
      test_3  User
          A         echo "A3"]]), funcs.execute('autocmd User A'))
    eq(dedent([[

      --- Autocommands ---
      test_1  BufEnter
          B         echo "B1"
      test_2  BufEnter
          B         echo "B2"
      test_3  BufEnter
          B         echo "B3"
      test_1  User
          B         echo "B1"
      test_2  User
          B         echo "B2"
      test_3  User
          B         echo "B3"]]), funcs.execute('autocmd * B'))
    eq(dedent([[

      --- Autocommands ---
      test_3  BufEnter
          B         echo "B3"
      test_3  User
          B         echo "B3"]]), funcs.execute('autocmd test_3 * B'))
  end)
end)