robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

robinmerge: 8c77b5be50c50ab119

master
2.8 KiB108 linesraw
1-- Test suite for testing interactions with API bindings
2local t = require('test.testutil')
3local n = require('test.functional.testnvim')()
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local exec_lua = n.exec_lua
7local command = n.command
8local clear = n.clear
9local eq = t.eq
10
11describe('vim.loader', function()
12  before_each(clear)
13
14  it('can be disabled', function()
15    exec_lua(function()
16      local orig_loader = _G.loadfile
17      local orig_loaders = { unpack(package.loaders) }
18      vim.loader.enable()
19      assert(orig_loader ~= _G.loadfile)
20      vim.loader.enable(false)
21      assert(orig_loader == _G.loadfile)
22      assert(vim.deep_equal(orig_loaders, package.loaders))
23    end)
24  end)
25
26  it('works with --luamod-dev #27413', function()
27    clear({ args = { '--luamod-dev' } })
28    exec_lua(function()
29      vim.loader.enable()
30
31      require('vim.fs')
32
33      -- try to load other vim submodules as well (Nvim Lua stdlib)
34      for key, _ in pairs(vim._submodules) do
35        local modname = 'vim.' .. key -- e.g. "vim.fs"
36
37        local lhs = vim[key]
38        local rhs = require(modname)
39        assert(
40          lhs == rhs,
41          ('%s != require("%s"), %s != %s'):format(modname, modname, tostring(lhs), tostring(rhs))
42        )
43      end
44    end)
45  end)
46
47  it('handles changing files #23027', function()
48    exec_lua(function()
49      vim.loader.enable()
50    end)
51
52    local tmp = t.tmpname()
53    command('edit ' .. tmp)
54
55    eq(
56      1,
57      exec_lua(function()
58        vim.api.nvim_buf_set_lines(0, 0, -1, true, { '_G.TEST=1' })
59        vim.cmd.write()
60        loadfile(tmp)()
61        return _G.TEST
62      end)
63    )
64
65    -- fs latency
66    vim.uv.sleep(10)
67
68    eq(
69      2,
70      exec_lua(function()
71        vim.api.nvim_buf_set_lines(0, 0, -1, true, { '_G.TEST=2' })
72        vim.cmd.write()
73        loadfile(tmp)()
74        return _G.TEST
75      end)
76    )
77  end)
78
79  it('handles % signs in modpath #24491', function()
80    exec_lua [[
81      vim.loader.enable()
82    ]]
83
84    local tmp = t.tmpname(false)
85    assert(t.mkdir(tmp))
86    assert(t.mkdir(tmp .. '/%'))
87    local tmp1 = tmp .. '/%/x'
88    local tmp2 = tmp .. '/%%x'
89
90    t.write_file(tmp1, 'return 1', true)
91    t.write_file(tmp2, 'return 2', true)
92    vim.uv.fs_utime(tmp1, 0, 0)
93    vim.uv.fs_utime(tmp2, 0, 0)
94    eq(1, exec_lua('return loadfile(...)()', tmp1))
95    eq(2, exec_lua('return loadfile(...)()', tmp2))
96  end)
97
98  it('indents error message #29809', function()
99    local errmsg = exec_lua [[
100      vim.loader.enable()
101      local _, errmsg = pcall(require, 'non_existent_module')
102      return errmsg
103    ]]
104    local errors = vim.split(errmsg, '\n')
105    eq("\tcache_loader: module 'non_existent_module' not found", errors[3])
106    eq("\tcache_loader_lib: module 'non_existent_module' not found", errors[4])
107  end)
108end)