diff options
author | zeertzjq <zeertzjq@outlook.com> | 2024-03-30 09:29:21 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-30 09:29:21 +0800 |
commit | 35239e977f53c25016b57729cada612aa53e11d4 (patch) | |
tree | 45e24edd39b7b80199d4a2b510add5c57f4148a8 | |
parent | 19d63563e1cceabbf8603d0abb2e88fae5bd3626 (diff) | |
download | rneovim-35239e977f53c25016b57729cada612aa53e11d4.tar.gz rneovim-35239e977f53c25016b57729cada612aa53e11d4.tar.bz2 rneovim-35239e977f53c25016b57729cada612aa53e11d4.zip |
test: use matches(...) instead of ok(string.find(...)) (#28111)
-rw-r--r-- | src/nvim/change.c | 4 | ||||
-rw-r--r-- | test/functional/api/vim_spec.lua | 13 | ||||
-rw-r--r-- | test/functional/core/channels_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/core/job_spec.lua | 9 | ||||
-rw-r--r-- | test/functional/ex_cmds/arg_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/ex_cmds/edit_spec.lua | 3 | ||||
-rw-r--r-- | test/functional/vimscript/reltime_spec.lua | 5 | ||||
-rw-r--r-- | test/functional/vimscript/server_spec.lua | 4 |
8 files changed, 20 insertions, 24 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c index 42884842b3..fce0de49bb 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -1838,8 +1838,8 @@ bool open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) saved_line = NULL; if (did_append) { - // Always move extmarks - Here we move only the line where the - // cursor is, the later mark_adjust takes care of the lines after. + // Always move extmarks - Here we move only the line where the cursor is, + // the previous mark_adjust() took care of the lines after. int cols_added = mincol - 1 + less_cols_off - less_cols; extmark_splice(curbuf, (int)lnum - 1, mincol - 1 - cols_spliced, 0, less_cols_off, less_cols_off, diff --git a/test/functional/api/vim_spec.lua b/test/functional/api/vim_spec.lua index d98308ee87..d72ccf99b3 100644 --- a/test/functional/api/vim_spec.lua +++ b/test/functional/api/vim_spec.lua @@ -1593,9 +1593,7 @@ describe('API', function() api.nvim_set_option_value('equalalways', false, {}) local status, rv = pcall(command_output, 'verbose set equalalways?') eq(true, status) - ok( - nil ~= string.find(rv, 'noequalalways\n' .. '\tLast set from API client %(channel id %d+%)') - ) + matches('noequalalways\n' .. '\tLast set from API client %(channel id %d+%)', rv) api.nvim_exec_lua('vim.api.nvim_set_option_value("equalalways", true, {})', {}) status, rv = pcall(command_output, 'verbose set equalalways?') @@ -2723,7 +2721,7 @@ describe('API', function() it('can throw exceptions', function() local status, err = pcall(api.nvim_get_option_value, 'invalid-option', {}) eq(false, status) - ok(err:match("Unknown option 'invalid%-option'") ~= nil) + matches("Unknown option 'invalid%-option'", err) end) it('does not truncate error message <1 MB #5984', function() @@ -2736,10 +2734,7 @@ describe('API', function() it('does not leak memory on incorrect argument types', function() local status, err = pcall(api.nvim_set_current_dir, { 'not', 'a', 'dir' }) eq(false, status) - ok( - err:match(': Wrong type for argument 1 when calling nvim_set_current_dir, expecting String') - ~= nil - ) + matches(': Wrong type for argument 1 when calling nvim_set_current_dir, expecting String', err) end) describe('nvim_parse_expression', function() @@ -3670,7 +3665,7 @@ describe('API', function() api.nvim_buf_set_name(buf, 'mybuf') local mark = api.nvim_get_mark('F', {}) -- Compare the path tail only - assert(string.find(mark[4], 'mybuf$')) + matches('mybuf$', mark[4]) eq({ 2, 2, buf, mark[4] }, mark) end) it('validation', function() diff --git a/test/functional/core/channels_spec.lua b/test/functional/core/channels_spec.lua index 56a2f5a571..0ab885e02f 100644 --- a/test/functional/core/channels_spec.lua +++ b/test/functional/core/channels_spec.lua @@ -2,6 +2,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, eval, next_msg, ok, source = helpers.clear, helpers.eq, helpers.eval, helpers.next_msg, helpers.ok, helpers.source local command, fn, api = helpers.command, helpers.fn, helpers.api +local matches = helpers.matches local sleep = vim.uv.sleep local spawn, nvim_argv = helpers.spawn, helpers.nvim_argv local get_session, set_session = helpers.get_session, helpers.set_session @@ -277,7 +278,7 @@ describe('channels', function() local _, err = pcall(command, "call rpcrequest(id, 'nvim_command', 'call chanclose(v:stderr, \"stdin\")')") - ok(string.find(err, 'E906: invalid stream for channel') ~= nil) + matches('E906: invalid stream for channel', err) eq(1, eval("rpcrequest(id, 'nvim_eval', 'chanclose(v:stderr, \"stderr\")')")) eq({ 'notification', 'stderr', { 3, { '' } } }, next_msg()) diff --git a/test/functional/core/job_spec.lua b/test/functional/core/job_spec.lua index 9e7f1faa47..b7e9af99ac 100644 --- a/test/functional/core/job_spec.lua +++ b/test/functional/core/job_spec.lua @@ -73,7 +73,7 @@ describe('jobs', function() command("let j = jobstart('env', g:job_opts)") end end) - ok(string.find(err, 'E475: Invalid argument: env') ~= nil) + matches('E475: Invalid argument: env', err) end) it('append environment #env', function() @@ -227,7 +227,7 @@ describe('jobs', function() command("let j = jobstart('pwd', g:job_opts)") end end) - ok(string.find(err, 'E475: Invalid argument: expected valid directory$') ~= nil) + matches('E475: Invalid argument: expected valid directory$', err) end) it('error on non-executable `cwd`', function() @@ -980,10 +980,7 @@ describe('jobs', function() command('let g:job_opts.pty = v:true') command('let g:job_opts.rpc = v:true') local _, err = pcall(command, "let j = jobstart(['cat', '-'], g:job_opts)") - ok( - string.find(err, "E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set") - ~= nil - ) + matches("E475: Invalid argument: job cannot have both 'pty' and 'rpc' options set", err) end) it('does not crash when repeatedly failing to start shell', function() diff --git a/test/functional/ex_cmds/arg_spec.lua b/test/functional/ex_cmds/arg_spec.lua index 810b001ec0..45b2f50af1 100644 --- a/test/functional/ex_cmds/arg_spec.lua +++ b/test/functional/ex_cmds/arg_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq, command, fn = helpers.eq, helpers.command, helpers.fn local ok = helpers.ok +local matches = helpers.matches local clear = helpers.clear describe(':argument', function() @@ -15,7 +16,7 @@ describe(':argument', function() helpers.feed([[<C-\><C-N>]]) local bufname_before = fn.bufname('%') local bufnr_before = fn.bufnr('%') - helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity + matches('^term://', bufname_before) -- sanity command('argument 1') helpers.feed([[<C-\><C-N>]]) diff --git a/test/functional/ex_cmds/edit_spec.lua b/test/functional/ex_cmds/edit_spec.lua index b927fa418a..9d4effd72e 100644 --- a/test/functional/ex_cmds/edit_spec.lua +++ b/test/functional/ex_cmds/edit_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local eq, command, fn = helpers.eq, helpers.command, helpers.fn local ok = helpers.ok +local matches = helpers.matches local clear = helpers.clear local feed = helpers.feed @@ -14,7 +15,7 @@ describe(':edit', function() feed([[<C-\><C-N>]]) local bufname_before = fn.bufname('%') local bufnr_before = fn.bufnr('%') - helpers.ok(nil ~= string.find(bufname_before, '^term://')) -- sanity + matches('^term://', bufname_before) -- sanity command('edit') diff --git a/test/functional/vimscript/reltime_spec.lua b/test/functional/vimscript/reltime_spec.lua index 7cdb78e4ce..fc4dd0d87b 100644 --- a/test/functional/vimscript/reltime_spec.lua +++ b/test/functional/vimscript/reltime_spec.lua @@ -1,6 +1,7 @@ local helpers = require('test.functional.helpers')(after_each) local clear, eq, ok = helpers.clear, helpers.eq, helpers.ok local neq, command, fn = helpers.neq, helpers.command, helpers.fn +local matches = helpers.matches local reltime, reltimestr, reltimefloat = fn.reltime, fn.reltimestr, fn.reltimefloat describe('reltimestr(), reltimefloat()', function() @@ -15,7 +16,7 @@ describe('reltimestr(), reltimefloat()', function() neq('0.0', reltimestr(elapsed)) ok(reltimefloat(elapsed) > 0.0) -- original vim test for < 0.1, but easily fails on travis - ok(nil ~= string.match(reltimestr(elapsed), '0%.')) + matches('0%.', reltimestr(elapsed)) ok(reltimefloat(elapsed) < 1.0) local same = reltime(now, now) @@ -29,7 +30,7 @@ describe('reltimestr(), reltimefloat()', function() neq('0.0', reltimestr(differs)) ok(reltimefloat(differs) > 0.0) -- original vim test for < 0.1, but easily fails on travis - ok(nil ~= string.match(reltimestr(differs), '0%.')) + matches('0%.', reltimestr(differs)) ok(reltimefloat(differs) < 1.0) end) diff --git a/test/functional/vimscript/server_spec.lua b/test/functional/vimscript/server_spec.lua index 360fcf0dfe..c6c9e9c0ab 100644 --- a/test/functional/vimscript/server_spec.lua +++ b/test/functional/vimscript/server_spec.lua @@ -100,14 +100,14 @@ describe('server', function() local s = fn.serverstart('127.0.0.1:0') -- assign random port if #s > 0 then - assert(string.match(s, '127.0.0.1:%d+')) + matches('127.0.0.1:%d+', s) eq(s, fn.serverlist()[1]) clear_serverlist() end s = fn.serverstart('127.0.0.1:') -- assign random port if #s > 0 then - assert(string.match(s, '127.0.0.1:%d+')) + matches('127.0.0.1:%d+', s) eq(s, fn.serverlist()[1]) clear_serverlist() end |