summaryrefslogtreecommitdiffstatshomepage
path: root/test/functional/vimscript/vvars_spec.lua
blob: 377d6296fae71531fdf8dc6e2f43e37a1eb45829 (plain)
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
local t = require('test.testutil')
local pcall_err = t.pcall_err
local n = require('test.functional.testnvim')()

local clear, eval, eq = n.clear, n.eval, t.eq
local command = n.command

describe('v:event', function()
  before_each(clear)
  it('is empty before any autocommand', function()
    eq({}, eval('v:event'))
  end)

  it('is immutable', function()
    eq(false, pcall(command, 'let v:event = {}'))
    eq(false, pcall(command, 'let v:event.mykey = {}'))
  end)
end)

describe('v:argf', function()
  it('is read-only', function()
    n.clear()
    t.matches('E46', t.pcall_err(command, "let v:argf = ['foo']"))
  end)

  it('gets file args, ignores :argadd, handles "--"', function()
    local file1, file2, file3 = 'Xargf_sep1', 'Xargf_sep2', 'Xargf_sep3'

    n.clear {
      args_rm = { '--cmd', '-c' },
      args = {
        '--clean',
        '--cmd',
        'argadd extrafile.txt', -- :argadd should not affect v:argf.
        file1,
        file2,
        '-c',
        'let a = 1 + 3',
        '--',
        file3,
      },
    }

    local abs1 = n.fn.fnamemodify(file1, ':p')
    local abs2 = n.fn.fnamemodify(file2, ':p')
    local abs3 = n.fn.fnamemodify(file3, ':p')

    eq({ abs1, abs2, abs3 }, n.eval('v:argf'))
  end)
end)