mirror of
https://github.com/neovim/neovim
synced 2025-07-16 01:01:49 +00:00
test: use matches(...) instead of ok(string.find(...)) (#28111)
This commit is contained in:
@ -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,
|
||||
|
@ -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()
|
||||
|
@ -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())
|
||||
|
@ -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()
|
||||
|
@ -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>]])
|
||||
|
@ -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')
|
||||
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
Reference in New Issue
Block a user