diff options
Diffstat (limited to 'test/functional')
| -rw-r--r-- | test/functional/eval/environ_spec.lua | 12 | ||||
| -rw-r--r-- | test/functional/lua/buffer_updates_spec.lua | 162 | ||||
| -rw-r--r-- | test/functional/plugin/health_spec.lua | 3 | ||||
| -rw-r--r-- | test/functional/plugin/helpers.lua | 41 | ||||
| -rw-r--r-- | test/functional/plugin/matchparen_spec.lua | 6 | ||||
| -rw-r--r-- | test/functional/plugin/msgpack_spec.lua | 8 | ||||
| -rw-r--r-- | test/functional/plugin/shada_spec.lua | 17 |
7 files changed, 171 insertions, 78 deletions
diff --git a/test/functional/eval/environ_spec.lua b/test/functional/eval/environ_spec.lua new file mode 100644 index 0000000000..eb52f9e2da --- /dev/null +++ b/test/functional/eval/environ_spec.lua @@ -0,0 +1,12 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local eq = helpers.eq +local environ = helpers.funcs.environ + +describe('environ()', function() + it('handles empty env variable', function() + clear({env={EMPTY_VAR=""}}) + eq("", environ()['EMPTY_VAR']) + eq(nil, environ()['DOES_NOT_EXIST']) + end) +end) diff --git a/test/functional/lua/buffer_updates_spec.lua b/test/functional/lua/buffer_updates_spec.lua index c419d89be3..990cb97fec 100644 --- a/test/functional/lua/buffer_updates_spec.lua +++ b/test/functional/lua/buffer_updates_spec.lua @@ -5,28 +5,31 @@ local command = helpers.command local meths = helpers.meths local clear = helpers.clear local eq = helpers.eq +local exec_lua = helpers.exec_lua +local feed = helpers.feed local origlines = {"original line 1", "original line 2", "original line 3", "original line 4", "original line 5", - "original line 6"} + "original line 6", + " indented line"} describe('lua: buffer event callbacks', function() before_each(function() clear() - meths.execute_lua([[ + exec_lua([[ local events = {} - function test_register(bufnr, id, changedtick) + function test_register(bufnr, id, changedtick, utf_sizes) local function callback(...) table.insert(events, {id, ...}) if test_unreg == id then return true end end - local opts = {on_lines=callback, on_detach=callback} + local opts = {on_lines=callback, on_detach=callback, utf_sizes=utf_sizes} if changedtick then opts.on_changedtick = callback end @@ -38,55 +41,166 @@ describe('lua: buffer event callbacks', function() events = {} return ret_events end - ]], {}) + ]]) end) - it('works', function() + + -- verifying the sizes with nvim_buf_get_offset is nice (checks we cannot + -- assert the wrong thing), but masks errors with unflushed lines (as + -- nvim_buf_get_offset forces a flush of the memline). To be safe run the + -- test both ways. + local function check(verify,utf_sizes) + local lastsize meths.buf_set_lines(0, 0, -1, true, origlines) - meths.execute_lua("return test_register(...)", {0, "test1"}) + if verify then + lastsize = meths.buf_get_offset(0, meths.buf_line_count(0)) + end + exec_lua("return test_register(...)", 0, "test1",false,utf_sizes) local tick = meths.buf_get_changedtick(0) + local verify_name = "test1" + local function check_events(expected) + local events = exec_lua("return get_events(...)" ) + if utf_sizes then + -- this test case uses ASCII only, so sizes sshould be the same. + -- Unicode is tested below. + for _, event in ipairs(expected) do + event[9] = event[8] + event[10] = event[8] + end + end + eq(expected, events) + if verify then + for _, event in ipairs(events) do + if event[1] == verify_name and event[2] == "lines" then + local startline, endline = event[5], event[7] + local newrange = meths.buf_get_offset(0, endline) - meths.buf_get_offset(0, startline) + local newsize = meths.buf_get_offset(0, meths.buf_line_count(0)) + local oldrange = newrange + lastsize - newsize + eq(oldrange, event[8]) + lastsize = newsize + end + end + end + end + + command('set autoindent') command('normal! GyyggP') tick = tick + 1 - eq({{ "test1", "lines", 1, tick, 0, 0, 1 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test1", "lines", 1, tick, 0, 0, 1, 0}}) meths.buf_set_lines(0, 3, 5, true, {"changed line"}) tick = tick + 1 - eq({{ "test1", "lines", 1, tick, 3, 5, 4 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test1", "lines", 1, tick, 3, 5, 4, 32 }}) - meths.execute_lua("return test_register(...)", {0, "test2", true}) + exec_lua("return test_register(...)", 0, "test2", true, utf_sizes) tick = tick + 1 command('undo') -- plugins can opt in to receive changedtick events, or choose -- to only recieve actual changes. - eq({{ "test1", "lines", 1, tick, 3, 4, 5 }, - { "test2", "lines", 1, tick, 3, 4, 5 }, - { "test2", "changedtick", 1, tick+1 } }, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test1", "lines", 1, tick, 3, 4, 5, 13 }, + { "test2", "lines", 1, tick, 3, 4, 5, 13 }, + { "test2", "changedtick", 1, tick+1 } }) tick = tick + 1 -- simulate next callback returning true - meths.execute_lua("test_unreg = 'test1'", {}) + exec_lua("test_unreg = 'test1'") meths.buf_set_lines(0, 6, 7, true, {"x1","x2","x3"}) tick = tick + 1 -- plugins can opt in to receive changedtick events, or choose -- to only recieve actual changes. - eq({{ "test1", "lines", 1, tick, 6, 7, 9 }, - { "test2", "lines", 1, tick, 6, 7, 9 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test1", "lines", 1, tick, 6, 7, 9, 16 }, + { "test2", "lines", 1, tick, 6, 7, 9, 16 }}) + + verify_name = "test2" meths.buf_set_lines(0, 1, 1, true, {"added"}) tick = tick + 1 - eq({{ "test2", "lines", 1, tick, 1, 1, 2 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test2", "lines", 1, tick, 1, 1, 2, 0 }}) + + feed('wix') + tick = tick + 1 + check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 16 }}) + + -- check hot path for multiple insert + feed('yz') + tick = tick + 1 + check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 17 }}) + + feed('<bs>') + tick = tick + 1 + check_events({{ "test2", "lines", 1, tick, 4, 5, 5, 19 }}) + + feed('<esc>Go') + tick = tick + 1 + check_events({{ "test2", "lines", 1, tick, 11, 11, 12, 0 }}) + + feed('x') + tick = tick + 1 + check_events({{ "test2", "lines", 1, tick, 11, 12, 12, 5 }}) command('bwipe!') - eq({{ "test2", "detach", 1 }}, - meths.execute_lua("return get_events(...)", {})) + check_events({{ "test2", "detach", 1 }}) + end + + it('works', function() + check(false) end) + + it('works with verify', function() + check(true) + end) + + it('works with utf_sizes and ASCII text', function() + check(false,true) + end) + + it('works with utf_sizes and unicode text', function() + local unicode_text = {"ascii text", + "latin text åäö", + "BMP text ɧ αλφά", + "BMP text 汉语 ↥↧", + "SMP 🤦 🦄🦃", + "combining å بِيَّة"} + meths.buf_set_lines(0, 0, -1, true, unicode_text) + feed('gg') + exec_lua("return test_register(...)", 0, "test1", false, true) + local tick = meths.buf_get_changedtick(0) + + feed('dd') + tick = tick + 1 + eq({{ "test1", "lines", 1, tick, 0, 1, 0, 11, 11, 11 }}, exec_lua("return get_events(...)" )) + + feed('A<bs>') + tick = tick + 1 + eq({{ "test1", "lines", 1, tick, 0, 1, 1, 18, 15, 15 }}, exec_lua("return get_events(...)" )) + + feed('<esc>jylp') + tick = tick + 1 + eq({{ "test1", "lines", 1, tick, 1, 2, 2, 21, 16, 16 }}, exec_lua("return get_events(...)" )) + + feed('+eea<cr>') + tick = tick + 1 + eq({{ "test1", "lines", 1, tick, 2, 3, 4, 23, 15, 15 }}, exec_lua("return get_events(...)" )) + + feed('<esc>jdw') + tick = tick + 1 + -- non-BMP chars count as 2 UTF-2 codeunits + eq({{ "test1", "lines", 1, tick, 4, 5, 5, 18, 9, 12 }}, exec_lua("return get_events(...)" )) + + feed('+rx') + tick = tick + 1 + -- count the individual codepoints of a composed character. + eq({{ "test1", "lines", 1, tick, 5, 6, 6, 27, 20, 20 }}, exec_lua("return get_events(...)" )) + + feed('kJ') + tick = tick + 1 + -- NB: this is inefficient (but not really wrong). + eq({{ "test1", "lines", 1, tick, 4, 5, 5, 14, 5, 8 }, + { "test1", "lines", 1, tick+1, 5, 6, 5, 27, 20, 20 }}, exec_lua("return get_events(...)" )) + end) + end) diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index f2d5e433db..3525e235de 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -1,6 +1,5 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') -local plugin_helpers = require('test.functional.plugin.helpers') local clear = helpers.clear local curbuf_contents = helpers.curbuf_contents @@ -41,7 +40,7 @@ end) describe('health.vim', function() before_each(function() - plugin_helpers.reset() + clear{args={'-u', 'NORC'}} -- Provides functions: -- health#broken#check() -- health#success1#check() diff --git a/test/functional/plugin/helpers.lua b/test/functional/plugin/helpers.lua deleted file mode 100644 index 4359380bd7..0000000000 --- a/test/functional/plugin/helpers.lua +++ /dev/null @@ -1,41 +0,0 @@ -local paths = require('test.config.paths') - -local helpers = require('test.functional.helpers')(nil) -local spawn, set_session, nvim_prog, merge_args = - helpers.spawn, helpers.set_session, helpers.nvim_prog, helpers.merge_args - -local additional_cmd = '' - -local function nvim_argv(shada_file) - local rtp_value = ('\'%s/runtime\''):format( - paths.test_source_path:gsub('\'', '\'\'')) - local nvim_args = {nvim_prog, '-u', 'NORC', '-i', shada_file or 'NONE', '-N', - '--cmd', 'set shortmess+=I background=light noswapfile belloff= noshowcmd noruler', - '--cmd', 'let &runtimepath=' .. rtp_value, - '--cmd', additional_cmd, - '--embed', '--headless'} - if helpers.prepend_argv then - return merge_args(helpers.prepend_argv, nvim_args) - else - return nvim_args - end -end - -local session = nil - -local function reset(...) - if session then - session:close() - end - session = spawn(nvim_argv(...)) - set_session(session) -end - -local function set_additional_cmd(s) - additional_cmd = s -end - -return { - reset=reset, - set_additional_cmd=set_additional_cmd, -} diff --git a/test/functional/plugin/matchparen_spec.lua b/test/functional/plugin/matchparen_spec.lua index 51ec7e4870..13e1283e2c 100644 --- a/test/functional/plugin/matchparen_spec.lua +++ b/test/functional/plugin/matchparen_spec.lua @@ -1,19 +1,17 @@ local helpers = require('test.functional.helpers')(after_each) -local plugin_helpers = require('test.functional.plugin.helpers') local Screen = require('test.functional.ui.screen') +local clear = helpers.clear local command = helpers.command local meths = helpers.meths local feed = helpers.feed local eq = helpers.eq -local reset = plugin_helpers.reset - describe('matchparen', function() local screen before_each(function() - reset() + clear{args={'-u', 'NORC'}} screen = Screen.new(20,5) screen:attach() screen:set_default_attr_ids( { diff --git a/test/functional/plugin/msgpack_spec.lua b/test/functional/plugin/msgpack_spec.lua index 2ce9974812..d841cb8ce0 100644 --- a/test/functional/plugin/msgpack_spec.lua +++ b/test/functional/plugin/msgpack_spec.lua @@ -1,15 +1,15 @@ local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear local meths = helpers.meths local eq, nvim_eval, nvim_command, exc_exec = helpers.eq, helpers.eval, helpers.command, helpers.exc_exec local ok = helpers.ok local NIL = helpers.NIL -local plugin_helpers = require('test.functional.plugin.helpers') -local reset = plugin_helpers.reset - describe('autoload/msgpack.vim', function() - before_each(reset) + before_each(function() + clear{args={'-u', 'NORC'}} + end) local sp = function(typ, val) return ('{"_TYPE": v:msgpack_types.%s, "_VAL": %s}'):format(typ, val) diff --git a/test/functional/plugin/shada_spec.lua b/test/functional/plugin/shada_spec.lua index 1482d83ee6..778dc4e219 100644 --- a/test/functional/plugin/shada_spec.lua +++ b/test/functional/plugin/shada_spec.lua @@ -1,4 +1,6 @@ +local paths = require('test.config.paths') local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear local eq, nvim_eval, nvim_command, nvim, exc_exec, funcs, nvim_feed, curbuf = helpers.eq, helpers.eval, helpers.command, helpers.nvim, helpers.exc_exec, helpers.funcs, helpers.feed, helpers.curbuf @@ -7,12 +9,21 @@ local read_file = helpers.read_file local mpack = require('mpack') -local plugin_helpers = require('test.functional.plugin.helpers') -local reset = plugin_helpers.reset - local shada_helpers = require('test.functional.shada.helpers') local get_shada_rw = shada_helpers.get_shada_rw +local function reset(shada_file) + -- TODO(justinmk): why is this needed? + local rtp_value = ('\'%s/runtime\''):format( + paths.test_source_path:gsub('\'', '\'\'')) + clear{args_rm={'-u', '-i'}, + args={'-u', 'NORC', + '-i', shada_file or 'NONE', + '--cmd', 'set laststatus&', + '--cmd', 'let &runtimepath='..rtp_value, + }} +end + local mpack_eq = function(expected, mpack_result) local mpack_keys = {'type', 'timestamp', 'length', 'value'} |