diff options
Diffstat (limited to 'test/functional/lua')
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 72 | ||||
-rw-r--r-- | test/functional/lua/ffi_spec.lua | 62 | ||||
-rw-r--r-- | test/functional/lua/uri_spec.lua | 17 | ||||
-rw-r--r-- | test/functional/lua/vim_spec.lua | 11 |
4 files changed, 161 insertions, 1 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index a08c8d8681..33469597a1 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -473,6 +473,78 @@ describe('vim.diagnostic', function() end) describe('config()', function() + it('works with global, namespace, and ephemeral options', function() + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = true, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Some Error', 4, 4, 4, 4), + }) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = false, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_error('Some Error', 4, 4, 4, 4), + }, {virtual_text = true}) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(0, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = {severity=vim.diagnostic.severity.ERROR}, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_warning('Some Warning', 4, 4, 4, 4), + }, {virtual_text = true}) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + + eq(1, exec_lua [[ + vim.diagnostic.config({ + virtual_text = false, + }) + + vim.diagnostic.config({ + virtual_text = {severity=vim.diagnostic.severity.ERROR}, + underline = false, + }, diagnostic_ns) + + vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, { + make_warning('Some Warning', 4, 4, 4, 4), + }, { + virtual_text = {} -- An empty table uses default values + }) + + return count_extmarks(diagnostic_bufnr, diagnostic_ns) + ]]) + end) + it('can use functions for config values', function() exec_lua [[ vim.diagnostic.config({ diff --git a/test/functional/lua/ffi_spec.lua b/test/functional/lua/ffi_spec.lua new file mode 100644 index 0000000000..80c01a2b8c --- /dev/null +++ b/test/functional/lua/ffi_spec.lua @@ -0,0 +1,62 @@ +local helpers = require('test.functional.helpers')(after_each) +local eq = helpers.eq +local exec_lua = helpers.exec_lua +local clear = helpers.clear + +before_each(clear) + +describe('ffi.cdef', function() + it('can use Neovim core functions', function() + if not exec_lua("return pcall(require, 'ffi')") then + pending('missing LuaJIT FFI') + end + + eq(12, exec_lua[[ + local ffi = require('ffi') + + ffi.cdef('int curwin_col_off(void);') + + vim.cmd('set number numberwidth=4 signcolumn=yes:4') + + return ffi.C.curwin_col_off() + ]]) + + eq(20, exec_lua[=[ + local ffi = require('ffi') + + ffi.cdef[[ + typedef unsigned char char_u; + typedef struct window_S win_T; + typedef struct {} stl_hlrec_t; + typedef struct {} StlClickRecord; + typedef struct {} Error; + + win_T *find_window_by_handle(int Window, Error *err); + + int build_stl_str_hl( + win_T *wp, + char_u *out, + size_t outlen, + char_u *fmt, + int use_sandbox, + char_u fillchar, + int maxwidth, + stl_hlrec_t **hltab, + StlClickRecord **tabtab + ); + ]] + + return ffi.C.build_stl_str_hl( + ffi.C.find_window_by_handle(0, ffi.new('Error')), + ffi.new('char_u[1024]'), + 1024, + ffi.cast('char_u*', 'StatusLineOfLength20'), + 0, + 0, + 0, + nil, + nil + ) + ]=]) + end) +end) diff --git a/test/functional/lua/uri_spec.lua b/test/functional/lua/uri_spec.lua index 052a8a1ecd..81f1820986 100644 --- a/test/functional/lua/uri_spec.lua +++ b/test/functional/lua/uri_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear = helpers.clear local exec_lua = helpers.exec_lua local eq = helpers.eq +local write_file = require('test.helpers').write_file describe('URI methods', function() before_each(function() @@ -158,6 +159,22 @@ describe('URI methods', function() end) + describe('uri from bufnr', function() + it('Windows paths should not be treated as uris', function() + if not helpers.iswin() then return end + + local file = helpers.tmpname() + write_file(file, 'Test content') + local test_case = string.format([[ + local file = '%s' + return vim.uri_from_bufnr(vim.fn.bufadd(file)) + ]], file) + local expected_uri = 'file:///' .. file:gsub("\\", "/") + eq(expected_uri, exec_lua(test_case)) + os.remove(file) + end) + end) + describe('uri to bufnr', function() it('uri_to_bufnr & uri_from_bufnr returns original uri for non-file uris', function() local uri = 'jdt://contents/java.base/java.util/List.class?=sql/%5C/home%5C/user%5C/.jabba%5C/jdk%5C/openjdk%5C@1.14.0%5C/lib%5C/jrt-fs.jar%60java.base=/javadoc_location=/https:%5C/%5C/docs.oracle.com%5C/en%5C/java%5C/javase%5C/14%5C/docs%5C/api%5C/=/%3Cjava.util(List.class' diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua index 8651a38025..a739992611 100644 --- a/test/functional/lua/vim_spec.lua +++ b/test/functional/lua/vim_spec.lua @@ -2255,7 +2255,7 @@ end) describe('lua: require("mod") from packages', function() before_each(function() - command('set rtp+=test/functional/fixtures') + command('set rtp+=test/functional/fixtures pp+=test/functional/fixtures') end) it('propagates syntax error', function() @@ -2266,4 +2266,13 @@ describe('lua: require("mod") from packages', function() matches("unexpected symbol", syntax_error_msg) end) + + it('uses the right order of mod.lua vs mod/init.lua', function() + -- lua/fancy_x.lua takes precedence over lua/fancy_x/init.lua + eq('I am fancy_x.lua', exec_lua [[ return require'fancy_x' ]]) + -- but lua/fancy_y/init.lua takes precedence over after/lua/fancy_y.lua + eq('I am init.lua of fancy_y!', exec_lua [[ return require'fancy_y' ]]) + -- safety check: after/lua/fancy_z.lua is still loaded + eq('I am fancy_z.lua', exec_lua [[ return require'fancy_z' ]]) + end) end) |