~ubuntu-branches/debian/sid/neovim/sid

« back to all changes in this revision

Viewing changes to test/functional/legacy/011_autocommands_spec.lua

  • Committer: Package Import Robot
  • Author(s): James McCoy
  • Date: 2016-04-18 21:42:19 UTC
  • mfrom: (1.1.2)
  • Revision ID: package-import@ubuntu.com-20160418214219-1e6d4o1fwqarzk46
Tags: 0.1.3-1
* New upstream release.  (Closes: #820562)
* debian/control:
  + Remove unnecessary luarocks Build-Depends
  + Add libkvm-dev Build-Depends for kfreebsd-*
  + Add python(3)-neovim to Recommends.  (Closes: #812737)
  + Declare compiance with policy 3.9.8, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-- Tests for autocommands
 
2
-- - FileWritePre               writing a compressed file
 
3
-- - FileReadPost               reading a compressed file
 
4
-- - BufNewFile                 reading a file template
 
5
-- - BufReadPre                 decompressing the file to be read
 
6
-- - FilterReadPre              substituting characters in the temp file
 
7
-- - FilterReadPost             substituting characters after filtering
 
8
-- - FileReadPre                set options for decompression
 
9
-- - FileReadPost               decompress the file
 
10
-- Note: This test is skipped if "gzip" is not available.
 
11
-- $GZIP is made empty, "-v" would cause trouble.
 
12
-- Use a FileChangedShell autocommand to avoid a prompt for "Xtestfile.gz"
 
13
-- being modified outside of Vim (noticed on Solaris).
 
14
 
 
15
local helpers, lfs = require('test.functional.helpers'), require('lfs')
 
16
local clear, execute, expect, eq, neq, dedent, write_file, feed =
 
17
  helpers.clear, helpers.execute, helpers.expect, helpers.eq, helpers.neq,
 
18
  helpers.dedent, helpers.write_file, helpers.feed
 
19
 
 
20
local function has_gzip()
 
21
  return os.execute('gzip --help >/dev/null 2>&1') == 0
 
22
end
 
23
 
 
24
local function prepare_gz_file(name, text)
 
25
  write_file(name, text..'\n')
 
26
  -- Compress the file with gzip.
 
27
  os.execute('gzip --force '..name)
 
28
  -- This should create the .gz file and delete the original.
 
29
  neq(nil, lfs.attributes(name..'.gz'))
 
30
  eq(nil, lfs.attributes(name))
 
31
end
 
32
 
 
33
describe('file reading, writing and bufnew and filter autocommands', function()
 
34
  local text1 = dedent([[
 
35
      start of testfile
 
36
      line 2    Abcdefghijklmnopqrstuvwxyz
 
37
      line 3    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
38
      line 4    Abcdefghijklmnopqrstuvwxyz
 
39
      line 5    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
40
      line 6    Abcdefghijklmnopqrstuvwxyz
 
41
      line 7    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
42
      line 8    Abcdefghijklmnopqrstuvwxyz
 
43
      line 9    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
44
      line 10 Abcdefghijklmnopqrstuvwxyz
 
45
      end of testfile]])
 
46
  setup(function()
 
47
    write_file('Xtest.c', [[
 
48
      /*
 
49
       * Here is a new .c file
 
50
       */
 
51
      ]])
 
52
  end)
 
53
  before_each(clear)
 
54
  teardown(function()
 
55
    os.remove('Xtestfile.gz')
 
56
    os.remove('Xtest.c')
 
57
    os.remove('test.out')
 
58
  end)
 
59
 
 
60
  if not has_gzip() then
 
61
    pending('skipped (missing `gzip` utility)', function() end)
 
62
  else
 
63
 
 
64
    it('FileReadPost (using gzip)', function()
 
65
      prepare_gz_file('Xtestfile', text1)
 
66
      execute('let $GZIP = ""')
 
67
      --execute('au FileChangedShell * echo "caught FileChangedShell"')
 
68
      execute('set bin')
 
69
      execute("au FileReadPost    *.gz   '[,']!gzip -d")
 
70
      -- Read and decompress the testfile.
 
71
      execute('$r Xtestfile.gz')
 
72
      expect('\n'..text1)
 
73
    end)
 
74
 
 
75
    it('BufReadPre, BufReadPost (using gzip)', function()
 
76
      prepare_gz_file('Xtestfile', text1)
 
77
      local gzip_data = io.open('Xtestfile.gz'):read('*all')
 
78
      execute('let $GZIP = ""')
 
79
      -- Setup autocommands to decompress before reading and re-compress afterwards.
 
80
      execute("au BufReadPre   *.gz  exe '!gzip -d ' . shellescape(expand('<afile>'))")
 
81
      execute("au BufReadPre   *.gz  call rename(expand('<afile>:r'), expand('<afile>'))")
 
82
      execute("au BufReadPost  *.gz  call rename(expand('<afile>'), expand('<afile>:r'))")
 
83
      execute("au BufReadPost  *.gz  exe '!gzip ' . shellescape(expand('<afile>:r'))")
 
84
      -- Edit compressed file.
 
85
      execute('e! Xtestfile.gz')
 
86
      -- Discard all prompts and messages.
 
87
      feed('<C-L>')
 
88
      -- Expect the decompressed file in the buffer.
 
89
      expect(text1)
 
90
      -- Expect the original file to be unchanged.
 
91
      eq(gzip_data, io.open('Xtestfile.gz'):read('*all'))
 
92
    end)
 
93
 
 
94
    it('FileReadPre, FileReadPost', function()
 
95
      prepare_gz_file('Xtestfile', text1)
 
96
      execute('au! FileReadPre    *.gz   exe "silent !gzip -d " . shellescape(expand("<afile>"))')
 
97
      execute('au  FileReadPre    *.gz   call rename(expand("<afile>:r"), expand("<afile>"))')
 
98
      execute("au! FileReadPost   *.gz   '[,']s/l/L/")
 
99
      -- Read compressed file.
 
100
      execute('$r Xtestfile.gz')
 
101
      -- Discard all prompts and messages.
 
102
      feed('<C-L>')
 
103
      expect([[
 
104
        
 
105
        start of testfiLe
 
106
        Line 2  Abcdefghijklmnopqrstuvwxyz
 
107
        Line 3  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
108
        Line 4  Abcdefghijklmnopqrstuvwxyz
 
109
        Line 5  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
110
        Line 6  Abcdefghijklmnopqrstuvwxyz
 
111
        Line 7  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
112
        Line 8  Abcdefghijklmnopqrstuvwxyz
 
113
        Line 9  xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
114
        Line 10 Abcdefghijklmnopqrstuvwxyz
 
115
        end of testfiLe]])
 
116
    end)
 
117
 
 
118
  end
 
119
 
 
120
  it('FileAppendPre, FileAppendPost', function()
 
121
    execute('au BufNewFile      *.c    read Xtest.c')
 
122
    -- Will load Xtest.c.
 
123
    execute('e! foo.c')
 
124
    execute("au FileAppendPre   *.out  '[,']s/new/NEW/")
 
125
    execute('au FileAppendPost  *.out  !cat Xtest.c >>test.out')
 
126
    -- Append it to the output file.
 
127
    execute('w>>test.out')
 
128
    -- Discard all prompts and messages.
 
129
    feed('<C-L>')
 
130
    -- Expect the decompressed file in the buffer.
 
131
    execute('e test.out')
 
132
    expect([[
 
133
      
 
134
      /*
 
135
       * Here is a NEW .c file
 
136
       */]])
 
137
  end)
 
138
 
 
139
  it('FilterReadPre, FilterReadPost', function()
 
140
    -- Write a special input file for this test block.
 
141
    write_file('test.out', dedent([[
 
142
      startstart
 
143
      ]]) .. text1 .. dedent([[
 
144
      
 
145
      
 
146
      start of test.c
 
147
      /*
 
148
       * Here is a new .c file
 
149
       */
 
150
      end of test.c
 
151
      ]]) .. text1 .. dedent([[
 
152
      
 
153
      
 
154
      /*
 
155
       * Here is a NEW .c file
 
156
       */
 
157
      /*
 
158
       * Here is a new .c file
 
159
       */
 
160
      ]]) .. text1 .. dedent([[
 
161
      
 
162
      /*
 
163
       * Here is a new .c file
 
164
       */]]))
 
165
    -- Need temp files here.
 
166
    execute('set shelltemp')
 
167
    execute('au FilterReadPre   *.out  call rename(expand("<afile>"), expand("<afile>") . ".t")')
 
168
    execute('au FilterReadPre   *.out  exe "silent !sed s/e/E/ " . shellescape(expand("<afile>")) . ".t >" . shellescape(expand("<afile>"))')
 
169
    execute('au FilterReadPre   *.out  exe "silent !rm " . shellescape(expand("<afile>")) . ".t"')
 
170
    execute("au FilterReadPost  *.out  '[,']s/x/X/g")
 
171
    -- Edit the output file.
 
172
    execute('e! test.out')
 
173
    execute('23,$!cat')
 
174
    -- Discard all prompts and messages.
 
175
    feed('<C-L>')
 
176
    -- Remove CR for when sed adds them.
 
177
    execute([[23,$s/\r$//]])
 
178
    expect([[
 
179
      startstart
 
180
      start of testfile
 
181
      line 2    Abcdefghijklmnopqrstuvwxyz
 
182
      line 3    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
183
      line 4    Abcdefghijklmnopqrstuvwxyz
 
184
      line 5    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
185
      line 6    Abcdefghijklmnopqrstuvwxyz
 
186
      line 7    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
187
      line 8    Abcdefghijklmnopqrstuvwxyz
 
188
      line 9    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
189
      line 10 Abcdefghijklmnopqrstuvwxyz
 
190
      end of testfile
 
191
      
 
192
      start of test.c
 
193
      /*
 
194
       * Here is a new .c file
 
195
       */
 
196
      end of test.c
 
197
      start of testfile
 
198
      line 2    Abcdefghijklmnopqrstuvwxyz
 
199
      line 3    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
 
200
      line 4    Abcdefghijklmnopqrstuvwxyz
 
201
      linE 5    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
202
      linE 6    AbcdefghijklmnopqrstuvwXyz
 
203
      linE 7    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
204
      linE 8    AbcdefghijklmnopqrstuvwXyz
 
205
      linE 9    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
206
      linE 10 AbcdefghijklmnopqrstuvwXyz
 
207
      End of testfile
 
208
      
 
209
      /*
 
210
       * HEre is a NEW .c file
 
211
       */
 
212
      /*
 
213
       * HEre is a new .c file
 
214
       */
 
215
      start of tEstfile
 
216
      linE 2    AbcdefghijklmnopqrstuvwXyz
 
217
      linE 3    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
218
      linE 4    AbcdefghijklmnopqrstuvwXyz
 
219
      linE 5    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
220
      linE 6    AbcdefghijklmnopqrstuvwXyz
 
221
      linE 7    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
222
      linE 8    AbcdefghijklmnopqrstuvwXyz
 
223
      linE 9    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
224
      linE 10 AbcdefghijklmnopqrstuvwXyz
 
225
      End of testfile
 
226
      /*
 
227
       * HEre is a new .c file
 
228
       */]])
 
229
  end)
 
230
end)