aboutsummaryrefslogtreecommitdiff
path: root/test/functional/ex_cmds/script_spec.lua
blob: 4c963c5da7cbc7e342dfe5d4326e3380653203be (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
local helpers = require('test.functional.helpers')(after_each)

local eq = helpers.eq
local neq = helpers.neq
local command = helpers.command
local exec_capture = helpers.exec_capture
local write_file = helpers.write_file
local api = helpers.api
local clear = helpers.clear
local dedent = helpers.dedent
local exc_exec = helpers.exc_exec
local missing_provider = helpers.missing_provider

local tmpfile = 'X_ex_cmds_script'

before_each(clear)

local function source(code)
  write_file(tmpfile, code)
  command('source ' .. tmpfile)
end

describe('script_get-based command', function()
  local garbage = ')}{+*({}]*[;(+}{&[]}{*])('

  after_each(function()
    os.remove(tmpfile)
  end)

  local function test_garbage_exec(cmd, check_neq)
    describe(cmd, function()
      it('works correctly when skipping oneline variant', function()
        eq(
          true,
          pcall(
            source,
            (dedent([[
          if 0
            %s %s
          endif
        ]])):format(cmd, garbage)
          )
        )
        eq('', exec_capture('messages'))
        if check_neq then
          neq(
            0,
            exc_exec(dedent([[
            %s %s
          ]])):format(cmd, garbage)
          )
        end
      end)
      it('works correctly when skipping HEREdoc variant', function()
        eq(
          true,
          pcall(
            source,
            (dedent([[
          if 0
          %s << EOF
          %s
          EOF
          endif
        ]])):format(cmd, garbage)
          )
        )
        eq('', exec_capture('messages'))
        if check_neq then
          eq(
            true,
            pcall(
              source,
              (dedent([[
            let g:exc = 0
            try
            %s << EOF
            %s
            EOF
            catch
            let g:exc = v:exception
            endtry
          ]])):format(cmd, garbage)
            )
          )
          neq(0, api.nvim_get_var('exc'))
        end
      end)
    end)
  end

  clear()

  -- Built-in scripts
  test_garbage_exec('lua', true)

  -- Provider-based scripts
  test_garbage_exec('ruby', not missing_provider('ruby'))
  test_garbage_exec('python3', not missing_provider('python'))

  -- Missing scripts
  test_garbage_exec('python', false)
  test_garbage_exec('tcl', false)
  test_garbage_exec('mzscheme', false)
  test_garbage_exec('perl', false)

  -- Not really a script
  test_garbage_exec('xxxinvalidlanguagexxx', true)
end)