neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

script_spec.lua (2439B)


      1 local t = require('test.testutil')
      2 local n = require('test.functional.testnvim')()
      3 
      4 local eq = t.eq
      5 local neq = t.neq
      6 local command = n.command
      7 local exec_capture = n.exec_capture
      8 local write_file = t.write_file
      9 local api = n.api
     10 local clear = n.clear
     11 local dedent = t.dedent
     12 local exc_exec = n.exc_exec
     13 local missing_provider = n.missing_provider
     14 
     15 local tmpfile = 'X_ex_cmds_script'
     16 
     17 before_each(clear)
     18 
     19 local function source(code)
     20  write_file(tmpfile, code)
     21  command('source ' .. tmpfile)
     22 end
     23 
     24 describe('script_get-based command', function()
     25  local garbage = ')}{+*({}]*[;(+}{&[]}{*])('
     26 
     27  after_each(function()
     28    os.remove(tmpfile)
     29  end)
     30 
     31  local function test_garbage_exec(cmd, check_neq)
     32    describe(cmd, function()
     33      it('works correctly when skipping oneline variant', function()
     34        eq(
     35          true,
     36          pcall(
     37            source,
     38            (dedent([[
     39          if 0
     40            %s %s
     41          endif
     42        ]])):format(cmd, garbage)
     43          )
     44        )
     45        eq('', exec_capture('messages'))
     46        if check_neq then
     47          neq(
     48            0,
     49            exc_exec(dedent([[
     50            %s %s
     51          ]])):format(cmd, garbage)
     52          )
     53        end
     54      end)
     55      it('works correctly when skipping HEREdoc variant', function()
     56        eq(
     57          true,
     58          pcall(
     59            source,
     60            (dedent([[
     61          if 0
     62          %s << EOF
     63          %s
     64          EOF
     65          endif
     66        ]])):format(cmd, garbage)
     67          )
     68        )
     69        eq('', exec_capture('messages'))
     70        if check_neq then
     71          eq(
     72            true,
     73            pcall(
     74              source,
     75              (dedent([[
     76            let g:exc = 0
     77            try
     78            %s << EOF
     79            %s
     80            EOF
     81            catch
     82            let g:exc = v:exception
     83            endtry
     84          ]])):format(cmd, garbage)
     85            )
     86          )
     87          neq(0, api.nvim_get_var('exc'))
     88        end
     89      end)
     90    end)
     91  end
     92 
     93  clear()
     94 
     95  -- Built-in scripts
     96  test_garbage_exec('lua', true)
     97 
     98  -- Provider-based scripts
     99  test_garbage_exec('ruby', not missing_provider('ruby'))
    100  test_garbage_exec('python3', not missing_provider('python'))
    101 
    102  -- Missing scripts
    103  test_garbage_exec('python', false)
    104  test_garbage_exec('tcl', false)
    105  test_garbage_exec('mzscheme', false)
    106  test_garbage_exec('perl', false)
    107 
    108  -- Not really a script
    109  test_garbage_exec('xxxinvalidlanguagexxx', true)
    110 end)