From 419819b6245e120aba8897e3ddea711b2cd0246c Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 5 Mar 2023 09:18:42 +0800 Subject: vim-patch:9.0.1380: CTRL-X on 2**64 subtracts two (#22530) Problem: CTRL-X on 2**64 subtracts two. (James McCoy) Solution: Correct computation for large number. (closes vim/vim#12103) https://github.com/vim/vim/commit/5fb78c3fa5c996c08a65431d698bd2c251eef5c7 Co-authored-by: Bram Moolenaar --- test/unit/charset/vim_str2nr_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/charset/vim_str2nr_spec.lua b/test/unit/charset/vim_str2nr_spec.lua index caf330c378..fc40fa39d4 100644 --- a/test/unit/charset/vim_str2nr_spec.lua +++ b/test/unit/charset/vim_str2nr_spec.lua @@ -63,7 +63,7 @@ local function test_vim_str2nr(s, what, exp, maxlen, strict) cv[k] = args[k] end end - lib.vim_str2nr(s, cv.pre, cv.len, what, cv.num, cv.unum, maxlen, strict) + lib.vim_str2nr(s, cv.pre, cv.len, what, cv.num, cv.unum, maxlen, strict, nil) for cck, ccv in pairs(cv) do if exp[cck] ~= tonumber(ccv[0]) then error(('Failed check (%s = %d) in test (s=%s, w=%u, m=%d, strict=%s): %d'):format( -- cgit From 6d267ad30cf539f520b46e3c92939f7031ce116f Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 23 Mar 2023 12:44:05 +0100 Subject: fix(api): make nvim_get_hl return 'cterm' attrs properly --- test/unit/eval/typval_spec.lua | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 825377813d..ecee773ba8 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1653,7 +1653,7 @@ describe('typval.c', function() eq(OK, lib.tv_dict_add(d, di)) alloc_log:check({}) eq(FAIL, check_emsg(function() return lib.tv_dict_add(d, di) end, - 'E685: Internal error: hash_add()')) + 'E685: Internal error: hash_add(): duplicate key ""')) alloc_log:clear() lib.tv_dict_item_remove(d, di) alloc_log:check({ @@ -1947,7 +1947,7 @@ describe('typval.c', function() alloc_log:check({}) eq({test=10, ['t-est']=int(42)}, dct2tbl(d)) eq(FAIL, check_emsg(function() return lib.tv_dict_add(d, di) end, - 'E685: Internal error: hash_add()')) + 'E685: Internal error: hash_add(): duplicate key "t-est"')) end) end) describe('list()', function() @@ -1964,7 +1964,7 @@ describe('typval.c', function() eq({test=10, tes={1, 2, 3}}, dct2tbl(d)) eq(2, l.lv_refcount) eq(FAIL, check_emsg(function() return lib.tv_dict_add_list(d, 'testt', 3, l) end, - 'E685: Internal error: hash_add()')) + 'E685: Internal error: hash_add(): duplicate key "tes"')) eq(2, l.lv_refcount) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 @@ -1990,7 +1990,7 @@ describe('typval.c', function() eq({test=10, tes={foo=42}}, dct2tbl(d)) eq(2, d2.dv_refcount) eq(FAIL, check_emsg(function() return lib.tv_dict_add_dict(d, 'testt', 3, d2) end, - 'E685: Internal error: hash_add()')) + 'E685: Internal error: hash_add(): duplicate key "tes"')) eq(2, d2.dv_refcount) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 @@ -2012,7 +2012,7 @@ describe('typval.c', function() alloc_log:check({a.di(dis.tes, 'tes')}) eq({test=10, tes=int(2)}, dct2tbl(d)) eq(FAIL, check_emsg(function() return lib.tv_dict_add_nr(d, 'testt', 3, 2) end, - 'E685: Internal error: hash_add()')) + 'E685: Internal error: hash_add(): duplicate key "tes"')) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 eq(FAIL, check_emsg(function() return lib.tv_dict_add_nr(d, 'testt', 3, 2) end, @@ -2032,7 +2032,7 @@ describe('typval.c', function() alloc_log:check({a.di(dis.tes, 'tes')}) eq({test=10, tes=1.5}, dct2tbl(d)) eq(FAIL, check_emsg(function() return lib.tv_dict_add_float(d, 'testt', 3, 1.5) end, - 'E685: Internal error: hash_add()')) + 'E685: Internal error: hash_add(): duplicate key "tes"')) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 eq(FAIL, check_emsg(function() return lib.tv_dict_add_float(d, 'testt', 3, 1.5) end, @@ -2055,7 +2055,7 @@ describe('typval.c', function() }) eq({test=10, tes='TEST'}, dct2tbl(d)) eq(FAIL, check_emsg(function() return lib.tv_dict_add_str(d, 'testt', 3, 'TEST') end, - 'E685: Internal error: hash_add()')) + 'E685: Internal error: hash_add(): duplicate key "tes"')) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 eq(FAIL, check_emsg(function() return lib.tv_dict_add_str(d, 'testt', 3, 'TEST') end, @@ -2085,7 +2085,7 @@ describe('typval.c', function() }) eq({test=10, tes='TEST'}, dct2tbl(d)) eq(FAIL, check_emsg(function() return lib.tv_dict_add_allocated_str(d, 'testt', 3, s2) end, - 'E685: Internal error: hash_add()')) + 'E685: Internal error: hash_add(): duplicate key "tes"')) alloc_log:clear() lib.emsg_skip = lib.emsg_skip + 1 eq(FAIL, check_emsg(function() return lib.tv_dict_add_allocated_str(d, 'testt', 3, s3) end, -- cgit From d510bfbc8e447b1a60d5ec7faaa8f440eb4ef56f Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Sun, 2 Apr 2023 10:11:42 +0200 Subject: refactor: remove char_u (#22829) Closes https://github.com/neovim/neovim/issues/459 --- test/unit/eval/helpers.lua | 2 +- test/unit/message_spec.lua | 4 ++-- test/unit/undo_spec.lua | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index b600f01ab2..9dd6b76de2 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -349,7 +349,7 @@ local special_vals = nil lua2typvalt = function(l, processed) if not special_vals then special_vals = { - [null_string] = {'VAR_STRING', {v_string=ffi.cast('char_u*', nil)}}, + [null_string] = {'VAR_STRING', {v_string=ffi.cast('char*', nil)}}, [null_list] = {'VAR_LIST', {v_list=ffi.cast('list_T*', nil)}}, [null_dict] = {'VAR_DICT', {v_dict=ffi.cast('dict_T*', nil)}}, [nil_value] = {'VAR_SPECIAL', {v_special=eval.kSpecialVarNull}}, diff --git a/test/unit/message_spec.lua b/test/unit/message_spec.lua index 549eff6e03..0d5268d199 100644 --- a/test/unit/message_spec.lua +++ b/test/unit/message_spec.lua @@ -12,7 +12,7 @@ describe('trunc_string', function() local buflen = 40 local function test_inplace(s, expected, room) room = room and room or 20 - local buf = cimp.xmalloc(ffi.sizeof('char_u') * buflen) + local buf = cimp.xmalloc(ffi.sizeof('char') * buflen) ffi.C.strcpy(buf, s) cimp.trunc_string(buf, buf, room, buflen) eq(expected, ffi.string(buf)) @@ -21,7 +21,7 @@ describe('trunc_string', function() local function test_copy(s, expected, room) room = room and room or 20 - local buf = cimp.xmalloc(ffi.sizeof('char_u') * buflen) + local buf = cimp.xmalloc(ffi.sizeof('char') * buflen) local str = cimp.xstrdup(to_cstr(s)) cimp.trunc_string(str, buf, room, buflen) eq(expected, ffi.string(buf)) diff --git a/test/unit/undo_spec.lua b/test/unit/undo_spec.lua index f7f8d26d58..cdc5d3a99e 100644 --- a/test/unit/undo_spec.lua +++ b/test/unit/undo_spec.lua @@ -37,7 +37,7 @@ child_call_once(function() -- requires refactor of UNDO_HASH_SIZE into constant/enum for ffi -- -- compute a hash for this undofile - buffer_hash = ffi.new('char_u[32]') + buffer_hash = ffi.new('char[32]') undo.u_compute_hash(file_buffer, buffer_hash) end) -- cgit From f4cbe0360651123d7f33ddbaa046f797c7d73671 Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 3 Apr 2023 10:27:14 +0100 Subject: fix(test): fix C imports on macOS arm64 System headers on macOS arm64 contain 128-bit numeric types. These types are built into clang and GCC as extensions. Unfortunately, they break the LuaJIT C importer. Define dummy typedefs for the missing numeric types to satisfy the ffi C importer. --- test/unit/helpers.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 686af3b461..708929ad9f 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -148,7 +148,11 @@ local cdef = ffi.cdef local cimportstr -local previous_defines_init = '' +local previous_defines_init = [[ +typedef struct { char bytes[16]; } __attribute__((aligned(16))) __uint128_t; +typedef struct { char bytes[16]; } __attribute__((aligned(16))) __float128; +]] + local preprocess_cache_init = {} local previous_defines_mod = '' local preprocess_cache_mod = nil -- cgit From 743860de40502227b3f0ed64317eb937d24d4a36 Mon Sep 17 00:00:00 2001 From: dundargoc <33953936+dundargoc@users.noreply.github.com> Date: Tue, 4 Apr 2023 21:59:06 +0200 Subject: test: replace lfs with luv and vim.fs test: replace lfs with luv luv already pretty much does everything lfs does, so this duplication of dependencies isn't needed. --- test/unit/os/env_spec.lua | 2 -- test/unit/os/fileio_spec.lua | 69 ++++++++++++++++++++--------------------- test/unit/os/fs_spec.lua | 73 +++++++++++++++++++++----------------------- test/unit/path_spec.lua | 71 +++++++++++++++++++++--------------------- test/unit/preload.lua | 1 - test/unit/preprocess.lua | 6 ---- test/unit/tempfile_spec.lua | 3 +- test/unit/undo_spec.lua | 25 +++++++-------- 8 files changed, 120 insertions(+), 130 deletions(-) (limited to 'test/unit') diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua index 71177f4c65..24b92edee5 100644 --- a/test/unit/os/env_spec.lua +++ b/test/unit/os/env_spec.lua @@ -10,8 +10,6 @@ local to_cstr = helpers.to_cstr local NULL = helpers.NULL local OK = 0 -require('lfs') - local cimp = cimport('./src/nvim/os/os.h') describe('env.c', function() diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua index 4d58a8934e..fd30ca70da 100644 --- a/test/unit/os/fileio_spec.lua +++ b/test/unit/os/fileio_spec.lua @@ -1,4 +1,4 @@ -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) @@ -7,6 +7,7 @@ local eq = helpers.eq local ffi = helpers.ffi local cimport = helpers.cimport local cppimport = helpers.cppimport +local mkdir = helpers.mkdir local m = cimport('./src/nvim/os/os.h', './src/nvim/os/fileio.h') cppimport('fcntl.h') @@ -25,7 +26,7 @@ local linkb = dir .. '/broken.lnk' local filec = dir .. '/created-file.dat' before_each(function() - lfs.mkdir(dir); + mkdir(dir); local f1 = io.open(file1, 'w') f1:write(fcontents) @@ -35,8 +36,8 @@ before_each(function() f2:write(fcontents) f2:close() - lfs.link('file1.dat', linkf, true) - lfs.link('broken.dat', linkb, true) + luv.fs_symlink('file1.dat', linkf) + luv.fs_symlink('broken.dat', linkb) end) after_each(function() @@ -45,7 +46,7 @@ after_each(function() os.remove(linkf) os.remove(linkb) os.remove(filec) - lfs.rmdir(dir) + luv.fs_rmdir(dir) end) local function file_open(fname, flags, mode) @@ -119,13 +120,13 @@ describe('file_open_fd', function() eq(0, m.file_close(fp, false)) end) itp('can use file descriptor returned by os_open for writing', function() - eq(nil, lfs.attributes(filec)) + eq(nil, luv.fs_stat(filec)) local fd = m.os_open(filec, m.kO_WRONLY + m.kO_CREAT, 384) local err, fp = file_open_fd(fd, m.kFileWriteOnly) eq(0, err) eq(4, file_write(fp, 'test')) eq(0, m.file_close(fp, false)) - eq(4, lfs.attributes(filec).size) + eq(4, luv.fs_stat(filec).size) eq('test', io.open(filec):read('*a')) end) end) @@ -139,13 +140,13 @@ describe('file_open_fd_new', function() eq(0, m.file_free(fp, false)) end) itp('can use file descriptor returned by os_open for writing', function() - eq(nil, lfs.attributes(filec)) + eq(nil, luv.fs_stat(filec)) local fd = m.os_open(filec, m.kO_WRONLY + m.kO_CREAT, 384) local err, fp = file_open_fd_new(fd, m.kFileWriteOnly) eq(0, err) eq(4, file_write(fp, 'test')) eq(0, m.file_free(fp, false)) - eq(4, lfs.attributes(filec).size) + eq(4, luv.fs_stat(filec).size) eq('test', io.open(filec):read('*a')) end) end) @@ -154,32 +155,32 @@ describe('file_open', function() itp('can create a rwx------ file with kFileCreate', function() local err, fp = file_open(filec, m.kFileCreate, 448) eq(0, err) - local attrs = lfs.attributes(filec) - eq('rwx------', attrs.permissions) + local attrs = luv.fs_stat(filec) + eq(33216, attrs.mode) eq(0, m.file_close(fp, false)) end) itp('can create a rw------- file with kFileCreate', function() local err, fp = file_open(filec, m.kFileCreate, 384) eq(0, err) - local attrs = lfs.attributes(filec) - eq('rw-------', attrs.permissions) + local attrs = luv.fs_stat(filec) + eq(33152, attrs.mode) eq(0, m.file_close(fp, false)) end) itp('can create a rwx------ file with kFileCreateOnly', function() local err, fp = file_open(filec, m.kFileCreateOnly, 448) eq(0, err) - local attrs = lfs.attributes(filec) - eq('rwx------', attrs.permissions) + local attrs = luv.fs_stat(filec) + eq(33216, attrs.mode) eq(0, m.file_close(fp, false)) end) itp('can create a rw------- file with kFileCreateOnly', function() local err, fp = file_open(filec, m.kFileCreateOnly, 384) eq(0, err) - local attrs = lfs.attributes(filec) - eq('rw-------', attrs.permissions) + local attrs = luv.fs_stat(filec) + eq(33152, attrs.mode) eq(0, m.file_close(fp, false)) end) @@ -228,7 +229,7 @@ describe('file_open', function() eq(0, err) eq(true, fp.wr) eq(0, m.file_close(fp, false)) - local attrs = lfs.attributes(file1) + local attrs = luv.fs_stat(file1) eq(0, attrs.size) end) @@ -237,14 +238,14 @@ describe('file_open', function() eq(0, err) eq(true, fp.wr) eq(0, m.file_close(fp, false)) - local attrs = lfs.attributes(file1) + local attrs = luv.fs_stat(file1) eq(4096, attrs.size) end) itp('fails to create a file with just kFileWriteOnly', function() local err, _ = file_open(filec, m.kFileWriteOnly, 384) eq(m.UV_ENOENT, err) - local attrs = lfs.attributes(filec) + local attrs = luv.fs_stat(filec) eq(nil, attrs) end) @@ -254,7 +255,7 @@ describe('file_open', function() eq(0, err) eq(true, fp.wr) eq(0, m.file_close(fp, false)) - local attrs = lfs.attributes(file1) + local attrs = luv.fs_stat(file1) eq(0, attrs.size) end) @@ -295,9 +296,9 @@ describe('file_close', function() eq(0, err) local wsize = file_write(fp, 'test') eq(4, wsize) - eq(0, lfs.attributes(filec).size) + eq(0, luv.fs_stat(filec).size) eq(0, m.file_close(fp, true)) - eq(wsize, lfs.attributes(filec).size) + eq(wsize, luv.fs_stat(filec).size) end) end) @@ -307,9 +308,9 @@ describe('file_free', function() eq(0, err) local wsize = file_write(fp, 'test') eq(4, wsize) - eq(0, lfs.attributes(filec).size) + eq(0, luv.fs_stat(filec).size) eq(0, m.file_free(fp, true)) - eq(wsize, lfs.attributes(filec).size) + eq(wsize, luv.fs_stat(filec).size) end) end) @@ -318,12 +319,12 @@ describe('file_fsync', function() local err, fp = file_open(filec, m.kFileCreateOnly, 384) eq(0, file_fsync(fp)) eq(0, err) - eq(0, lfs.attributes(filec).size) + eq(0, luv.fs_stat(filec).size) local wsize = file_write(fp, 'test') eq(4, wsize) - eq(0, lfs.attributes(filec).size) + eq(0, luv.fs_stat(filec).size) eq(0, file_fsync(fp)) - eq(wsize, lfs.attributes(filec).size) + eq(wsize, luv.fs_stat(filec).size) eq(0, m.file_close(fp, false)) end) end) @@ -333,12 +334,12 @@ describe('file_flush', function() local err, fp = file_open(filec, m.kFileCreateOnly, 384) eq(0, file_flush(fp)) eq(0, err) - eq(0, lfs.attributes(filec).size) + eq(0, luv.fs_stat(filec).size) local wsize = file_write(fp, 'test') eq(4, wsize) - eq(0, lfs.attributes(filec).size) + eq(0, luv.fs_stat(filec).size) eq(0, file_flush(fp)) - eq(wsize, lfs.attributes(filec).size) + eq(wsize, luv.fs_stat(filec).size) eq(0, m.file_close(fp, false)) end) end) @@ -412,7 +413,7 @@ describe('file_write', function() local wr = file_write(fp, fcontents) eq(#fcontents, wr) eq(0, m.file_close(fp, false)) - eq(wr, lfs.attributes(filec).size) + eq(wr, luv.fs_stat(filec).size) eq(fcontents, io.open(filec):read('*a')) end) @@ -429,7 +430,7 @@ describe('file_write', function() shift = shift + size end eq(0, m.file_close(fp, false)) - eq(#fcontents, lfs.attributes(filec).size) + eq(#fcontents, luv.fs_stat(filec).size) eq(fcontents, io.open(filec):read('*a')) end) @@ -446,7 +447,7 @@ describe('file_write', function() shift = shift + size end eq(0, m.file_close(fp, false)) - eq(#fcontents, lfs.attributes(filec).size) + eq(#fcontents, luv.fs_stat(filec).size) eq(fcontents, io.open(filec):read('*a')) end) end) diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index c718244ea4..95a12f5b17 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -1,4 +1,4 @@ -local lfs = require('lfs') +local luv = require('luv') local bit = require('bit') local helpers = require('test.unit.helpers')(after_each) @@ -16,6 +16,7 @@ local to_cstr = helpers.to_cstr local OK = helpers.OK local FAIL = helpers.FAIL local NULL = helpers.NULL +local mkdir = helpers.mkdir local NODE_NORMAL = 0 local NODE_WRITABLE = 1 @@ -48,11 +49,11 @@ local function unset_bit(number, to_unset) end local function assert_file_exists(filepath) - neq(nil, lfs.attributes(filepath)) + neq(nil, luv.fs_stat(filepath)) end local function assert_file_does_not_exist(filepath) - eq(nil, lfs.attributes(filepath)) + eq(nil, luv.fs_stat(filepath)) end local function os_setperm(filename, perm) @@ -70,14 +71,14 @@ describe('fs.c', function() end before_each(function() - lfs.mkdir('unit-test-directory'); + mkdir('unit-test-directory'); io.open('unit-test-directory/test.file', 'w'):close() io.open('unit-test-directory/test_2.file', 'w'):close() - lfs.link('test.file', 'unit-test-directory/test_link.file', true) + luv.fs_symlink('test.file', 'unit-test-directory/test_link.file') - lfs.link('non_existing_file.file', 'unit-test-directory/test_broken_link.file', true) + luv.fs_symlink('non_existing_file.file', 'unit-test-directory/test_broken_link.file') -- The tests are invoked with an absolute path to `busted` executable. absolute_executable = arg[0] -- Split the absolute_executable path into a directory and filename. @@ -90,19 +91,19 @@ describe('fs.c', function() os.remove('unit-test-directory/test_link.file') os.remove('unit-test-directory/test_hlink.file') os.remove('unit-test-directory/test_broken_link.file') - lfs.rmdir('unit-test-directory') + luv.fs_rmdir('unit-test-directory') end) describe('os_dirname', function() itp('returns OK and writes current directory to the buffer', function() - local length = string.len(lfs.currentdir()) + 1 + local length = string.len(luv.cwd()) + 1 local buf = cstr(length, '') eq(OK, fs.os_dirname(buf, length)) - eq(lfs.currentdir(), ffi.string(buf)) + eq(luv.cwd(), ffi.string(buf)) end) itp('returns FAIL if the buffer is too small', function() - local length = string.len(lfs.currentdir()) + 1 + local length = string.len(luv.cwd()) + 1 local buf = cstr(length - 1, '') eq(FAIL, fs.os_dirname(buf, length - 1)) end) @@ -203,20 +204,20 @@ describe('fs.c', function() end) itp('returns the absolute path when given an executable relative to the current dir', function() - local old_dir = lfs.currentdir() + local old_dir = luv.cwd() - lfs.chdir(directory) + luv.chdir(directory) -- Rely on currentdir to resolve symlinks, if any. Testing against -- the absolute path taken from arg[0] may result in failure where -- the path has a symlink in it. - local canonical = lfs.currentdir() .. '/' .. executable_name + local canonical = luv.cwd() .. '/' .. executable_name local expected = exe(canonical) local relative_executable = './' .. executable_name local res = exe(relative_executable) -- Don't test yet; we need to chdir back first. - lfs.chdir(old_dir) + luv.chdir(old_dir) eq(expected, res) end) end) @@ -278,11 +279,11 @@ describe('fs.c', function() describe('os_fchown', function() local filename = 'unit-test-directory/test.file' itp('does not change owner and group if respective IDs are equal to -1', function() - local uid = lfs.attributes(filename, 'uid') - local gid = lfs.attributes(filename, 'gid') + local uid = luv.fs_stat(filename).uid + local gid = luv.fs_stat(filename).gid eq(0, os_fchown(filename, -1, -1)) - eq(uid, lfs.attributes(filename, 'uid')) - return eq(gid, lfs.attributes(filename, 'gid')) + eq(uid, luv.fs_stat(filename).uid) + return eq(gid, luv.fs_stat(filename).gid) end) -- Some systems may not have `id` utility. @@ -290,7 +291,7 @@ describe('fs.c', function() pending('skipped (missing `id` utility)', function() end) else itp('owner of a file may change the group of the file to any group of which that owner is a member', function() - local file_gid = lfs.attributes(filename, 'gid') + local file_gid = luv.fs_stat(filename).gid -- Gets ID of any group of which current user is a member except the -- group that owns the file. @@ -305,7 +306,7 @@ describe('fs.c', function() -- In that case we can not perform this test. if new_gid then eq(0, (os_fchown(filename, -1, new_gid))) - eq(new_gid, (lfs.attributes(filename, 'gid'))) + eq(new_gid, luv.fs_stat(filename).gid) end end) end @@ -548,7 +549,7 @@ describe('fs.c', function() --create the file local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber("700", 8)) --verify permissions - eq('rwx------', lfs.attributes(new_file)['permissions']) + eq(33216, luv.fs_stat(new_file).mode) eq(0, os_close(fd)) end) @@ -557,7 +558,7 @@ describe('fs.c', function() --create the file local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber("600", 8)) --verify permissions - eq('rw-------', lfs.attributes(new_file)['permissions']) + eq(33152, luv.fs_stat(new_file).mode) eq(0, os_close(fd)) end) @@ -766,7 +767,7 @@ describe('fs.c', function() eq(false, (os_isdir('unit-test-directory/new-dir'))) eq(0, (os_mkdir('unit-test-directory/new-dir', mode))) eq(true, (os_isdir('unit-test-directory/new-dir'))) - lfs.rmdir('unit-test-directory/new-dir') + luv.fs_rmdir('unit-test-directory/new-dir') end) end) @@ -801,7 +802,7 @@ describe('fs.c', function() eq(0, ret) eq(nil, failed_str) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) - lfs.rmdir('unit-test-directory/new-dir-recurse') + luv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) @@ -812,7 +813,7 @@ describe('fs.c', function() eq(0, ret) eq(nil, failed_str) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) - lfs.rmdir('unit-test-directory/new-dir-recurse') + luv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) @@ -823,7 +824,7 @@ describe('fs.c', function() eq(0, ret) eq(nil, failed_str) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) - lfs.rmdir('unit-test-directory/new-dir-recurse') + luv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) @@ -837,10 +838,10 @@ describe('fs.c', function() eq(true, os_isdir('unit-test-directory/new-dir-recurse/1')) eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2')) eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2/3')) - lfs.rmdir('unit-test-directory/new-dir-recurse/1/2/3') - lfs.rmdir('unit-test-directory/new-dir-recurse/1/2') - lfs.rmdir('unit-test-directory/new-dir-recurse/1') - lfs.rmdir('unit-test-directory/new-dir-recurse') + luv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2/3') + luv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2') + luv.fs_rmdir('unit-test-directory/new-dir-recurse/1') + luv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) end) end) @@ -851,7 +852,7 @@ describe('fs.c', function() end) itp('removes the given directory and returns 0', function() - lfs.mkdir('unit-test-directory/new-dir') + mkdir('unit-test-directory/new-dir') eq(0, os_rmdir('unit-test-directory/new-dir')) eq(false, (os_isdir('unit-test-directory/new-dir'))) end) @@ -1005,7 +1006,7 @@ describe('fs.c', function() file:write('some bytes to get filesize != 0') file:flush() file:close() - local size = lfs.attributes(path, 'size') + local size = luv.fs_stat(path).size local info = file_info_new() assert.is_true(fs.os_fileinfo(path, info)) eq(size, fs.os_fileinfo_size(info)) @@ -1019,7 +1020,7 @@ describe('fs.c', function() local info = file_info_new() assert.is_true(fs.os_fileinfo(path, info)) eq(1, fs.os_fileinfo_hardlinks(info)) - lfs.link(path, path_link) + luv.fs_link(path, path_link) assert.is_true(fs.os_fileinfo(path, info)) eq(2, fs.os_fileinfo_hardlinks(info)) end) @@ -1028,11 +1029,7 @@ describe('fs.c', function() describe('os_fileinfo_blocksize', function() itp('returns the correct blocksize of a file', function() local path = 'unit-test-directory/test.file' - -- there is a bug in luafilesystem where - -- `lfs.attributes path, 'blksize'` returns the wrong value: - -- https://github.com/keplerproject/luafilesystem/pull/44 - -- using this workaround for now: - local blksize = lfs.attributes(path).blksize + local blksize = luv.fs_stat(path).blksize local info = file_info_new() assert.is_true(fs.os_fileinfo(path, info)) if blksize then diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 1fc4e2496e..5808e2013a 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -1,4 +1,4 @@ -local lfs = require('lfs') +local luv = require('luv') local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) @@ -11,6 +11,7 @@ local to_cstr = helpers.to_cstr local NULL = helpers.NULL local OK = helpers.OK local FAIL = helpers.FAIL +local mkdir = helpers.mkdir cimport('string.h') local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h') @@ -21,11 +22,11 @@ local buffer = nil describe('path.c', function() describe('path_full_dir_name', function() setup(function() - lfs.mkdir('unit-test-directory') + mkdir('unit-test-directory') end) teardown(function() - lfs.rmdir('unit-test-directory') + luv.fs_rmdir('unit-test-directory') end) local function path_full_dir_name(directory, buf, len) @@ -35,34 +36,34 @@ describe('path.c', function() before_each(function() -- Create empty string buffer which will contain the resulting path. - length = string.len(lfs.currentdir()) + 22 + length = string.len(luv.cwd()) + 22 buffer = cstr(length, '') end) itp('returns the absolute directory name of a given relative one', function() local result = path_full_dir_name('..', buffer, length) eq(OK, result) - local old_dir = lfs.currentdir() - lfs.chdir('..') - local expected = lfs.currentdir() - lfs.chdir(old_dir) + local old_dir = luv.cwd() + luv.chdir('..') + local expected = luv.cwd() + luv.chdir(old_dir) eq(expected, (ffi.string(buffer))) end) itp('returns the current directory name if the given string is empty', function() eq(OK, (path_full_dir_name('', buffer, length))) - eq(lfs.currentdir(), (ffi.string(buffer))) + eq(luv.cwd(), (ffi.string(buffer))) end) itp('works with a normal relative dir', function() local result = path_full_dir_name('unit-test-directory', buffer, length) - eq(lfs.currentdir() .. '/unit-test-directory', (ffi.string(buffer))) + eq(luv.cwd() .. '/unit-test-directory', (ffi.string(buffer))) eq(OK, result) end) itp('works with a non-existing relative dir', function() local result = path_full_dir_name('does-not-exist', buffer, length) - eq(lfs.currentdir() .. '/does-not-exist', (ffi.string(buffer))) + eq(luv.cwd() .. '/does-not-exist', (ffi.string(buffer))) eq(OK, result) end) @@ -268,27 +269,27 @@ describe('path.c', function() end) describe('path_try_shorten_fname', function() - local cwd = lfs.currentdir() + local cwd = luv.cwd() before_each(function() - lfs.mkdir('ut_directory') + mkdir('ut_directory') end) after_each(function() - lfs.chdir(cwd) - lfs.rmdir('ut_directory') + luv.chdir(cwd) + luv.fs_rmdir('ut_directory') end) describe('path_try_shorten_fname', function() itp('returns shortened path if possible', function() - lfs.chdir('ut_directory') - local full = to_cstr(lfs.currentdir() .. '/subdir/file.txt') + luv.chdir('ut_directory') + local full = to_cstr(luv.cwd() .. '/subdir/file.txt') eq('subdir/file.txt', (ffi.string(cimp.path_try_shorten_fname(full)))) end) itp('returns `full_path` if a shorter version is not possible', function() - local old = lfs.currentdir() - lfs.chdir('ut_directory') + local old = luv.cwd() + luv.chdir('ut_directory') local full = old .. '/subdir/file.txt' eq(full, (ffi.string(cimp.path_try_shorten_fname(to_cstr(full))))) end) @@ -300,7 +301,7 @@ describe('path_try_shorten_fname', function() end) describe('path.c path_guess_exepath', function() - local cwd = lfs.currentdir() + local cwd = luv.cwd() for _,name in ipairs({'./nvim', '.nvim', 'foo/nvim'}) do itp('"'..name..'" returns name catenated with CWD', function() @@ -354,7 +355,7 @@ end) describe('path.c', function() setup(function() - lfs.mkdir('unit-test-directory'); + mkdir('unit-test-directory'); io.open('unit-test-directory/test.file', 'w'):close() -- Since the tests are executed, they are called by an executable. We use @@ -368,7 +369,7 @@ describe('path.c', function() teardown(function() os.remove('unit-test-directory/test.file') - lfs.rmdir('unit-test-directory') + luv.fs_rmdir('unit-test-directory') end) describe('vim_FullName', function() @@ -420,7 +421,7 @@ describe('path.c', function() end) itp('concatenates filename if it does not contain a slash', function() - local expected = lfs.currentdir() .. '/test.file' + local expected = luv.cwd() .. '/test.file' local filename = 'test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -430,7 +431,7 @@ describe('path.c', function() end) itp('concatenates directory name if it does not contain a slash', function() - local expected = lfs.currentdir() .. '/..' + local expected = luv.cwd() .. '/..' local filename = '..' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -440,10 +441,10 @@ describe('path.c', function() end) itp('enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', function() - local old_dir = lfs.currentdir() - lfs.chdir('..') - local expected = lfs.currentdir() .. '/test.file' - lfs.chdir(old_dir) + local old_dir = luv.cwd() + luv.chdir('..') + local expected = luv.cwd() .. '/test.file' + luv.chdir(old_dir) local filename = '../test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -472,7 +473,7 @@ describe('path.c', function() end) itp('works with some "normal" relative path with directories', function() - local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local expected = luv.cwd() .. '/unit-test-directory/test.file' local filename = 'unit-test-directory/test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -482,7 +483,7 @@ describe('path.c', function() end) itp('does not modify the given filename', function() - local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local expected = luv.cwd() .. '/unit-test-directory/test.file' local filename = to_cstr('unit-test-directory/test.file') local buflen = string.len(expected) + 1 local buf = cstr(buflen, '') @@ -505,7 +506,7 @@ describe('path.c', function() end) itp('does not remove trailing slash from non-existing relative directory #20847', function() - local expected = lfs.currentdir() .. '/non_existing_dir/' + local expected = luv.cwd() .. '/non_existing_dir/' local filename = 'non_existing_dir/' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -515,7 +516,7 @@ describe('path.c', function() end) itp('expands "./" to the current directory #7117', function() - local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local expected = luv.cwd() .. '/unit-test-directory/test.file' local filename = './unit-test-directory/test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -525,7 +526,7 @@ describe('path.c', function() end) itp('collapses "foo/../foo" to "foo" #7117', function() - local expected = lfs.currentdir() .. '/unit-test-directory/test.file' + local expected = luv.cwd() .. '/unit-test-directory/test.file' local filename = 'unit-test-directory/../unit-test-directory/test.file' local buflen = get_buf_len(expected, filename) local do_expand = 1 @@ -542,8 +543,8 @@ describe('path.c', function() return ffi.string(c_file) end - before_each(function() lfs.mkdir('CamelCase') end) - after_each(function() lfs.rmdir('CamelCase') end) + before_each(function() mkdir('CamelCase') end) + after_each(function() luv.fs_rmdir('CamelCase') end) if ffi.os == 'Windows' or ffi.os == 'OSX' then itp('Corrects the case of file names in Mac and Windows', function() diff --git a/test/unit/preload.lua b/test/unit/preload.lua index 841e19b878..c2d051d98a 100644 --- a/test/unit/preload.lua +++ b/test/unit/preload.lua @@ -3,5 +3,4 @@ -- for more information about this. local ffi = require('ffi') local helpers = require('test.unit.helpers')(nil) -local lfs = require('lfs') local preprocess = require('test.unit.preprocess') diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 1073855a7d..88f7a14d1f 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -199,12 +199,6 @@ function Gcc:preprocess(previous_defines, ...) {pseudoheader_fname}) defines = self:filter_standard_defines(defines) - -- lfs = require("lfs") - -- print("CWD: #{lfs.currentdir!}") - -- print("CMD: #{cmd}") - -- io.stderr\write("CWD: #{lfs.currentdir!}\n") - -- io.stderr\write("CMD: #{cmd}\n") - local declarations = repeated_read_cmd(self.path, self.preprocessor_extra_flags, self.get_declarations_extra_flags, diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua index 44bd19c1d2..e35490a561 100644 --- a/test/unit/tempfile_spec.lua +++ b/test/unit/tempfile_spec.lua @@ -1,4 +1,3 @@ -local lfs = require('lfs') local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) @@ -30,7 +29,7 @@ describe('tempfile related functions', function() -- os_file_is_writable returns 2 for a directory which we have rights -- to write into. eq(lib.os_file_is_writable(helpers.to_cstr(dir)), 2) - for entry in lfs.dir(dir) do + for entry in vim.fs.dir(dir) do assert.True(entry == '.' or entry == '..') end end) diff --git a/test/unit/undo_spec.lua b/test/unit/undo_spec.lua index cdc5d3a99e..9261eca19d 100644 --- a/test/unit/undo_spec.lua +++ b/test/unit/undo_spec.lua @@ -1,6 +1,6 @@ local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) -local lfs = require('lfs') +local luv = require('luv') local child_call_once = helpers.child_call_once local sleep = helpers.sleep @@ -9,6 +9,7 @@ local cimport = helpers.cimport local to_cstr = helpers.to_cstr local neq = helpers.neq local eq = helpers.eq +local mkdir = helpers.mkdir cimport('./src/nvim/ex_cmds_defs.h') cimport('./src/nvim/buffer_defs.h') @@ -44,14 +45,14 @@ end) describe('u_write_undo', function() setup(function() - lfs.mkdir('unit-test-directory') - lfs.chdir('unit-test-directory') - options.p_udir = to_cstr(lfs.currentdir()) -- set p_udir to be the test dir + mkdir('unit-test-directory') + luv.chdir('unit-test-directory') + options.p_udir = to_cstr(luv.cwd()) -- set p_udir to be the test dir end) teardown(function() - lfs.chdir('..') - local success, err = lfs.rmdir('unit-test-directory') + luv.chdir('..') + local success, err = luv.fs_rmdir('unit-test-directory') if not success then print(err) -- inform tester if directory fails to delete end @@ -102,7 +103,7 @@ describe('u_write_undo', function() local test_permission_file = io.open(test_file_name, "w") test_permission_file:write("testing permissions") test_permission_file:close() - local test_permissions = lfs.attributes(test_file_name).permissions + local test_permissions = luv.fs_stat(test_file_name).mode -- Create vim buffer local c_file = to_cstr(test_file_name) @@ -115,7 +116,7 @@ describe('u_write_undo', function() local undo_file_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false)) -- Find out the permissions of the new file - local permissions = lfs.attributes(undo_file_name).permissions + local permissions = luv.fs_stat(undo_file_name).mode eq(test_permissions, permissions) -- delete the file now that we're done with it. @@ -130,7 +131,7 @@ describe('u_write_undo', function() end) itp('writes an undofile only readable by the user if the buffer is unnamed', function() - local correct_permissions = "rw-------" + local correct_permissions = 33152 local undo_file_name = "test.undo" -- Create vim buffer @@ -140,7 +141,7 @@ describe('u_write_undo', function() u_write_undo(undo_file_name, false, file_buffer, buffer_hash) -- Find out the permissions of the new file - local permissions = lfs.attributes(undo_file_name).permissions + local permissions = luv.fs_stat(undo_file_name).mode eq(correct_permissions, permissions) -- delete the file now that we're done with it. @@ -172,13 +173,13 @@ describe('u_write_undo', function() u_write_undo(nil, false, file_buffer, buffer_hash) local correct_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false)) - local file_last_modified = lfs.attributes(correct_name).modification + local file_last_modified = luv.fs_stat(correct_name).mtime.sec sleep(1000) -- Ensure difference in timestamps. file_buffer.b_u_numhead = 1 -- Mark it as if there are changes u_write_undo(nil, false, file_buffer, buffer_hash) - local file_last_modified_2 = lfs.attributes(correct_name).modification + local file_last_modified_2 = luv.fs_stat(correct_name).mtime.sec -- print(file_last_modified, file_last_modified_2) neq(file_last_modified, file_last_modified_2) -- cgit From 7190dba017e3aac0409c73ff1c954d18858cb3c9 Mon Sep 17 00:00:00 2001 From: ii14 <59243201+ii14@users.noreply.github.com> Date: Thu, 6 Apr 2023 22:39:50 +0200 Subject: refactor: remove use of reserved c++ keywords libnvim couldn't be easily used in C++ due to the use of reserved keywords. Additionally, add explicit casts to *alloc function calls used in inline functions, as C++ doesn't allow implicit casts from void pointers. --- test/unit/fixtures/multiqueue.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'test/unit') diff --git a/test/unit/fixtures/multiqueue.c b/test/unit/fixtures/multiqueue.c index a8dca0a844..4f4f5989d9 100644 --- a/test/unit/fixtures/multiqueue.c +++ b/test/unit/fixtures/multiqueue.c @@ -7,13 +7,13 @@ #include "multiqueue.h" -void ut_multiqueue_put(MultiQueue *this, const char *str) +void ut_multiqueue_put(MultiQueue *self, const char *str) { - multiqueue_put(this, NULL, 1, str); + multiqueue_put(self, NULL, 1, str); } -const char *ut_multiqueue_get(MultiQueue *this) +const char *ut_multiqueue_get(MultiQueue *self) { - Event event = multiqueue_get(this); + Event event = multiqueue_get(self); return event.argv[0]; } -- cgit From 8f69c5ed450337b9f77c50f9ee0d3eb32f649ca6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 07:11:59 +0800 Subject: vim-patch:8.2.{0695,0725,0734,0753,0818,0819,0822} (#23075) vim-patch:8.2.0695: Vim9: cannot define a function inside a function Problem: Vim9: cannot define a function inside a function. Solution: Initial support for :def inside :def. https://github.com/vim/vim/commit/04b12697838b232b8b17c553ccc74cf1f1bdb81c vim-patch:8.2.0725: Vim9: cannot call a function declared later in Vim9 script Problem: Vim9: cannot call a function declared later in Vim9 script. Solution: Make two passes through the script file. https://github.com/vim/vim/commit/09689a02840be40fa7bb10b1921fb5bc5b2908f1 vim-patch:8.2.0734: Vim9: leaking memory when using :finish Problem: Vim9: leaking memory when using :finish. Solution: Do not check for next line in third pass. https://github.com/vim/vim/commit/04816717dfea6e2469ff4c9d40f68b59aaf03724 vim-patch:8.2.0753: Vim9: expressions are evaluated in the discovery phase Problem: Vim9: expressions are evaluated in the discovery phase. Solution: Bail out if an expression is not a constant. Require a type for declared constants. https://github.com/vim/vim/commit/32e351179eacfc84f64cd5029e221582d400bb38 vim-patch:8.2.0818: Vim9: using a discovery phase doesn't work well Problem: Vim9: using a discovery phase doesn't work well. Solution: Remove the discovery phase, instead compile a function only when it is used. Add :defcompile to compile def functions earlier. https://github.com/vim/vim/commit/822ba24743af9ee1b5e7f656a7a61a38f3638bca vim-patch:8.2.0819: compiler warning for unused variable Problem: Compiler warning for unused variable. Solution: Remove the variable. https://github.com/vim/vim/commit/f40e51a880a95f94dbbbecc9476559506c2cc345 vim-patch:8.2.0822: Vim9: code left over from discovery phase Problem: Vim9: code left over from discovery phase. Solution: Remove the dead code. https://github.com/vim/vim/commit/2eec37926db6d31beb36f162ac00357a30c093c8 Co-authored-by: Bram Moolenaar --- test/unit/eval/helpers.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 9dd6b76de2..0694fceaec 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -512,7 +512,7 @@ end local function eval0(expr) local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}), eval.tv_clear) - if eval.eval0(to_cstr(expr), tv, nil, true) == 0 then + if eval.eval0(to_cstr(expr), tv, nil, eval.EVAL_EVALUATE) == 0 then return nil else return tv -- cgit From bd83b587b18bb6f2ac555a992fa5b7d907de7e79 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Apr 2023 07:22:01 +0800 Subject: vim-patch:8.2.1047: Vim9: script cannot use line continuation like :def function Problem: Vim9: script cannot use line continuation like in a :def function. Solution: Pass the getline function pointer to the eval() functions. Use it for addition and multiplication operators. https://github.com/vim/vim/commit/5409f5d8c95007216ae1190565a7a8ee9ebd7100 Omit source_nextline() and eval_next_non_blank(): Vim9 script only. N/A patches for version.c: vim-patch:8.2.1048: build failure without the eval feature Problem: Build failure without the eval feature. Solution: Add dummy typedef. https://github.com/vim/vim/commit/9d40c63c7dc8c3eb3886c58dcd334bc7f37eceba vim-patch:8.2.1052: build failure with older compilers Problem: Build failure with older compilers. Solution: Move declaration to start of block. https://github.com/vim/vim/commit/7acde51832f383f9a6d2e740cd0420b433ea841a Co-authored-by: Bram Moolenaar --- test/unit/eval/helpers.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua index 0694fceaec..883f01bd84 100644 --- a/test/unit/eval/helpers.lua +++ b/test/unit/eval/helpers.lua @@ -512,7 +512,8 @@ end local function eval0(expr) local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}), eval.tv_clear) - if eval.eval0(to_cstr(expr), tv, nil, eval.EVAL_EVALUATE) == 0 then + local evalarg = ffi.new('evalarg_T', {eval_flags = eval.EVAL_EVALUATE}) + if eval.eval0(to_cstr(expr), tv, nil, evalarg) == 0 then return nil else return tv -- cgit From 3d29424fb9960085f09f7e322abf204eab9287b9 Mon Sep 17 00:00:00 2001 From: Lewis Russell Date: Mon, 3 Apr 2023 12:01:23 +0100 Subject: refactor(unit): add type annotations --- test/unit/formatc.lua | 2 + test/unit/helpers.lua | 314 ++++++++++++++++++++++++++--------------------- test/unit/preprocess.lua | 176 ++++++++++++++------------ test/unit/set.lua | 44 +++---- 4 files changed, 295 insertions(+), 241 deletions(-) (limited to 'test/unit') diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua index 2fd37c599a..c94f0d88f7 100644 --- a/test/unit/formatc.lua +++ b/test/unit/formatc.lua @@ -154,6 +154,8 @@ local C_keywords = set { -- luacheck: ignore -- -- The first one will have a lot of false positives (the line '{' for -- example), the second one is more unique. +--- @param string +--- @return string local function formatc(str) local toks = TokeniseC(str) local result = {} diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 708929ad9f..10b7594a88 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -14,20 +14,15 @@ local map = global_helpers.tbl_map local eq = global_helpers.eq local trim = global_helpers.trim --- C constants. -local NULL = ffi.cast('void*', 0) - -local OK = 1 -local FAIL = 0 - -local cimport - -- add some standard header locations for _, p in ipairs(Paths.include_paths) do Preprocess.add_to_include_path(p) end -local child_pid = nil +local child_pid = nil --- @type integer +--- @generic F: function +--- @param func F +--- @return F local function only_separate(func) return function(...) if child_pid ~= 0 then @@ -36,9 +31,20 @@ local function only_separate(func) return func(...) end end -local child_calls_init = {} -local child_calls_mod = nil -local child_calls_mod_once = nil + +--- @class ChildCall +--- @field func function +--- @field args any[] + +--- @class ChildCallLog +--- @field func string +--- @field args any[] +--- @field ret any? + +local child_calls_init = {} --- @type ChildCall[] +local child_calls_mod = nil --- @type ChildCall[] +local child_calls_mod_once = nil --- @type ChildCall[]? + local function child_call(func, ret) return function(...) local child_calls = child_calls_mod or child_calls_init @@ -53,16 +59,16 @@ end -- Run some code at the start of the child process, before running the test -- itself. Is supposed to be run in `before_each`. +--- @param func function local function child_call_once(func, ...) if child_pid ~= 0 then - child_calls_mod_once[#child_calls_mod_once + 1] = { - func=func, args={...}} + child_calls_mod_once[#child_calls_mod_once + 1] = { func = func, args = {...} } else func(...) end end -local child_cleanups_mod_once = nil +local child_cleanups_mod_once = nil --- @type ChildCall[]? -- Run some code at the end of the child process, before exiting. Is supposed to -- be run in `before_each` because `after_each` is run after child has exited. @@ -125,8 +131,9 @@ local pragma_pack_id = 1 -- some things are just too complex for the LuaJIT C parser to digest. We -- usually don't need them anyway. +--- @param body string local function filter_complex_blocks(body) - local result = {} + local result = {} --- @type string[] for line in body:gmatch("[^\r\n]+") do if not (string.find(line, "(^)", 1, true) ~= nil @@ -153,18 +160,20 @@ typedef struct { char bytes[16]; } __attribute__((aligned(16))) __uint128_t; typedef struct { char bytes[16]; } __attribute__((aligned(16))) __float128; ]] -local preprocess_cache_init = {} +local preprocess_cache_init = {} --- @type table local previous_defines_mod = '' -local preprocess_cache_mod = nil +local preprocess_cache_mod = nil --- @type table local function is_child_cdefs() - return (os.getenv('NVIM_TEST_MAIN_CDEFS') ~= '1') + return os.getenv('NVIM_TEST_MAIN_CDEFS') ~= '1' end -- use this helper to import C files, you can pass multiple paths at once, -- this helper will return the C namespace of the nvim library. -cimport = function(...) - local previous_defines, preprocess_cache, cdefs +local function cimport(...) + local previous_defines --- @type string + local preprocess_cache --- @type table + local cdefs if is_child_cdefs() and preprocess_cache_mod then preprocess_cache = preprocess_cache_mod previous_defines = previous_defines_mod @@ -180,7 +189,7 @@ cimport = function(...) path = './' .. path end if not preprocess_cache[path] then - local body + local body --- @type string body, previous_defines = Preprocess.preprocess(previous_defines, path) -- format it (so that the lines are "unique" statements), also filter out -- Objective-C blocks @@ -202,6 +211,7 @@ cimport = function(...) -- (they are needed in the right order with the struct definitions, -- otherwise luajit has wrong memory layouts for the sturcts) if line:match("#pragma%s+pack") then + --- @type string line = line .. " // " .. pragma_pack_id pragma_pack_id = pragma_pack_id + 1 end @@ -229,20 +239,21 @@ cimport = function(...) return lib end -local cimport_immediate = function(...) +local function cimport_immediate(...) local saved_pid = child_pid child_pid = 0 local err, emsg = pcall(cimport, ...) child_pid = saved_pid if not err then - emsg = tostring(emsg) - io.stderr:write(emsg .. '\n') + io.stderr:write(tostring(emsg) .. '\n') assert(false) else return lib end end +--- @param preprocess_cache table +--- @param path string local function _cimportstr(preprocess_cache, path) if imported:contains(path) then return lib @@ -265,12 +276,14 @@ end local function alloc_log_new() local log = { - log={}, - lib=cimport('./src/nvim/memory.h'), - original_functions={}, + log={}, --- @type ChildCallLog[] + lib=cimport('./src/nvim/memory.h'), --- @type table + original_functions={}, --- @type table null={['\0:is_null']=true}, } + local allocator_functions = {'malloc', 'free', 'calloc', 'realloc'} + function log:save_original_functions() for _, funcname in ipairs(allocator_functions) do if not self.original_functions[funcname] then @@ -278,13 +291,16 @@ local function alloc_log_new() end end end + log.save_original_functions = child_call(log.save_original_functions) + function log:set_mocks() for _, k in ipairs(allocator_functions) do do local kk = k self.lib['mem_' .. k] = function(...) - local log_entry = {func=kk, args={...}} + --- @type ChildCallLog + local log_entry = { func = kk, args = {...} } self.log[#self.log + 1] = log_entry if kk == 'free' then self.original_functions[kk](...) @@ -305,17 +321,21 @@ local function alloc_log_new() end end end + log.set_mocks = child_call(log.set_mocks) + function log:clear() self.log = {} end + function log:check(exp) eq(exp, self.log) self:clear() end + function log:clear_tmp_allocs(clear_null_frees) - local toremove = {} - local allocs = {} + local toremove = {} --- @type integer[] + local allocs = {} --- @type table for i, v in ipairs(self.log) do if v.func == 'malloc' or v.func == 'calloc' then allocs[tostring(v.ret)] = i @@ -338,26 +358,20 @@ local function alloc_log_new() table.remove(self.log, toremove[i]) end end - function log:restore_original_functions() - -- Do nothing: set mocks live in a separate process - return - --[[ - [ for k, v in pairs(self.original_functions) do - [ self.lib['mem_' .. k] = v - [ end - ]] - end + function log:setup() log:save_original_functions() log:set_mocks() end + function log:before_each() - return end + function log:after_each() - log:restore_original_functions() end + log:setup() + return log end @@ -374,98 +388,109 @@ local function to_cstr(string) end cimport_immediate('./test/unit/fixtures/posix.h') -local sc = { - fork = function() - return tonumber(ffi.C.fork()) - end, - pipe = function() - local ret = ffi.new('int[2]', {-1, -1}) - ffi.errno(0) - local res = ffi.C.pipe(ret) - if (res ~= 0) then + +local sc = {} + +function sc.fork() + return tonumber(ffi.C.fork()) +end + +function sc.pipe() + local ret = ffi.new('int[2]', {-1, -1}) + ffi.errno(0) + local res = ffi.C.pipe(ret) + if (res ~= 0) then + local err = ffi.errno(0) + assert(res == 0, ("pipe() error: %u: %s"):format( + err, ffi.string(ffi.C.strerror(err)))) + end + assert(ret[0] ~= -1 and ret[1] ~= -1) + return ret[0], ret[1] +end + +--- @return string +function sc.read(rd, len) + local ret = ffi.new('char[?]', len, {0}) + local total_bytes_read = 0 + ffi.errno(0) + while total_bytes_read < len do + local bytes_read = tonumber(ffi.C.read( + rd, + ffi.cast('void*', ret + total_bytes_read), + len - total_bytes_read)) + if bytes_read == -1 then local err = ffi.errno(0) - assert(res == 0, ("pipe() error: %u: %s"):format( - err, ffi.string(ffi.C.strerror(err)))) - end - assert(ret[0] ~= -1 and ret[1] ~= -1) - return ret[0], ret[1] - end, - read = function(rd, len) - local ret = ffi.new('char[?]', len, {0}) - local total_bytes_read = 0 - ffi.errno(0) - while total_bytes_read < len do - local bytes_read = tonumber(ffi.C.read( - rd, - ffi.cast('void*', ret + total_bytes_read), - len - total_bytes_read)) - if bytes_read == -1 then - local err = ffi.errno(0) - if err ~= ffi.C.kPOSIXErrnoEINTR then - assert(false, ("read() error: %u: %s"):format( - err, ffi.string(ffi.C.strerror(err)))) - end - elseif bytes_read == 0 then - break - else - total_bytes_read = total_bytes_read + bytes_read + if err ~= ffi.C.kPOSIXErrnoEINTR then + assert(false, ("read() error: %u: %s"):format( + err, ffi.string(ffi.C.strerror(err)))) end + elseif bytes_read == 0 then + break + else + total_bytes_read = total_bytes_read + bytes_read end - return ffi.string(ret, total_bytes_read) - end, - write = function(wr, s) - local wbuf = to_cstr(s) - local total_bytes_written = 0 - ffi.errno(0) - while total_bytes_written < #s do - local bytes_written = tonumber(ffi.C.write( - wr, - ffi.cast('void*', wbuf + total_bytes_written), - #s - total_bytes_written)) - if bytes_written == -1 then - local err = ffi.errno(0) - if err ~= ffi.C.kPOSIXErrnoEINTR then - assert(false, ("write() error: %u: %s ('%s')"):format( - err, ffi.string(ffi.C.strerror(err)), s)) - end - elseif bytes_written == 0 then - break - else - total_bytes_written = total_bytes_written + bytes_written + end + return ffi.string(ret, total_bytes_read) +end + +function sc.write(wr, s) + local wbuf = to_cstr(s) + local total_bytes_written = 0 + ffi.errno(0) + while total_bytes_written < #s do + local bytes_written = tonumber(ffi.C.write( + wr, + ffi.cast('void*', wbuf + total_bytes_written), + #s - total_bytes_written)) + if bytes_written == -1 then + local err = ffi.errno(0) + if err ~= ffi.C.kPOSIXErrnoEINTR then + assert(false, ("write() error: %u: %s ('%s')"):format( + err, ffi.string(ffi.C.strerror(err)), s)) end + elseif bytes_written == 0 then + break + else + total_bytes_written = total_bytes_written + bytes_written end - return total_bytes_written - end, - close = ffi.C.close, - wait = function(pid) - ffi.errno(0) - local stat_loc = ffi.new('int[1]', {0}) - while true do - local r = ffi.C.waitpid(pid, stat_loc, ffi.C.kPOSIXWaitWUNTRACED) - if r == -1 then - local err = ffi.errno(0) - if err == ffi.C.kPOSIXErrnoECHILD then - break - elseif err ~= ffi.C.kPOSIXErrnoEINTR then - assert(false, ("waitpid() error: %u: %s"):format( - err, ffi.string(ffi.C.strerror(err)))) - end - else - assert(r == pid) + end + return total_bytes_written +end + +sc.close = ffi.C.close + +--- @param pid integer +--- @return integer +function sc.wait(pid) + ffi.errno(0) + local stat_loc = ffi.new('int[1]', {0}) + while true do + local r = ffi.C.waitpid(pid, stat_loc, ffi.C.kPOSIXWaitWUNTRACED) + if r == -1 then + local err = ffi.errno(0) + if err == ffi.C.kPOSIXErrnoECHILD then + break + elseif err ~= ffi.C.kPOSIXErrnoEINTR then + assert(false, ("waitpid() error: %u: %s"):format( + err, ffi.string(ffi.C.strerror(err)))) end + else + assert(r == pid) end - return stat_loc[0] - end, - exit = ffi.C._exit, -} + end + return stat_loc[0] +end + +sc.exit = ffi.C._exit +--- @param lst string[] +--- @return string local function format_list(lst) - local ret = '' + local ret = {} --- @type string[] for _, v in ipairs(lst) do - if ret ~= '' then ret = ret .. ', ' end - ret = ret .. assert:format({v, n=1})[1] + ret[#ret+1] = assert:format({v, n=1})[1] end - return ret + return table.concat(ret, ', ') end if os.getenv('NVIM_TEST_PRINT_SYSCALLS') == '1' then @@ -513,19 +538,26 @@ local tracehelp = dedent([[ ]]) local function child_sethook(wr) - local trace_level = os.getenv('NVIM_TEST_TRACE_LEVEL') - if not trace_level or trace_level == '' then - trace_level = 0 - else - trace_level = tonumber(trace_level) + local trace_level_str = os.getenv('NVIM_TEST_TRACE_LEVEL') + local trace_level = 0 + if trace_level_str and trace_level_str ~= '' then + --- @type number + trace_level = assert(tonumber(trace_level_str)) end + if trace_level <= 0 then return end + local trace_only_c = trace_level <= 1 + --- @type debuginfo?, string?, integer local prev_info, prev_reason, prev_lnum + + --- @param reason string + --- @param lnum integer + --- @param use_prev boolean local function hook(reason, lnum, use_prev) - local info = nil + local info = nil --- @type debuginfo? if use_prev then info = prev_info elseif reason ~= 'tail return' then -- tail return @@ -533,6 +565,7 @@ local function child_sethook(wr) end if trace_only_c and (not info or info.what ~= 'C') and not use_prev then + --- @cast info -nil if info.source:sub(-9) == '_spec.lua' then prev_info = info prev_reason = 'saved' @@ -573,12 +606,8 @@ local function child_sethook(wr) end -- assert(-1 <= lnum and lnum <= 99999) - local lnum_s - if lnum == -1 then - lnum_s = 'nknwn' - else - lnum_s = ('%u'):format(lnum) - end + local lnum_s = lnum == -1 and 'nknwn' or ('%u'):format(lnum) + --- @type string local msg = ( -- lua does not support %* '' .. msgchar @@ -600,6 +629,7 @@ end local trace_end_msg = ('E%s\n'):format((' '):rep(hook_msglen - 2)) +--- @type function local _debug_log local debug_log = only_separate(function(...) @@ -607,6 +637,7 @@ local debug_log = only_separate(function(...) end) local function itp_child(wr, func) + --- @param s string _debug_log = function(s) s = s:sub(1, hook_msglen - 2) sc.write(wr, '>' .. s .. (' '):rep(hook_msglen - 2 - #s) .. '\n') @@ -638,7 +669,7 @@ local function itp_child(wr, func) end local function check_child_err(rd) - local trace = {} + local trace = {} --- @type string[] local did_traceline = false local maxtrace = tonumber(os.getenv('NVIM_TEST_MAXTRACE')) or 1024 while true do @@ -668,11 +699,14 @@ local function check_child_err(rd) local len = tonumber(len_s) neq(0, len) if os.getenv('NVIM_TEST_TRACE_ON_ERROR') == '1' and #trace ~= 0 then + --- @type string err = '\nTest failed, trace:\n' .. tracehelp for _, traceline in ipairs(trace) do + --- @type string err = err .. traceline end end + --- @type string err = err .. sc.read(rd, len + 1) end local eres = sc.read(rd, 2) @@ -686,10 +720,12 @@ local function check_child_err(rd) end end if not did_traceline then + --- @type string err = err .. '\nNo end of trace occurred' end local cc_err, cc_emsg = pcall(check_cores, Paths.test_luajit_prg, true) if not cc_err then + --- @type string err = err .. '\ncheck_cores failed: ' .. cc_emsg end end @@ -822,9 +858,9 @@ local module = { lib = lib, cstr = cstr, to_cstr = to_cstr, - NULL = NULL, - OK = OK, - FAIL = FAIL, + NULL = ffi.cast('void*', 0), + OK = 1, + FAIL = 0, alloc_log_new = alloc_log_new, gen_itp = gen_itp, only_separate = only_separate, diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index 88f7a14d1f..c5fb62dce5 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -7,6 +7,9 @@ local global_helpers = require('test.helpers') local argss_to_cmd = global_helpers.argss_to_cmd local repeated_read_cmd = global_helpers.repeated_read_cmd +--- @alias Compiler {path: string[], type: string} + +--- @type Compiler[] local ccs = {} local env_cc = os.getenv("CC") @@ -27,6 +30,8 @@ table.insert(ccs, {path = {"/usr/bin/env", "clang"}, type = "clang"}) table.insert(ccs, {path = {"/usr/bin/env", "icc"}, type = "gcc"}) -- parse Makefile format dependencies into a Lua table +--- @param deps string +--- @return string[] local function parse_make_deps(deps) -- remove line breaks and line concatenators deps = deps:gsub("\n", ""):gsub("\\", "") @@ -36,7 +41,7 @@ local function parse_make_deps(deps) deps = deps:gsub(" +", " ") -- split according to token (space in this case) - local headers = {} + local headers = {} --- @type string[] for token in deps:gmatch("[^%s]+") do -- headers[token] = true headers[#headers + 1] = token @@ -53,57 +58,58 @@ local function parse_make_deps(deps) return headers end --- will produce a string that represents a meta C header file that includes --- all the passed in headers. I.e.: --- --- headerize({"stdio.h", "math.h"}, true) --- produces: --- #include --- #include --- --- headerize({"vim.h", "memory.h"}, false) --- produces: --- #include "vim.h" --- #include "memory.h" +--- will produce a string that represents a meta C header file that includes +--- all the passed in headers. I.e.: +--- +--- headerize({"stdio.h", "math.h"}, true) +--- produces: +--- #include +--- #include +--- +--- headerize({"vim.h", "memory.h"}, false) +--- produces: +--- #include "vim.h" +--- #include "memory.h" +--- @param headers string[] +--- @param global? boolean +--- @return string local function headerize(headers, global) - local pre = '"' - local post = pre - if global then - pre = "<" - post = ">" - end - - local formatted = {} + local fmt = global and '#include <%s>' or '#include "%s"' + local formatted = {} --- @type string[] for _, hdr in ipairs(headers) do - formatted[#formatted + 1] = "#include " .. - tostring(pre) .. - tostring(hdr) .. - tostring(post) + formatted[#formatted + 1] = string.format(fmt, hdr) end return table.concat(formatted, "\n") end +--- @class Gcc +--- @field path string +--- @field preprocessor_extra_flags string[] +--- @field get_defines_extra_flags string[] +--- @field get_declarations_extra_flags string[] local Gcc = { preprocessor_extra_flags = {}, get_defines_extra_flags = {'-std=c99', '-dM', '-E'}, get_declarations_extra_flags = {'-std=c99', '-P', '-E'}, } +--- @param name string +--- @param args string[]? +--- @param val string? function Gcc:define(name, args, val) - local define = '-D' .. name - if args ~= nil then - define = define .. '(' .. table.concat(args, ',') .. ')' + local define = string.format('-D%s', name) + if args then + define = string.format('%s(%s)', define, table.concat(args, ',')) end - if val ~= nil then - define = define .. '=' .. val + if val then + define = string.format('%s=%s', define, val) end self.preprocessor_extra_flags[#self.preprocessor_extra_flags + 1] = define end function Gcc:undefine(name) - self.preprocessor_extra_flags[#self.preprocessor_extra_flags + 1] = ( - '-U' .. name) + self.preprocessor_extra_flags[#self.preprocessor_extra_flags + 1] = '-U' .. name end function Gcc:init_defines() @@ -128,6 +134,8 @@ function Gcc:init_defines() self:undefine('__BLOCKS__') end +--- @param obj? Compiler +--- @return Gcc function Gcc:new(obj) obj = obj or {} setmetatable(obj, self) @@ -136,6 +144,7 @@ function Gcc:new(obj) return obj end +--- @param ... string function Gcc:add_to_include_path(...) for i = 1, select('#', ...) do local path = select(i, ...) @@ -145,110 +154,115 @@ function Gcc:add_to_include_path(...) end -- returns a list of the headers files upon which this file relies +--- @param hdr string +--- @return string[]? function Gcc:dependencies(hdr) + --- @type string local cmd = argss_to_cmd(self.path, {'-M', hdr}) .. ' 2>&1' - local out = io.popen(cmd) + local out = assert(io.popen(cmd)) local deps = out:read("*a") out:close() if deps then return parse_make_deps(deps) - else - return nil end end +--- @param defines string +--- @return string function Gcc:filter_standard_defines(defines) if not self.standard_defines then local pseudoheader_fname = 'tmp_empty_pseudoheader.h' - local pseudoheader_file = io.open(pseudoheader_fname, 'w') + local pseudoheader_file = assert(io.open(pseudoheader_fname, 'w')) pseudoheader_file:close() - local standard_defines = repeated_read_cmd(self.path, - self.preprocessor_extra_flags, - self.get_defines_extra_flags, - {pseudoheader_fname}) + local standard_defines = assert(repeated_read_cmd(self.path, + self.preprocessor_extra_flags, + self.get_defines_extra_flags, + {pseudoheader_fname})) os.remove(pseudoheader_fname) - self.standard_defines = {} + self.standard_defines = {} --- @type table for line in standard_defines:gmatch('[^\n]+') do self.standard_defines[line] = true end end - local ret = {} + + local ret = {} --- @type string[] for line in defines:gmatch('[^\n]+') do if not self.standard_defines[line] then ret[#ret + 1] = line end end + return table.concat(ret, "\n") end --- returns a stream representing a preprocessed form of the passed-in headers. --- Don't forget to close the stream by calling the close() method on it. +--- returns a stream representing a preprocessed form of the passed-in headers. +--- Don't forget to close the stream by calling the close() method on it. +--- @param previous_defines string +--- @param ... string +--- @return string, string function Gcc:preprocess(previous_defines, ...) -- create pseudo-header local pseudoheader = headerize({...}, false) local pseudoheader_fname = 'tmp_pseudoheader.h' - local pseudoheader_file = io.open(pseudoheader_fname, 'w') + local pseudoheader_file = assert(io.open(pseudoheader_fname, 'w')) pseudoheader_file:write(previous_defines) pseudoheader_file:write("\n") pseudoheader_file:write(pseudoheader) pseudoheader_file:flush() pseudoheader_file:close() - local defines = repeated_read_cmd(self.path, self.preprocessor_extra_flags, - self.get_defines_extra_flags, - {pseudoheader_fname}) + local defines = assert(repeated_read_cmd(self.path, self.preprocessor_extra_flags, + self.get_defines_extra_flags, + {pseudoheader_fname})) defines = self:filter_standard_defines(defines) - local declarations = repeated_read_cmd(self.path, - self.preprocessor_extra_flags, - self.get_declarations_extra_flags, - {pseudoheader_fname}) + local declarations = assert(repeated_read_cmd(self.path, + self.preprocessor_extra_flags, + self.get_declarations_extra_flags, + {pseudoheader_fname})) os.remove(pseudoheader_fname) - assert(declarations and defines) return declarations, defines end -local Clang = Gcc:new() -local Msvc = Gcc:new() - -local type_to_class = { - ["gcc"] = Gcc, - ["clang"] = Clang, - ["msvc"] = Msvc -} - -- find the best cc. If os.exec causes problems on windows (like popping up -- a console window) we might consider using something like this: -- http://scite-ru.googlecode.com/svn/trunk/pack/tools/LuaLib/shell.html#exec +--- @param compilers Compiler[] +--- @return Gcc? local function find_best_cc(compilers) for _, meta in pairs(compilers) do - local version = io.popen(tostring(meta.path) .. " -v 2>&1") + local version = assert(io.popen(tostring(meta.path) .. " -v 2>&1")) version:close() if version then - return type_to_class[meta.type]:new({path = meta.path}) + return Gcc:new({path = meta.path}) end end - return nil end -- find the best cc. If os.exec causes problems on windows (like popping up -- a console window) we might consider using something like this: -- http://scite-ru.googlecode.com/svn/trunk/pack/tools/LuaLib/shell.html#exec -local cc = nil -if cc == nil then - cc = find_best_cc(ccs) -end - -return { - includes = function(hdr) - return cc:dependencies(hdr) - end, - preprocess = function(...) - return cc:preprocess(...) - end, - add_to_include_path = function(...) - return cc:add_to_include_path(...) - end -} +local cc = assert(find_best_cc(ccs)) + +local M = {} + +--- @param hdr string +--- @return string[]? +function M.includes(hdr) + return cc:dependencies(hdr) +end + +--- @param ... string +--- @return string, string +function M.preprocess(...) + return cc:preprocess(...) +end + +--- @param ... string +function M.add_to_include_path(...) + return cc:add_to_include_path(...) +end + +return M diff --git a/test/unit/set.lua b/test/unit/set.lua index f3d68c3042..91b7e2dd70 100644 --- a/test/unit/set.lua +++ b/test/unit/set.lua @@ -4,10 +4,15 @@ -- other: -- 1) index => item -- 2) item => index +--- @class Set +--- @field nelem integer +--- @field items string[] +--- @field tbl table local Set = {} +--- @param items? string[] function Set:new(items) - local obj = {} + local obj = {} --- @ type Set setmetatable(obj, self) self.__index = self @@ -26,8 +31,9 @@ function Set:new(items) return obj end +--- @return Set function Set:copy() - local obj = {} + local obj = {} --- @ type Set obj.nelem = self.nelem obj.tbl = {} obj.items = {} @@ -43,6 +49,7 @@ function Set:copy() end -- adds the argument Set to this Set +--- @param other Set function Set:union(other) for e in other:iterator() do self:add(e) @@ -57,6 +64,7 @@ function Set:union_table(t) end -- subtracts the argument Set from this Set +--- @param other Set function Set:diff(other) if other:size() > self:size() then -- this set is smaller than the other set @@ -75,6 +83,7 @@ function Set:diff(other) end end +--- @param it string function Set:add(it) if not self:contains(it) then local idx = #self.tbl + 1 @@ -84,6 +93,7 @@ function Set:add(it) end end +--- @param it string function Set:remove(it) if self:contains(it) then local idx = self.items[it] @@ -93,10 +103,13 @@ function Set:remove(it) end end +--- @param it string +--- @return boolean function Set:contains(it) return self.items[it] or false end +--- @return integer function Set:size() return self.nelem end @@ -113,29 +126,18 @@ function Set:iterator() return pairs(self.items) end +--- @return string[] function Set:to_table() -- there might be gaps in @tbl, so we have to be careful and sort first - local keys - do - local _accum_0 = { } - local _len_0 = 1 - for idx, _ in pairs(self.tbl) do - _accum_0[_len_0] = idx - _len_0 = _len_0 + 1 - end - keys = _accum_0 + local keys = {} --- @type string[] + for idx, _ in pairs(self.tbl) do + keys[#keys+1] = idx end + table.sort(keys) - local copy - do - local _accum_0 = { } - local _len_0 = 1 - for _index_0 = 1, #keys do - local idx = keys[_index_0] - _accum_0[_len_0] = self.tbl[idx] - _len_0 = _len_0 + 1 - end - copy = _accum_0 + local copy = {} --- @type string[] + for _, idx in ipairs(keys) do + copy[#copy+1] = self.tbl[idx] end return copy end -- cgit From f39b33ee491a4a8d4b08425e582dd0dd53617edf Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Apr 2023 11:46:17 +0800 Subject: vim-patch:9.0.0411: only created files can be cleaned up with one call MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem: Only created files can be cleaned up with one call. Solution: Add flags to mkdir() to delete with a deferred function. Expand the writefile() name to a full path to handle changing directory. https://github.com/vim/vim/commit/6f14da15ac900589f2f413d77898b9bff3b31ece vim-patch:8.2.3742: dec mouse test fails without gnome terminfo entry Problem: Dec mouse test fails without gnome terminfo entry. Solution: Check if there is a gnome entry. Also fix 'acd' test on MS-Windows. (Dominique Pellé, closes vim/vim#9282) https://github.com/vim/vim/commit/f589fd3e1047cdf90566b68aaf9a13389e54d26a Cherry-pick test_autochdir.vim changes from patch 9.0.0313. Cherry-pick test_autocmd.vim changes from patch 9.0.0323. Co-authored-by: Bram Moolenaar --- test/unit/os/fs_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index 95a12f5b17..c32098a395 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -748,7 +748,7 @@ describe('fs.c', function() local function os_mkdir_recurse(path, mode) local failed_str = ffi.new('char *[1]', {nil}) - local ret = fs.os_mkdir_recurse(path, mode, failed_str) + local ret = fs.os_mkdir_recurse(path, mode, failed_str, nil) local str = failed_str[0] if str ~= nil then str = ffi.string(str) -- cgit From 8a59d04a31725d9038e8c7df30f9b95ea82f9a76 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sun, 16 Apr 2023 12:28:04 +0800 Subject: test(unit): add test for os_mkdir_recurse "created" --- test/unit/os/fs_spec.lua | 51 ++++++++++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 19 deletions(-) (limited to 'test/unit') diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index c32098a395..3a40e97755 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -17,6 +17,7 @@ local OK = helpers.OK local FAIL = helpers.FAIL local NULL = helpers.NULL local mkdir = helpers.mkdir +local endswith = helpers.endswith local NODE_NORMAL = 0 local NODE_WRITABLE = 1 @@ -748,12 +749,17 @@ describe('fs.c', function() local function os_mkdir_recurse(path, mode) local failed_str = ffi.new('char *[1]', {nil}) - local ret = fs.os_mkdir_recurse(path, mode, failed_str, nil) - local str = failed_str[0] - if str ~= nil then - str = ffi.string(str) + local created_str = ffi.new('char *[1]', {nil}) + local ret = fs.os_mkdir_recurse(path, mode, failed_str, created_str) + local failed_dir = failed_str[0] + if failed_dir ~= nil then + failed_dir = ffi.string(failed_dir) end - return ret, str + local created_dir = created_str[0] + if created_dir ~= nil then + created_dir = ffi.string(created_dir) + end + return ret, failed_dir, created_dir end describe('os_mkdir', function() @@ -774,33 +780,37 @@ describe('fs.c', function() describe('os_mkdir_recurse', function() itp('returns zero when given an already existing directory', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR - local ret, failed_str = os_mkdir_recurse('unit-test-directory', mode) + local ret, failed_dir, created_dir = os_mkdir_recurse('unit-test-directory', mode) eq(0, ret) - eq(nil, failed_str) + eq(nil, failed_dir) + eq(nil, created_dir) end) itp('fails to create a directory where there is a file', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR - local ret, failed_str = os_mkdir_recurse( + local ret, failed_dir, created_dir = os_mkdir_recurse( 'unit-test-directory/test.file', mode) neq(0, ret) - eq('unit-test-directory/test.file', failed_str) + eq('unit-test-directory/test.file', failed_dir) + eq(nil, created_dir) end) itp('fails to create a directory where there is a file in path', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR - local ret, failed_str = os_mkdir_recurse( + local ret, failed_dir, created_dir = os_mkdir_recurse( 'unit-test-directory/test.file/test', mode) neq(0, ret) - eq('unit-test-directory/test.file', failed_str) + eq('unit-test-directory/test.file', failed_dir) + eq(nil, created_dir) end) itp('succeeds to create a directory', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR - local ret, failed_str = os_mkdir_recurse( + local ret, failed_dir, created_dir = os_mkdir_recurse( 'unit-test-directory/new-dir-recurse', mode) eq(0, ret) - eq(nil, failed_str) + eq(nil, failed_dir) + ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse')) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) luv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) @@ -808,10 +818,11 @@ describe('fs.c', function() itp('succeeds to create a directory ending with ///', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR - local ret, failed_str = os_mkdir_recurse( + local ret, failed_dir, created_dir = os_mkdir_recurse( 'unit-test-directory/new-dir-recurse///', mode) eq(0, ret) - eq(nil, failed_str) + eq(nil, failed_dir) + ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse')) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) luv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) @@ -819,10 +830,11 @@ describe('fs.c', function() itp('succeeds to create a directory ending with /', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR - local ret, failed_str = os_mkdir_recurse( + local ret, failed_dir, created_dir = os_mkdir_recurse( 'unit-test-directory/new-dir-recurse/', mode) eq(0, ret) - eq(nil, failed_str) + eq(nil, failed_dir) + ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse')) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) luv.fs_rmdir('unit-test-directory/new-dir-recurse') eq(false, os_isdir('unit-test-directory/new-dir-recurse')) @@ -830,10 +842,11 @@ describe('fs.c', function() itp('succeeds to create a directory tree', function() local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR - local ret, failed_str = os_mkdir_recurse( + local ret, failed_dir, created_dir = os_mkdir_recurse( 'unit-test-directory/new-dir-recurse/1/2/3', mode) eq(0, ret) - eq(nil, failed_str) + eq(nil, failed_dir) + ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse')) eq(true, os_isdir('unit-test-directory/new-dir-recurse')) eq(true, os_isdir('unit-test-directory/new-dir-recurse/1')) eq(true, os_isdir('unit-test-directory/new-dir-recurse/1/2')) -- cgit From 0d2fe7786537ef63d0d3ed1e94546eb3ee35a368 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 23 Apr 2023 19:02:23 +0200 Subject: refactor(time): refactor delay with input checking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, there were three low-level delay entry points - os_delay(ms, ignoreinput=true): sleep for ms, only break on got_int - os_delay(ms, ignoreinput=false): sleep for ms, break on any key input os_microdelay(us, false): equivalent, but in μs (not directly called) - os_microdelay(us, true): sleep for μs, never break. The implementation of the latter two both used uv_cond_timedwait() This could have been for two reasons: 1. allow another thread to "interrupt" the wait 2. uv_cond_timedwait() has higher resolution than uv_sleep() However we (1) never used the first, even when TUI was a thread, and (2) nowhere in the codebase are we using μs resolution, it is always a ms multiplied with 1000. In addition, os_delay(ms, false) would completely block the thread for 100ms intervals and in between check for input. This is not how event handling is done alound here. Therefore: Replace the implementation of os_delay(ms, false) to use LOOP_PROCESS_EVENTS_UNTIL which does a proper epoll wait with a timeout, instead of the 100ms timer panic. Replace os_microdelay(us, false) with a direct wrapper of uv_sleep. --- test/unit/helpers.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 10b7594a88..8fa6378d10 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -97,7 +97,6 @@ local init = only_separate(function() for _, c in ipairs(child_calls_init) do c.func(unpack(c.args)) end - libnvim.time_init() libnvim.fs_init() libnvim.event_init() libnvim.early_init(nil) -- cgit From 5e569a47031d2a5b94cfadd67d5e76ba4651ac4d Mon Sep 17 00:00:00 2001 From: bfredl Date: Tue, 25 Apr 2023 13:39:28 +0200 Subject: refactor(fs): now it is time to get rid of fs_loop and fs_loop_mutex Here's the headline: when run in sync mode (last argument cb=NULL), these functions don't actually use the uv_loop_t. An earlier version of this patch instead replaced fs_loop with using main_loop.uv on the main thread and luv_loop() on luv worker threads. However this made the code more complicated for no reason. Also arbitrarily, half of these functions would attempt to handle UV_ENOMEM by try_to_free_memory(). This would mostly happen on windows because it needs to allocate a converted WCHAR buffer. This should be a quite rare situation. Your system is pretty much hosed already if you cannot allocate like 50 WCHAR:s. Therefore, take the liberty of simply removing this fallback. In addition, we tried to "recover" from ENOMEM in read()/readv() this way which doesn't make any sense. The read buffer(s) are already allocated at this point. This would also be an issue when using these functions on a worker thread, as try_to_free_memory() is not thread-safe. Currently os_file_is_readable() and os_is_dir() is used by worker threads (as part of nvim__get_runtime(), to implement require from 'rtp' in threads). In the end, these changes makes _all_ os/fs.c functions thread-safe, and we thus don't need to document and maintain a thread-safe subset. --- test/unit/helpers.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 8fa6378d10..52769cd9e9 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -97,7 +97,6 @@ local init = only_separate(function() for _, c in ipairs(child_calls_init) do c.func(unpack(c.args)) end - libnvim.fs_init() libnvim.event_init() libnvim.early_init(nil) if child_calls_mod then -- cgit From 75119fcc86e055895af824f7fdbba2f42c1cbbe8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:02:43 +0800 Subject: vim-patch:8.2.3135: Vim9: builtin function arguments not checked at compile time Problem: Vim9: builtin function arguments not checked at compile time. Solution: Add more type checks. (Yegappan Lakshmanan, closes vim/vim#8539) https://github.com/vim/vim/commit/5b73992d8f82be7ac4b6f46c17f53ffb9640e5fa Co-authored-by: Yegappan Lakshmanan --- test/unit/eval/typval_spec.lua | 52 +++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index ecee773ba8..59d150e63f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1468,10 +1468,10 @@ describe('typval.c', function() local l = list(1, empty_list, {}) eq('', tv_list_find_str(l, 0, 'E806: using Float as a String')) - eq('', tv_list_find_str(l, 1, 'E730: using List as a String')) - eq('', tv_list_find_str(l, 2, 'E731: using Dictionary as a String')) - eq('', tv_list_find_str(l, -1, 'E731: using Dictionary as a String')) - eq('', tv_list_find_str(l, -2, 'E730: using List as a String')) + eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) + eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) + eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) + eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) eq('', tv_list_find_str(l, -3, 'E806: using Float as a String')) end) end) @@ -1745,7 +1745,7 @@ describe('typval.c', function() itp('works', function() local d = ffi.gc(dict({test={}}), nil) eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 'test', false) end, - 'E731: using Dictionary as a String'))) + 'E731: Using a Dictionary as a String'))) d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil) alloc_log:clear() local dis = dict_items(d) @@ -1785,7 +1785,7 @@ describe('typval.c', function() return s_ret end local d = ffi.gc(dict({test={}}), nil) - eq('', tv_dict_get_string_alloc(d, 'test', 'E731: using Dictionary as a String')) + eq('', tv_dict_get_string_alloc(d, 'test', 'E731: Using a Dictionary as a String')) d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil) alloc_log:clear() eq(nil, tv_dict_get_string_alloc(d, 'test')) @@ -2832,10 +2832,10 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, {lib.VAR_FLOAT, 'E806: using Float as a String'}, - {lib.VAR_PARTIAL, 'E729: using Funcref as a String'}, - {lib.VAR_FUNC, 'E729: using Funcref as a String'}, - {lib.VAR_LIST, 'E730: using List as a String'}, - {lib.VAR_DICT, 'E731: using Dictionary as a String'}, + {lib.VAR_PARTIAL, 'E729: Using a Funcref as a String'}, + {lib.VAR_FUNC, 'E729: Using a Funcref as a String'}, + {lib.VAR_LIST, 'E730: Using a List as a String'}, + {lib.VAR_DICT, 'E731: Using a Dictionary as a String'}, {lib.VAR_BOOL, nil}, {lib.VAR_SPECIAL, nil}, {lib.VAR_UNKNOWN, 'E908: using an invalid value as a String'}, @@ -2987,10 +2987,10 @@ describe('typval.c', function() {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', ''}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', ''}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', ''}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', ''}, {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, @@ -3031,10 +3031,10 @@ describe('typval.c', function() {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', nil}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', nil}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', nil}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', nil}, {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, @@ -3073,10 +3073,10 @@ describe('typval.c', function() {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', ''}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', ''}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', ''}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', ''}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', ''}, {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, @@ -3116,10 +3116,10 @@ describe('typval.c', function() {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', nil}, - {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_FUNC, {v_string=NULL}, 'E729: using Funcref as a String', nil}, - {lib.VAR_LIST, {v_list=NULL}, 'E730: using List as a String', nil}, - {lib.VAR_DICT, {v_dict=NULL}, 'E731: using Dictionary as a String', nil}, + {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, + {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, + {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, + {lib.VAR_DICT, {v_dict=NULL}, 'E731: Using a Dictionary as a String', nil}, {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, -- cgit From 88cfb49bee3c9102082c7010acb92244e4ad1348 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 07:14:39 +0800 Subject: vim-patch:8.2.4890: inconsistent capitalization in error messages Problem: Inconsistent capitalization in error messages. Solution: Make capitalization consistent. (Doug Kearns) https://github.com/vim/vim/commit/cf030578b26460643dca4a40e7f2e3bc19c749aa Co-authored-by: Bram Moolenaar --- test/unit/eval/typval_spec.lua | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 59d150e63f..7474d5ec99 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1461,18 +1461,18 @@ describe('typval.c', function() itp('fails with error message when index is out of range', function() local l = list(int(1), int(2), int(3), int(4), int(5)) - eq(nil, tv_list_find_str(l, -6, 'E684: list index out of range: -6')) - eq(nil, tv_list_find_str(l, 5, 'E684: list index out of range: 5')) + eq(nil, tv_list_find_str(l, -6, 'E684: List index out of range: -6')) + eq(nil, tv_list_find_str(l, 5, 'E684: List index out of range: 5')) end) itp('fails with error message on invalid types', function() local l = list(1, empty_list, {}) - eq('', tv_list_find_str(l, 0, 'E806: using Float as a String')) + eq('', tv_list_find_str(l, 0, 'E806: Using Float as a String')) eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) - eq('', tv_list_find_str(l, -3, 'E806: using Float as a String')) + eq('', tv_list_find_str(l, -3, 'E806: Using Float as a String')) end) end) end) @@ -1766,7 +1766,7 @@ describe('typval.c', function() eq(s43, dis.te.di_tv.vval.v_string) alloc_log:check({}) eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, - 'E806: using Float as a String'))) + 'E806: Using Float as a String'))) end) itp('allocates a string copy when requested', function() local function tv_dict_get_string_alloc(d, key, emsg) @@ -1792,7 +1792,7 @@ describe('typval.c', function() eq('42', tv_dict_get_string_alloc(d, 'tes')) eq('45', tv_dict_get_string_alloc(d, 'xx')) eq('43', tv_dict_get_string_alloc(d, 'te')) - eq('', tv_dict_get_string_alloc(d, 't', 'E806: using Float as a String')) + eq('', tv_dict_get_string_alloc(d, 't', 'E806: Using Float as a String')) end) end) describe('get_string_buf()', function() @@ -1827,7 +1827,7 @@ describe('typval.c', function() s, r, b = tv_dict_get_string_buf(d, 'test') neq(r, b) eq('tset', s) - s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: using Float as a String') + s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: Using Float as a String') neq(r, b) eq('', s) s, r, b = tv_dict_get_string_buf(d, 'te') @@ -1870,7 +1870,7 @@ describe('typval.c', function() neq(r, b) neq(r, def) eq('tset', s) - s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: using Float as a String') + s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: Using Float as a String') neq(r, b) neq(r, def) eq(nil, s) @@ -2831,14 +2831,14 @@ describe('typval.c', function() alloc_log:clear() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, 'E806: using Float as a String'}, + {lib.VAR_FLOAT, 'E806: Using Float as a String'}, {lib.VAR_PARTIAL, 'E729: Using a Funcref as a String'}, {lib.VAR_FUNC, 'E729: Using a Funcref as a String'}, {lib.VAR_LIST, 'E730: Using a List as a String'}, {lib.VAR_DICT, 'E731: Using a Dictionary as a String'}, {lib.VAR_BOOL, nil}, {lib.VAR_SPECIAL, nil}, - {lib.VAR_UNKNOWN, 'E908: using an invalid value as a String'}, + {lib.VAR_UNKNOWN, 'E908: Using an invalid value as a String'}, }) do local typ = v[1] local emsg = v[2] @@ -2986,7 +2986,7 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', ''}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, @@ -2994,7 +2994,7 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, - {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''}, + {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''}, }) do -- Using to_cstr in place of Neovim allocated string, cannot -- tv_clear() that. @@ -3030,7 +3030,7 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', nil}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, @@ -3038,7 +3038,7 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, - {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil}, + {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil}, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) @@ -3072,7 +3072,7 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', ''}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, @@ -3080,7 +3080,7 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, - {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', ''}, + {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''}, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) @@ -3115,7 +3115,7 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: using Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', nil}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, @@ -3123,7 +3123,7 @@ describe('typval.c', function() {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 'v:null'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, - {lib.VAR_UNKNOWN, nil, 'E908: using an invalid value as a String', nil}, + {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil}, }) do -- Using to_cstr, cannot free with tv_clear local tv = ffi.gc(typvalt(v[1], v[2]), nil) -- cgit From bdaaf2e8e113f8c32c70f83b60e0bf3f648357c1 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 5 May 2023 09:00:35 +0800 Subject: vim-patch:9.0.0250: slightly inconsistent error messages Problem: Slightly inconsistent error messages. Solution: Make it "Using a Float". (closes vim/vim#10959) https://github.com/vim/vim/commit/dde77a7c4d72622284dc5fb72557bde42c314fa6 Co-authored-by: Bram Moolenaar --- test/unit/eval/typval_spec.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 7474d5ec99..cde5a731cf 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1467,12 +1467,12 @@ describe('typval.c', function() itp('fails with error message on invalid types', function() local l = list(1, empty_list, {}) - eq('', tv_list_find_str(l, 0, 'E806: Using Float as a String')) + eq('', tv_list_find_str(l, 0, 'E806: Using a Float as a String')) eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) - eq('', tv_list_find_str(l, -3, 'E806: Using Float as a String')) + eq('', tv_list_find_str(l, -3, 'E806: Using a Float as a String')) end) end) end) @@ -1766,7 +1766,7 @@ describe('typval.c', function() eq(s43, dis.te.di_tv.vval.v_string) alloc_log:check({}) eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, - 'E806: Using Float as a String'))) + 'E806: Using a Float as a String'))) end) itp('allocates a string copy when requested', function() local function tv_dict_get_string_alloc(d, key, emsg) @@ -1792,7 +1792,7 @@ describe('typval.c', function() eq('42', tv_dict_get_string_alloc(d, 'tes')) eq('45', tv_dict_get_string_alloc(d, 'xx')) eq('43', tv_dict_get_string_alloc(d, 'te')) - eq('', tv_dict_get_string_alloc(d, 't', 'E806: Using Float as a String')) + eq('', tv_dict_get_string_alloc(d, 't', 'E806: Using a Float as a String')) end) end) describe('get_string_buf()', function() @@ -1827,7 +1827,7 @@ describe('typval.c', function() s, r, b = tv_dict_get_string_buf(d, 'test') neq(r, b) eq('tset', s) - s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: Using Float as a String') + s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: Using a Float as a String') neq(r, b) eq('', s) s, r, b = tv_dict_get_string_buf(d, 'te') @@ -1870,7 +1870,7 @@ describe('typval.c', function() neq(r, b) neq(r, def) eq('tset', s) - s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: Using Float as a String') + s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: Using a Float as a String') neq(r, b) neq(r, def) eq(nil, s) @@ -2831,7 +2831,7 @@ describe('typval.c', function() alloc_log:clear() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, 'E806: Using Float as a String'}, + {lib.VAR_FLOAT, 'E806: Using a Float as a String'}, {lib.VAR_PARTIAL, 'E729: Using a Funcref as a String'}, {lib.VAR_FUNC, 'E729: Using a Funcref as a String'}, {lib.VAR_LIST, 'E730: Using a List as a String'}, @@ -2986,7 +2986,7 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', ''}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, @@ -3030,7 +3030,7 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', nil}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, @@ -3072,7 +3072,7 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', ''}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, @@ -3115,7 +3115,7 @@ describe('typval.c', function() for _, v in ipairs({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', nil}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, -- cgit From 1ffd20a26eeb360bc0d2fe8e36120d43134b465a Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Fri, 24 Sep 2021 22:42:31 +0100 Subject: test(unit/eval/typval_spec): don't dereference NULL last_msg_hist If last_msg_hist is NULL, check_emsg will cause the running test process to SIGSEGV from trying to access the msg member. --- test/unit/eval/typval_spec.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index cde5a731cf..5e8677c69d 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -101,12 +101,13 @@ local function check_emsg(f, msg) saved_last_msg_hist = nil end local ret = {f()} + local last_msg = lib.last_msg_hist ~= nil and ffi.string(lib.last_msg_hist.msg) or nil if msg ~= nil then - eq(msg, ffi.string(lib.last_msg_hist.msg)) + eq(msg, last_msg) neq(saved_last_msg_hist, lib.last_msg_hist) else if saved_last_msg_hist ~= lib.last_msg_hist then - eq(nil, ffi.string(lib.last_msg_hist.msg)) + eq(nil, last_msg) else eq(saved_last_msg_hist, lib.last_msg_hist) end -- cgit From 41ee7bc7dbcca4ce3d35c13450220d3bffcad15e Mon Sep 17 00:00:00 2001 From: Sean Dewar Date: Sat, 11 Sep 2021 21:25:29 +0100 Subject: test(unit/eval/typval_spec): adjust for Float to String conversion Adjust relevant Lua tests. Refactor testing logic for tv_get_string_* functions into test_string_fn(). Note that vim_snprintf(), which is used for stringifying floats, always calls xfree(tofree), even if tofree is NULL, so we need to expect that in the alloc log. --- test/unit/eval/typval_spec.lua | 228 ++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 138 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 5e8677c69d..a60700287f 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1430,15 +1430,16 @@ describe('typval.c', function() end describe('str()', function() itp('returns correct string', function() - local l = list(int(1), int(2), int(3), int(4), int(5)) + local l = list(int(1), 2.5, int(3), int(4), int(5)) alloc_log:clear() eq('1', tv_list_find_str(l, -5)) + eq('2.5', tv_list_find_str(l, 1)) eq('5', tv_list_find_str(l, 4)) eq('3', tv_list_find_str(l, 2)) eq('3', tv_list_find_str(l, -3)) - alloc_log:check({}) + alloc_log:check({a.freed(alloc_log.null)}) end) itp('returns string when used with VAR_STRING items', function() local l = list('1', '2', '3', '4', '5') @@ -1466,14 +1467,12 @@ describe('typval.c', function() eq(nil, tv_list_find_str(l, 5, 'E684: List index out of range: 5')) end) itp('fails with error message on invalid types', function() - local l = list(1, empty_list, {}) + local l = list(empty_list, {}) - eq('', tv_list_find_str(l, 0, 'E806: Using a Float as a String')) - eq('', tv_list_find_str(l, 1, 'E730: Using a List as a String')) - eq('', tv_list_find_str(l, 2, 'E731: Using a Dictionary as a String')) + eq('', tv_list_find_str(l, 0, 'E730: Using a List as a String')) + eq('', tv_list_find_str(l, 1, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -1, 'E731: Using a Dictionary as a String')) eq('', tv_list_find_str(l, -2, 'E730: Using a List as a String')) - eq('', tv_list_find_str(l, -3, 'E806: Using a Float as a String')) end) end) end) @@ -1766,18 +1765,24 @@ describe('typval.c', function() neq(s42, s43) eq(s43, dis.te.di_tv.vval.v_string) alloc_log:check({}) - eq('', ffi.string(check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, - 'E806: Using a Float as a String'))) + local s44 = check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, + nil) + eq('44.0', ffi.string(s44)) + alloc_log:check({a.freed(alloc_log.null)}) end) itp('allocates a string copy when requested', function() - local function tv_dict_get_string_alloc(d, key, emsg) + local function tv_dict_get_string_alloc(d, key, emsg, is_float) alloc_log:clear() local ret = check_emsg(function() return lib.tv_dict_get_string(d, key, true) end, emsg) local s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then if s_ret then - alloc_log:check({a.str(ret, s_ret)}) + if is_float then + alloc_log:check({a.freed(alloc_log.null), a.str(ret, s_ret)}) + else + alloc_log:check({a.str(ret, s_ret)}) + end else alloc_log:check({}) end @@ -1793,18 +1798,22 @@ describe('typval.c', function() eq('42', tv_dict_get_string_alloc(d, 'tes')) eq('45', tv_dict_get_string_alloc(d, 'xx')) eq('43', tv_dict_get_string_alloc(d, 'te')) - eq('', tv_dict_get_string_alloc(d, 't', 'E806: Using a Float as a String')) + eq('44.0', tv_dict_get_string_alloc(d, 't', nil, true)) end) end) describe('get_string_buf()', function() - local function tv_dict_get_string_buf(d, key, buf, emsg) + local function tv_dict_get_string_buf(d, key, is_float, buf, emsg) buf = buf or ffi.gc(lib.xmalloc(lib.NUMBUFLEN), lib.xfree) alloc_log:clear() local ret = check_emsg(function() return lib.tv_dict_get_string_buf(d, key, buf) end, emsg) local s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then - alloc_log:check({}) + if is_float then + alloc_log:check({a.freed(alloc_log.null)}) + else + alloc_log:check({}) + end end return s_ret, ret, buf end @@ -1828,16 +1837,16 @@ describe('typval.c', function() s, r, b = tv_dict_get_string_buf(d, 'test') neq(r, b) eq('tset', s) - s, r, b = tv_dict_get_string_buf(d, 't', nil, 'E806: Using a Float as a String') - neq(r, b) - eq('', s) + s, r, b = tv_dict_get_string_buf(d, 't', true) + eq(r, b) + eq('1.0', s) s, r, b = tv_dict_get_string_buf(d, 'te') eq(r, b) eq('2', s) end) end) describe('get_string_buf_chk()', function() - local function tv_dict_get_string_buf_chk(d, key, len, buf, def, emsg) + local function tv_dict_get_string_buf_chk(d, key, is_float, len, buf, def, emsg) buf = buf or ffi.gc(lib.xmalloc(lib.NUMBUFLEN), lib.xfree) def = def or ffi.gc(lib.xstrdup('DEFAULT'), lib.xfree) len = len or #key @@ -1846,7 +1855,11 @@ describe('typval.c', function() emsg) local s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then - alloc_log:check({}) + if is_float then + alloc_log:check({a.freed(alloc_log.null)}) + else + alloc_log:check({}) + end end return s_ret, ret, buf, def end @@ -1871,10 +1884,10 @@ describe('typval.c', function() neq(r, b) neq(r, def) eq('tset', s) - s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', 1, nil, nil, 'E806: Using a Float as a String') - neq(r, b) + s, r, b, def = tv_dict_get_string_buf_chk(d, 'test', true, 1) + eq(r, b) neq(r, def) - eq(nil, s) + eq('1.0', s) s, r, b, def = tv_dict_get_string_buf_chk(d, 'te') eq(r, b) neq(r, def) @@ -2832,7 +2845,7 @@ describe('typval.c', function() alloc_log:clear() for _, v in ipairs({ {lib.VAR_NUMBER, nil}, - {lib.VAR_FLOAT, 'E806: Using a Float as a String'}, + {lib.VAR_FLOAT, nil}, {lib.VAR_PARTIAL, 'E729: Using a Funcref as a String'}, {lib.VAR_FUNC, 'E729: Using a Funcref as a String'}, {lib.VAR_LIST, 'E730: Using a List as a String'}, @@ -2979,15 +2992,47 @@ describe('typval.c', function() end end) end) + + local function test_string_fn(input, fn) + for _, v in ipairs(input) do + -- Using to_cstr in place of Neovim allocated string, cannot + -- tv_clear() that. + local tv = ffi.gc(typvalt(v[1], v[2]), nil) + alloc_log:check({}) + local emsg = v[3] + local ret = v[4] + eq(ret, check_emsg(function() + local res, buf = fn(tv) + if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_FLOAT + or tv.v_type == lib.VAR_SPECIAL or tv.v_type == lib.VAR_BOOL then + eq(buf, res) + else + neq(buf, res) + end + if res ~= nil then + return ffi.string(res) + else + return nil + end + end, emsg)) + if emsg then + alloc_log:clear() + elseif tv.v_type == lib.VAR_FLOAT then + alloc_log:check({a.freed(alloc_log.null)}) + else + alloc_log:check({}) + end + end + end describe('string()', function() itp('works', function() local buf = lib.tv_get_string(lua2typvalt(int(1))) local buf_chk = lib.tv_get_string_chk(lua2typvalt(int(1))) neq(buf, buf_chk) - for _, v in ipairs({ + test_string_fn({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, nil, '42.53'}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, @@ -2996,42 +3041,18 @@ describe('typval.c', function() {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''}, - }) do - -- Using to_cstr in place of Neovim allocated string, cannot - -- tv_clear() that. - local tv = ffi.gc(typvalt(v[1], v[2]), nil) - alloc_log:check({}) - local emsg = v[3] - local ret = v[4] - eq(ret, check_emsg(function() - local res = lib.tv_get_string(tv) - if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_SPECIAL - or tv.v_type == lib.VAR_BOOL then - eq(buf, res) - else - neq(buf, res) - end - if res ~= nil then - return ffi.string(res) - else - return nil - end - end, emsg)) - if emsg then - alloc_log:clear() - else - alloc_log:check({}) - end - end + }, function(tv) + return lib.tv_get_string(tv), buf + end) end) end) describe('string_chk()', function() itp('works', function() local buf = lib.tv_get_string_chk(lua2typvalt(int(1))) - for _, v in ipairs({ + test_string_fn({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, nil, '42.53'}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, @@ -3040,40 +3061,17 @@ describe('typval.c', function() {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil}, - }) do - -- Using to_cstr, cannot free with tv_clear - local tv = ffi.gc(typvalt(v[1], v[2]), nil) - alloc_log:check({}) - local emsg = v[3] - local ret = v[4] - eq(ret, check_emsg(function() - local res = lib.tv_get_string_chk(tv) - if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_SPECIAL - or tv.v_type == lib.VAR_BOOL then - eq(buf, res) - else - neq(buf, res) - end - if res ~= nil then - return ffi.string(res) - else - return nil - end - end, emsg)) - if emsg then - alloc_log:clear() - else - alloc_log:check({}) - end - end + }, function(tv) + return lib.tv_get_string_chk(tv), buf + end) end) end) describe('string_buf()', function() itp('works', function() - for _, v in ipairs({ + test_string_fn({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', ''}, + {lib.VAR_FLOAT, {v_float=42.53}, nil, '42.53'}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', ''}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', ''}, @@ -3082,41 +3080,18 @@ describe('typval.c', function() {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''}, - }) do - -- Using to_cstr, cannot free with tv_clear - local tv = ffi.gc(typvalt(v[1], v[2]), nil) - alloc_log:check({}) - local emsg = v[3] - local ret = v[4] - eq(ret, check_emsg(function() - local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) - local res = lib.tv_get_string_buf(tv, buf) - if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_SPECIAL - or tv.v_type == lib.VAR_BOOL then - eq(buf, res) - else - neq(buf, res) - end - if res ~= nil then - return ffi.string(res) - else - return nil - end - end, emsg)) - if emsg then - alloc_log:clear() - else - alloc_log:check({}) - end - end + }, function(tv) + local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) + return lib.tv_get_string_buf(tv, buf), buf + end) end) end) describe('string_buf_chk()', function() itp('works', function() - for _, v in ipairs({ + test_string_fn({ {lib.VAR_NUMBER, {v_number=42}, nil, '42'}, {lib.VAR_STRING, {v_string=to_cstr('100500')}, nil, '100500'}, - {lib.VAR_FLOAT, {v_float=42.53}, 'E806: Using a Float as a String', nil}, + {lib.VAR_FLOAT, {v_float=42.53}, nil, '42.53'}, {lib.VAR_PARTIAL, {v_partial=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_FUNC, {v_string=NULL}, 'E729: Using a Funcref as a String', nil}, {lib.VAR_LIST, {v_list=NULL}, 'E730: Using a List as a String', nil}, @@ -3125,33 +3100,10 @@ describe('typval.c', function() {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 'v:true'}, {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 'v:false'}, {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil}, - }) do - -- Using to_cstr, cannot free with tv_clear - local tv = ffi.gc(typvalt(v[1], v[2]), nil) - alloc_log:check({}) - local emsg = v[3] - local ret = v[4] - eq(ret, check_emsg(function() - local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) - local res = lib.tv_get_string_buf_chk(tv, buf) - if tv.v_type == lib.VAR_NUMBER or tv.v_type == lib.VAR_SPECIAL - or tv.v_type == lib.VAR_BOOL then - eq(buf, res) - else - neq(buf, res) - end - if res ~= nil then - return ffi.string(res) - else - return nil - end - end, emsg)) - if emsg then - alloc_log:clear() - else - alloc_log:check({}) - end - end + }, function(tv) + local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0}) + return lib.tv_get_string_buf_chk(tv, buf), buf + end) end) end) end) -- cgit From 9176b5e10a6b32ff65c8ba3f532e3bd55c168ec6 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Fri, 14 Jul 2023 07:57:13 +0800 Subject: fix(runtime): respect 'fileignorecase' when sourcing (#24344) --- test/unit/path_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'test/unit') diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 5808e2013a..f9ce1ff099 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -15,6 +15,7 @@ local mkdir = helpers.mkdir cimport('string.h') local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h') +local options = cimport('./src/nvim/option_defs.h') local length = 0 local buffer = nil @@ -636,6 +637,15 @@ describe('path.c', function() eq(false, path_with_extension('/some/path/file.vim', 'lua')) eq(false, path_with_extension('/some/path/file', 'lua')) end) + + itp("respects 'fileignorecase' option", function() + options.p_fic = false + eq(false, path_with_extension('/some/path/file.VIM', 'vim')) + eq(false, path_with_extension('/some/path/file.LUA', 'lua')) + options.p_fic = true + eq(true, path_with_extension('/some/path/file.VIM', 'vim')) + eq(true, path_with_extension('/some/path/file.LUA', 'lua')) + end) end) describe('path_with_url', function() -- cgit From c43c745a14dced87a23227d7be4f1c33d4455193 Mon Sep 17 00:00:00 2001 From: Christian Clason Date: Wed, 9 Aug 2023 11:06:13 +0200 Subject: fix(lua): improve annotations for stricter luals diagnostics (#24609) Problem: luals returns stricter diagnostics with bundled luarc.json Solution: Improve some function and type annotations: * use recognized uv.* types * disable diagnostic for global `vim` in shared.lua * docs: don't start comment lines with taglink (otherwise LuaLS will interpret it as a type) * add type alias for lpeg pattern * fix return annotation for `vim.secure.trust` * rename local Range object in vim.version (shadows `Range` in vim.treesitter) * fix some "missing fields" warnings * add missing required fields for test functions in eval.lua * rename lsp meta files for consistency --- test/unit/set.lua | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'test/unit') diff --git a/test/unit/set.lua b/test/unit/set.lua index 91b7e2dd70..7c30be32aa 100644 --- a/test/unit/set.lua +++ b/test/unit/set.lua @@ -12,7 +12,7 @@ local Set = {} --- @param items? string[] function Set:new(items) - local obj = {} --- @ type Set + local obj = {} --- @type Set setmetatable(obj, self) self.__index = self @@ -33,10 +33,7 @@ end --- @return Set function Set:copy() - local obj = {} --- @ type Set - obj.nelem = self.nelem - obj.tbl = {} - obj.items = {} + local obj = {nelem = self.nelem, tbl = {}, items = {}} --- @type Set for k, v in pairs(self.tbl) do obj.tbl[k] = v end -- cgit From 389165cac1596bf602c50904a789722d65ceaac7 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Aug 2023 14:46:05 +0800 Subject: vim-patch:8.2.0066: some corners of vim_snprintf() are not tested (#24718) Problem: Some corners of vim_snprintf() are not tested. Solution: Add a test in C. (Dominique Pelle, closes vim/vim#5422) https://github.com/vim/vim/commit/d2c946bacfedf4e506a4c6771758beddb87df3af --- test/unit/strings_spec.lua | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'test/unit') diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua index b2c839f25c..bb5ea12edc 100644 --- a/test/unit/strings_spec.lua +++ b/test/unit/strings_spec.lua @@ -139,6 +139,42 @@ describe('vim_strchr()', function() end) end) +describe('vim_snprintf()', function() + itp('truncation', function() + local function check(expected, buf, bsize, fmt, ...) + eq(#expected, strings.vim_snprintf(buf, bsize, fmt, ...)) + if bsize > 0 then + local actual = ffi.string(buf, math.min(#expected + 1, bsize)) + eq(expected:sub(1, bsize - 1) .. '\0', actual) + end + end + + for bsize = 0, 14 do + local buf = ffi.gc(strings.xmalloc(bsize), strings.xfree) + check('1234567', buf, bsize, '%d', ffi.cast('int', 1234567)) + check('1234567', buf, bsize, '%ld', ffi.cast('long', 1234567)) + check(' 1234567', buf, bsize, '%9ld', ffi.cast('long', 1234567)) + check('1234567 ', buf, bsize, '%-9ld', ffi.cast('long', 1234567)) + check('deadbeef', buf, bsize, '%x', ffi.cast('unsigned', 0xdeadbeef)) + check('001100', buf, bsize, '%06b', ffi.cast('int', 12)) + check('1.234000', buf, bsize, '%f', ffi.cast('double', 1.234)) + check('1.234000e+00', buf, bsize, '%e', ffi.cast('double', 1.234)) + check('nan', buf, bsize, '%f', ffi.cast('double', 0.0 / 0.0)) + check('inf', buf, bsize, '%f', ffi.cast('double', 1.0 / 0.0)) + check('-inf', buf, bsize, '%f', ffi.cast('double', -1.0 / 0.0)) + check('-0.000000', buf, bsize, '%f', ffi.cast('double', -0.0)) + check('漢語', buf, bsize, '%s', '漢語') + check(' 漢語', buf, bsize, '%8s', '漢語') + check('漢語 ', buf, bsize, '%-8s', '漢語') + check('漢', buf, bsize, '%.3s', '漢語') + check(' foo', buf, bsize, '%5S', 'foo') + check('%%%', buf, bsize, '%%%%%%') + check('0x87654321', buf, bsize, '%p', ffi.cast('char *', 0x87654321)) + check('0x0087654321', buf, bsize, '%012p', ffi.cast('char *', 0x87654321)) + end + end) +end) + describe('strcase_save()' , function() local strcase_save = function(input_string, upper) local res = strings.strcase_save(to_cstr(input_string), upper) -- cgit From 842a47d6a4103a75e33c2c0023dbae5ad2c0f534 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Aug 2023 19:16:19 +0800 Subject: vim-patch:9.0.1704: Cannot use positional arguments for printf() (#24719) Problem: Cannot use positional arguments for printf() Solution: Support positional arguments in string formatting closes: vim/vim#12140 https://github.com/vim/vim/commit/0c6181fec4c362eb9682d5af583341eb20cb1af5 Co-authored-by: Christ van Willegen --- test/unit/eval/typval_spec.lua | 12 ++--- test/unit/strings_spec.lua | 100 ++++++++++++++++++++++++++++++----------- 2 files changed, 79 insertions(+), 33 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index a60700287f..6fb8ba5a1c 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -1439,7 +1439,7 @@ describe('typval.c', function() eq('3', tv_list_find_str(l, 2)) eq('3', tv_list_find_str(l, -3)) - alloc_log:check({a.freed(alloc_log.null)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) end) itp('returns string when used with VAR_STRING items', function() local l = list('1', '2', '3', '4', '5') @@ -1768,7 +1768,7 @@ describe('typval.c', function() local s44 = check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end, nil) eq('44.0', ffi.string(s44)) - alloc_log:check({a.freed(alloc_log.null)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) end) itp('allocates a string copy when requested', function() local function tv_dict_get_string_alloc(d, key, emsg, is_float) @@ -1779,7 +1779,7 @@ describe('typval.c', function() if not emsg then if s_ret then if is_float then - alloc_log:check({a.freed(alloc_log.null), a.str(ret, s_ret)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null), a.str(ret, s_ret)}) else alloc_log:check({a.str(ret, s_ret)}) end @@ -1810,7 +1810,7 @@ describe('typval.c', function() local s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then if is_float then - alloc_log:check({a.freed(alloc_log.null)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) else alloc_log:check({}) end @@ -1856,7 +1856,7 @@ describe('typval.c', function() local s_ret = (ret ~= nil) and ffi.string(ret) or nil if not emsg then if is_float then - alloc_log:check({a.freed(alloc_log.null)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) else alloc_log:check({}) end @@ -3018,7 +3018,7 @@ describe('typval.c', function() if emsg then alloc_log:clear() elseif tv.v_type == lib.VAR_FLOAT then - alloc_log:check({a.freed(alloc_log.null)}) + alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)}) else alloc_log:check({}) end diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua index bb5ea12edc..68790ea026 100644 --- a/test/unit/strings_spec.lua +++ b/test/unit/strings_spec.lua @@ -140,37 +140,83 @@ describe('vim_strchr()', function() end) describe('vim_snprintf()', function() - itp('truncation', function() - local function check(expected, buf, bsize, fmt, ...) - eq(#expected, strings.vim_snprintf(buf, bsize, fmt, ...)) - if bsize > 0 then - local actual = ffi.string(buf, math.min(#expected + 1, bsize)) - eq(expected:sub(1, bsize - 1) .. '\0', actual) - end + local function a(expected, buf, bsize, fmt, ...) + eq(#expected, strings.vim_snprintf(buf, bsize, fmt, ...)) + if bsize > 0 then + local actual = ffi.string(buf, math.min(#expected + 1, bsize)) + eq(expected:sub(1, bsize - 1) .. '\0', actual) end + end + local function i(n) return ffi.cast('int', n) end + local function l(n) return ffi.cast('long', n) end + local function u(n) return ffi.cast('unsigned', n) end + local function ll(n) return ffi.cast('long long', n) end + local function ul(n) return ffi.cast('unsigned long', n) end + local function ull(n) return ffi.cast('unsigned long long', n) end + + itp('truncation', function() for bsize = 0, 14 do local buf = ffi.gc(strings.xmalloc(bsize), strings.xfree) - check('1234567', buf, bsize, '%d', ffi.cast('int', 1234567)) - check('1234567', buf, bsize, '%ld', ffi.cast('long', 1234567)) - check(' 1234567', buf, bsize, '%9ld', ffi.cast('long', 1234567)) - check('1234567 ', buf, bsize, '%-9ld', ffi.cast('long', 1234567)) - check('deadbeef', buf, bsize, '%x', ffi.cast('unsigned', 0xdeadbeef)) - check('001100', buf, bsize, '%06b', ffi.cast('int', 12)) - check('1.234000', buf, bsize, '%f', ffi.cast('double', 1.234)) - check('1.234000e+00', buf, bsize, '%e', ffi.cast('double', 1.234)) - check('nan', buf, bsize, '%f', ffi.cast('double', 0.0 / 0.0)) - check('inf', buf, bsize, '%f', ffi.cast('double', 1.0 / 0.0)) - check('-inf', buf, bsize, '%f', ffi.cast('double', -1.0 / 0.0)) - check('-0.000000', buf, bsize, '%f', ffi.cast('double', -0.0)) - check('漢語', buf, bsize, '%s', '漢語') - check(' 漢語', buf, bsize, '%8s', '漢語') - check('漢語 ', buf, bsize, '%-8s', '漢語') - check('漢', buf, bsize, '%.3s', '漢語') - check(' foo', buf, bsize, '%5S', 'foo') - check('%%%', buf, bsize, '%%%%%%') - check('0x87654321', buf, bsize, '%p', ffi.cast('char *', 0x87654321)) - check('0x0087654321', buf, bsize, '%012p', ffi.cast('char *', 0x87654321)) + a('1.00000001e7', buf, bsize, '%.8g', 10000000.1) + a('1234567', buf, bsize, '%d', i(1234567)) + a('1234567', buf, bsize, '%ld', l(1234567)) + a(' 1234567', buf, bsize, '%9ld', l(1234567)) + a('1234567 ', buf, bsize, '%-9ld', l(1234567)) + a('deadbeef', buf, bsize, '%x', u(0xdeadbeef)) + a('001100', buf, bsize, '%06b', u(12)) + a('one two', buf, bsize, '%s %s', 'one', 'two') + a('1.234000', buf, bsize, '%f', 1.234) + a('1.234000e+00', buf, bsize, '%e', 1.234) + a('nan', buf, bsize, '%f', 0.0 / 0.0) + a('inf', buf, bsize, '%f', 1.0 / 0.0) + a('-inf', buf, bsize, '%f', -1.0 / 0.0) + a('-0.000000', buf, bsize, '%f', -0.0) + a('漢語', buf, bsize, '%s', '漢語') + a(' 漢語', buf, bsize, '%8s', '漢語') + a('漢語 ', buf, bsize, '%-8s', '漢語') + a('漢', buf, bsize, '%.3s', '漢語') + a(' foo', buf, bsize, '%5S', 'foo') + a('%%%', buf, bsize, '%%%%%%') + a('0x87654321', buf, bsize, '%p', ffi.cast('char *', 0x87654321)) + a('0x0087654321', buf, bsize, '%012p', ffi.cast('char *', 0x87654321)) + end + end) + + itp('positional arguments', function() + for bsize = 0, 24 do + local buf = ffi.gc(strings.xmalloc(bsize), strings.xfree) + a('1234567 ', buf, bsize, '%1$*2$ld', l(1234567), i(-9)) + a('1234567 ', buf, bsize, '%1$*2$.*3$ld', l(1234567), i(-9), i(5)) + a('1234567 ', buf, bsize, '%1$*3$.*2$ld', l(1234567), i(5), i(-9)) + a('1234567 ', buf, bsize, '%3$*1$.*2$ld', i(-9), i(5), l(1234567)) + a('1234567', buf, bsize, '%1$ld', l(1234567)) + a(' 1234567', buf, bsize, '%1$*2$ld', l(1234567), i(9)) + a('9 12345 7654321', buf, bsize, '%2$ld %1$d %3$lu', i(12345), l(9), ul(7654321)) + a('9 1234567 7654321', buf, bsize, '%2$d %1$ld %3$lu', l(1234567), i(9), ul(7654321)) + a('9 1234567 7654321', buf, bsize, '%2$d %1$lld %3$lu', ll(1234567), i(9), ul(7654321)) + a('9 12345 7654321', buf, bsize, '%2$ld %1$u %3$lu', u(12345), l(9), ul(7654321)) + a('9 1234567 7654321', buf, bsize, '%2$d %1$lu %3$lu', ul(1234567), i(9), ul(7654321)) + a('9 1234567 7654321', buf, bsize, '%2$d %1$llu %3$lu', ull(1234567), i(9), ul(7654321)) + a('9 1234567 7654321', buf, bsize, '%2$d %1$llu %3$lu', ull(1234567), i(9), ul(7654321)) + a('9 deadbeef 7654321', buf, bsize, '%2$d %1$x %3$lu', u(0xdeadbeef), i(9), ul(7654321)) + a('9 c 7654321', buf, bsize, '%2$ld %1$c %3$lu', i(('c'):byte()), l(9), ul(7654321)) + a('9 hi 7654321', buf, bsize, '%2$ld %1$s %3$lu', 'hi', l(9), ul(7654321)) + a('9 0.000000e+00 7654321', buf, bsize, '%2$ld %1$e %3$lu', 0.0, l(9), ul(7654321)) + a('two one two', buf, bsize, '%2$s %1$s %2$s', 'one', 'two', 'three') + a('three one two', buf, bsize, '%3$s %1$s %2$s', 'one', 'two', 'three') + a('1234567', buf, bsize, '%1$d', i(1234567)) + a('deadbeef', buf, bsize, '%1$x', u(0xdeadbeef)) + a('001100', buf, bsize, '%1$0.*2$b', u(12), i(6)) + a('one two', buf, bsize, '%1$s %2$s', 'one', 'two') + a('001100', buf, bsize, '%06b', u(12)) + a('two one', buf, bsize, '%2$s %1$s', 'one', 'two') + a('1.234000', buf, bsize, '%1$f', 1.234) + a('1.234000e+00', buf, bsize, '%1$e', 1.234) + a('nan', buf, bsize, '%1$f', 0.0 / 0.0) + a('inf', buf, bsize, '%1$f', 1.0 / 0.0) + a('-inf', buf, bsize, '%1$f', -1.0 / 0.0) + a('-0.000000', buf, bsize, '%1$f', -0.0) end end) end) -- cgit From fc14928719df12826397b46b1765b82f1fc7d1d8 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Tue, 15 Aug 2023 20:54:28 +0800 Subject: fix(printf): make positional %zd and %zu work (#24722) --- test/unit/strings_spec.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua index 68790ea026..d6c14e7a40 100644 --- a/test/unit/strings_spec.lua +++ b/test/unit/strings_spec.lua @@ -150,10 +150,12 @@ describe('vim_snprintf()', function() local function i(n) return ffi.cast('int', n) end local function l(n) return ffi.cast('long', n) end - local function u(n) return ffi.cast('unsigned', n) end local function ll(n) return ffi.cast('long long', n) end + local function z(n) return ffi.cast('ptrdiff_t', n) end + local function u(n) return ffi.cast('unsigned', n) end local function ul(n) return ffi.cast('unsigned long', n) end local function ull(n) return ffi.cast('unsigned long long', n) end + local function uz(n) return ffi.cast('size_t', n) end itp('truncation', function() for bsize = 0, 14 do @@ -219,6 +221,15 @@ describe('vim_snprintf()', function() a('-0.000000', buf, bsize, '%1$f', -0.0) end end) + + itp('%zd and %zu', function() + local bsize = 20 + local buf = ffi.gc(strings.xmalloc(bsize), strings.xfree) + a('-1234567 -7654321', buf, bsize, '%zd %zd', z(-1234567), z(-7654321)) + a('-7654321 -1234567', buf, bsize, '%2$zd %1$zd', z(-1234567), z(-7654321)) + a('1234567 7654321', buf, bsize, '%zu %zu', uz(1234567), uz(7654321)) + a('7654321 1234567', buf, bsize, '%2$zu %1$zu', uz(1234567), uz(7654321)) + end) end) describe('strcase_save()' , function() -- cgit From 10c5f35a8ddf2683e0c849f71c02b81556ece902 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Wed, 16 Aug 2023 06:11:05 +0800 Subject: vim-patch:9.0.1715: duplicate test in message_test.c (#24728) Problem: duplicate test in message_test.c Solution: Remove duplicate test and make functions static closes: vim/vim#12803 https://github.com/vim/vim/commit/7772c93a3ec1ce60469e9aea9899687ae1141f34 --- test/unit/strings_spec.lua | 1 - 1 file changed, 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua index d6c14e7a40..04d11d8f04 100644 --- a/test/unit/strings_spec.lua +++ b/test/unit/strings_spec.lua @@ -200,7 +200,6 @@ describe('vim_snprintf()', function() a('9 12345 7654321', buf, bsize, '%2$ld %1$u %3$lu', u(12345), l(9), ul(7654321)) a('9 1234567 7654321', buf, bsize, '%2$d %1$lu %3$lu', ul(1234567), i(9), ul(7654321)) a('9 1234567 7654321', buf, bsize, '%2$d %1$llu %3$lu', ull(1234567), i(9), ul(7654321)) - a('9 1234567 7654321', buf, bsize, '%2$d %1$llu %3$lu', ull(1234567), i(9), ul(7654321)) a('9 deadbeef 7654321', buf, bsize, '%2$d %1$x %3$lu', u(0xdeadbeef), i(9), ul(7654321)) a('9 c 7654321', buf, bsize, '%2$ld %1$c %3$lu', i(('c'):byte()), l(9), ul(7654321)) a('9 hi 7654321', buf, bsize, '%2$ld %1$s %3$lu', 'hi', l(9), ul(7654321)) -- cgit From c431d820e7be1c511d3d16e89cdffaa21b7909fa Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Mon, 4 Sep 2023 08:49:50 +0800 Subject: vim-patch:9.0.1856: issues with formatting positional arguments (#25013) Problem: issues with formatting positional arguments Solution: fix them, add tests and documentation closes: vim/vim#12140 closes: vim/vim#12985 Tentatively fix message_test. Check NULL ptr. https://github.com/vim/vim/commit/aa90d4f031f73a34aaef5746931ea746849a2231 Co-authored-by: Christ van Willegen --- test/unit/strings_spec.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit') diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua index 04d11d8f04..6d7aceb4b2 100644 --- a/test/unit/strings_spec.lua +++ b/test/unit/strings_spec.lua @@ -208,6 +208,7 @@ describe('vim_snprintf()', function() a('three one two', buf, bsize, '%3$s %1$s %2$s', 'one', 'two', 'three') a('1234567', buf, bsize, '%1$d', i(1234567)) a('deadbeef', buf, bsize, '%1$x', u(0xdeadbeef)) + a('001100', buf, bsize, '%2$0*1$b', i(6), u(12)) a('001100', buf, bsize, '%1$0.*2$b', u(12), i(6)) a('one two', buf, bsize, '%1$s %2$s', 'one', 'two') a('001100', buf, bsize, '%06b', u(12)) -- cgit From 5970157e1d22fd5e05ae5d3bd949f807fb7a744c Mon Sep 17 00:00:00 2001 From: bfredl Date: Wed, 17 May 2023 16:08:06 +0200 Subject: refactor(map): enhanced implementation, Clean Code™, etc etc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This involves two redesigns of the map.c implementations: 1. Change of macro style and code organization The old khash.h and map.c implementation used huge #define blocks with a lot of backslash line continuations. This instead uses the "implementation file" .c.h pattern. Such a file is meant to be included multiple times, with different macros set prior to inclusion as parameters. we already use this pattern e.g. for eval/typval_encode.c.h to implement different typval encoders reusing a similar structure. We can structure this code into two parts. one that only depends on key type and is enough to implement sets, and one which depends on both key and value to implement maps (as a wrapper around sets, with an added value[] array) 2. Separate the main hash buckets from the key / value arrays Change the hack buckets to only contain an index into separate key / value arrays This is a common pattern in modern, state of the art hashmap implementations. Even though this leads to one more allocated array, it is this often is a net reduction of memory consumption. Consider key+value consuming at least 12 bytes per pair. On average, we will have twice as many buckets per item. Thus old implementation: 2*12 = 24 bytes per item New implementation 1*12 + 2*4 = 20 bytes per item And the difference gets bigger with larger items. One might think we have pulled a fast one here, as wouldn't the average size of the new key/value arrays be 1.5 slots per items due to amortized grows? But remember, these arrays are fully dense, and thus the accessed memory, measured in _cache lines_, the unit which actually matters, will be the fully used memory but just rounded up to the nearest cache line boundary. This has some other interesting properties, such as an insert-only set/map will be fully ordered by insert only. Preserving this ordering in face of deletions is more tricky tho. As we currently don't use ordered maps, the "delete" operation maintains compactness of the item arrays in the simplest way by breaking the ordering. It would be possible to implement an order-preserving delete although at some cost, like allowing the items array to become non-dense until the next rehash. Finally, in face of these two major changes, all code used in khash.h has been integrated into map.c and friends. Given the heavy edits it makes no sense to "layer" the code into a vendored and a wrapper part. Rather, the layered cake follows the specialization depth: code shared for all maps, code specialized to a key type (and its equivalence relation), and finally code specialized to value+key type. --- test/unit/helpers.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'test/unit') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 52769cd9e9..e9b97266d0 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -139,6 +139,7 @@ local function filter_complex_blocks(body) or string.find(line, "_Float") or string.find(line, "msgpack_zone_push_finalizer") or string.find(line, "msgpack_unpacker_reserve_buffer") + or string.find(line, "value_init_") or string.find(line, "UUID_NULL") -- static const uuid_t UUID_NULL = {...} or string.find(line, "inline _Bool")) then result[#result + 1] = line -- cgit From b04286a187d57c50f01cd36cd4668b7a69026579 Mon Sep 17 00:00:00 2001 From: bfredl Date: Sun, 22 Nov 2020 10:10:37 +0100 Subject: feat(extmark): support proper multiline ranges The removes the previous restriction that nvim_buf_set_extmark() could not be used to highlight arbitrary multi-line regions The problem can be summarized as follows: let's assume an extmark with a hl_group is placed covering the region (5,0) to (50,0) Now, consider what happens if nvim needs to redraw a window covering the lines 20-30. It needs to be able to ask the marktree what extmarks cover this region, even if they don't begin or end here. Therefore the marktree needs to be augmented with the information covers a point, not just what marks begin or end there. To do this, we augment each node with a field "intersect" which is a set the ids of the marks which overlap this node, but only if it is not part of the set of any parent. This ensures the number of nodes that need to be explicitly marked grows only logarithmically with the total number of explicitly nodes (and thus the number of of overlapping marks). Thus we can quickly iterate all marks which overlaps any query position by looking up what leaf node contains that position. Then we only need to consider all "start" marks within that leaf node, and the "intersect" set of that node and all its parents. Now, and the major source of complexity is that the tree restructuring operations (to ensure that each node has T-1 <= size <= 2*T-1) also need to update these sets. If a full inner node is split in two, one of the new parents might start to completely overlap some ranges and its ids will need to be moved from its children's sets to its own set. Similarly, if two undersized nodes gets joined into one, it might no longer completely overlap some ranges, and now the children which do needs to have the have the ids in its set instead. And then there are the pivots! Yes the pivot operations when a child gets moved from one parent to another. --- test/unit/helpers.lua | 11 +++ test/unit/marktree_spec.lua | 233 ++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 237 insertions(+), 7 deletions(-) (limited to 'test/unit') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index e9b97266d0..43b6980702 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -849,6 +849,16 @@ local function ptr2key(ptr) return ffi.string(s) end +local function is_asan() + cimport('./src/nvim/version.h') + local status, res = pcall(function() return lib.version_cflags end) + if status then + return ffi.string(res):match('-fsanitize=[a-z,]*address') + else + return false + end +end + local module = { cimport = cimport, cppimport = cppimport, @@ -876,6 +886,7 @@ local module = { ptr2addr = ptr2addr, ptr2key = ptr2key, debug_log = debug_log, + is_asan = is_asan, } module = global_helpers.tbl_extend('error', module, global_helpers) return function() diff --git a/test/unit/marktree_spec.lua b/test/unit/marktree_spec.lua index 3c96bc5f58..32300c167c 100644 --- a/test/unit/marktree_spec.lua +++ b/test/unit/marktree_spec.lua @@ -87,13 +87,18 @@ local function dosplice(tree, shadow, start, old_extent, new_extent) shadowsplice(shadow, start, old_extent, new_extent) end +local ns = 10 local last_id = nil -local function put(tree, row, col, gravitate) +local function put(tree, row, col, gravitate, end_row, end_col, end_gravitate) last_id = last_id + 1 local my_id = last_id - lib.marktree_put_test(tree, my_id, row, col, gravitate); + end_row = end_row or -1 + end_col = end_col or -1 + end_gravitate = end_gravitate or false + + lib.marktree_put_test(tree, ns, my_id, row, col, gravitate, end_row, end_col, end_gravitate); return my_id end @@ -102,7 +107,7 @@ describe('marktree', function() last_id = 0 end) - itp('works', function() + itp('works', function() local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit local shadow = {} local iter = ffi.new("MarkTreeIter[1]") @@ -129,7 +134,7 @@ describe('marktree', function() eq({}, id2pos) for i,ipos in pairs(shadow) do - local p = lib.marktree_lookup_ns(tree, -1, i, false, iter) + local p = lib.marktree_lookup_ns(tree, ns, i, false, iter) eq(ipos[1], p.pos.row) eq(ipos[2], p.pos.col) local k = lib.marktree_itr_current(iter) @@ -210,10 +215,224 @@ describe('marktree', function() lib.marktree_itr_get(tree, 10, 10, iter) lib.marktree_del_itr(tree, iter, false) - eq(11, iter[0].node.key[iter[0].i].pos.col) + eq(11, iter[0].x.key[iter[0].i].pos.col) lib.marktree_itr_get(tree, 11, 11, iter) lib.marktree_del_itr(tree, iter, false) - eq(12, iter[0].node.key[iter[0].i].pos.col) - end) + eq(12, iter[0].x.key[iter[0].i].pos.col) + end) + + itp("'intersect_mov' function works correctly", function() + local function mov(x, y, w) + local xa = ffi.new("uint64_t[?]", #x) + for i, xi in ipairs(x) do xa[i-1] = xi end + local ya = ffi.new("uint64_t[?]", #y) + for i, yi in ipairs(y) do ya[i-1] = yi end + local wa = ffi.new("uint64_t[?]", #w) + for i, wi in ipairs(w) do wa[i-1] = wi end + + local dummy_size = #x + #y + #w + local wouta = ffi.new("uint64_t[?]", dummy_size) + local douta = ffi.new("uint64_t[?]", dummy_size) + local wsize = ffi.new("size_t[1]") + wsize[0] = dummy_size + local dsize = ffi.new("size_t[1]") + dsize[0] = dummy_size + + local status = lib.intersect_mov_test(xa, #x, ya, #y, wa, #w, wouta, wsize, douta, dsize) + if status == 0 then error'wowza' end + + local wout, dout = {}, {} + for i = 0,tonumber(wsize[0])-1 do table.insert(wout, tonumber(wouta[i])) end + for i = 0,tonumber(dsize[0])-1 do table.insert(dout, tonumber(douta[i])) end + return {wout, dout} + end + + eq({{}, {}}, mov({}, {2, 3}, {2, 3})) + eq({{2, 3}, {}}, mov({}, {}, {2, 3})) + eq({{2, 3}, {}}, mov({2, 3}, {}, {})) + eq({{}, {2,3}}, mov({}, {2,3}, {})) + + eq({{1, 5}, {}}, mov({1,2,5}, {2, 3}, {3})) + eq({{1, 2}, {}}, mov({1,2,5}, {5, 10}, {10})) + eq({{1, 2}, {5}}, mov({1,2}, {5, 10}, {10})) + eq({{1,3,5,7,9}, {2,4,6,8,10}}, mov({1,3,5,7,9}, {2,4,6,8,10}, {})) + eq({{1,3,5,7,9}, {2,6,10}}, mov({1,3,5,7,9}, {2,4,6,8,10}, {4, 8})) + eq({{1,4,7}, {2,5,8}}, mov({1,3,4,6,7,9}, {2,3,5,6,8,9}, {})) + eq({{1,4,7}, {}}, mov({1,3,4,6,7,9}, {2,3,5,6,8,9}, {2,5,8})) + eq({{0,1,4,7,10}, {}}, mov({1,3,4,6,7,9}, {2,3,5,6,8,9}, {0,2,5,8,10})) + end) + + + local function check_intersections(tree) + lib.marktree_check(tree) + -- to debug stuff disable this branch + if true == true then + ok(lib.marktree_check_intersections(tree)) + return + end + + local str1 = lib.mt_inspect(tree, true, true) + local dot1 = ffi.string(str1.data, str1.size) + + local val = lib.marktree_check_intersections(tree) + if not val then + local str2 = lib.mt_inspect(tree, true, true) + local dot2 = ffi.string(str2.data, str2.size) + print("actual:\n\n".."Xafile.dot".."\n\nexpected:\n\n".."Xefile.dot".."\n") + print("nivå", tree[0].root.level); + io.stdout:flush() + local afil = io.open("Xafile.dot", "wb") + afil:write(dot1) + afil:close() + local efil = io.open("Xefile.dot", "wb") + efil:write(dot2) + efil:close() + ok(false) + else + ffi.C.xfree(str1.data) + end + end + + itp('works with intersections', function() + local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit + + local ids = {} + + for i = 1,80 do + table.insert(ids, put(tree, 1, i, false, 2, 100-i, false)) + check_intersections(tree) + end + for i = 1,80 do + lib.marktree_del_pair_test(tree, ns, ids[i]) + check_intersections(tree) + end + ids = {} + + for i = 1,80 do + table.insert(ids, put(tree, 1, i, false, 2, 100-i, false)) + check_intersections(tree) + end + + for i = 1,10 do + for j = 1,8 do + local ival = (j-1)*10+i + lib.marktree_del_pair_test(tree, ns, ids[ival]) + check_intersections(tree) + end + end + end) + + itp('works with intersections with a big tree', function() + local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit + + local ids = {} + + for i = 1,1000 do + table.insert(ids, put(tree, 1, i, false, 2, 1000-i, false)) + if i % 10 == 1 then + check_intersections(tree) + end + end + + check_intersections(tree) + eq(2000, tree[0].n_keys) + ok(tree[0].root.level >= 2) + + local iter = ffi.new("MarkTreeIter[1]") + + local k = 0 + for i = 1,20 do + for j = 1,50 do + k = k + 1 + local ival = (j-1)*20+i + if false == true then -- if there actually is a failure, this branch will fail out at the actual spot of the error + lib.marktree_lookup_ns(tree, ns, ids[ival], false, iter) + lib.marktree_del_itr(tree, iter, false) + check_intersections(tree) + + lib.marktree_lookup_ns(tree, ns, ids[ival], true, iter) + lib.marktree_del_itr(tree, iter, false) + check_intersections(tree) + else + lib.marktree_del_pair_test(tree, ns, ids[ival]) + if k % 5 == 1 then + check_intersections(tree) + end + end + end + end + + eq(0, tree[0].n_keys) + end) + + itp('works with intersections with a even bigger tree', function() + local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit + + local ids = {} + + -- too much overhead on ASAN + local size_factor = helpers.is_asan() and 3 or 10 + + local at_row = {} + for i = 1, 10 do + at_row[i] = {} + end + + local size = 1000*size_factor + local k = 1 + while k <= size do + for row1 = 1,9 do + for row2 = row1,10 do -- note row2 can be == row1, leads to empty ranges being tested when k > size/2 + if k > size then + break + end + local id = put(tree, row1, k, false, row2, size-k, false) + table.insert(ids, id) + for i = row1+1, row2 do + table.insert(at_row[i], id) + end + --if tree[0].root.level == 4 then error("kk"..k) end + if k % 100*size_factor == 1 or (k < 2000 and k%100 == 1) then + check_intersections(tree) + end + k = k + 1 + end + end + end + + eq(2*size, tree[0].n_keys) + ok(tree[0].root.level >= 3) + check_intersections(tree) + + local iter = ffi.new("MarkTreeIter[1]") + local pair = ffi.new("MTPair[1]") + for i = 1,10 do + -- use array as set and not {[id]=true} map, to detect duplicates + local set = {} + eq(true, ffi.C.marktree_itr_get_overlap(tree, i, 0, iter)) + while ffi.C.marktree_itr_step_overlap(tree, iter, pair) do + local id = tonumber(pair[0].start.id) + table.insert(set, id) + end + table.sort(set) + eq(at_row[i], set) + end + + k = 0 + for i = 1,100 do + for j = 1,(10*size_factor) do + k = k + 1 + local ival = (j-1)*100+i + lib.marktree_del_pair_test(tree, ns, ids[ival]) + -- just a few stickprov, if there is trouble we need to check + -- everyone using the code in the "big tree" case above + if k % 100*size_factor == 0 or (k > 3000 and k % 200 == 0) then + check_intersections(tree) + end + end + end + + eq(0, tree[0].n_keys) + end) end) -- cgit From 477458f7bf8dc70ff56d3d4af4ef44f83b95016a Mon Sep 17 00:00:00 2001 From: bfredl Date: Thu, 14 Sep 2023 11:45:19 +0200 Subject: fix(test): more tests for marktree Co-Authored-By: L Lllvvuu --- test/unit/marktree_spec.lua | 106 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) (limited to 'test/unit') diff --git a/test/unit/marktree_spec.lua b/test/unit/marktree_spec.lua index 32300c167c..97b97b47bb 100644 --- a/test/unit/marktree_spec.lua +++ b/test/unit/marktree_spec.lua @@ -366,6 +366,68 @@ describe('marktree', function() eq(0, tree[0].n_keys) end) + itp('works with intersections and marktree_splice', function() + local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit + + for i = 1,1000 do + put(tree, 1, i, false, 2, 1000-i, false) + if i % 10 == 1 then + check_intersections(tree) + end + end + + check_intersections(tree) + eq(2000, tree[0].n_keys) + ok(tree[0].root.level >= 2) + + for _ = 1,10 do + lib.marktree_splice(tree, 0, 0, 0, 100, 0, 0) + check_intersections(tree) + end + end) + + itp('marktree_move should preserve key order', function() + local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit + local iter = ffi.new("MarkTreeIter[1]") + local ids = {} + + -- new index and old index look the same, but still have to move becase + -- pos will get updated + table.insert(ids, put(tree, 1, 1, false, 1, 3, false)) + table.insert(ids, put(tree, 1, 3, false, 1, 3, false)) + table.insert(ids, put(tree, 1, 3, false, 1, 3, false)) + table.insert(ids, put(tree, 1, 3, false, 1, 3, false)) + + lib.marktree_lookup_ns(tree, ns, ids[3], false, iter) + lib.marktree_move(tree, iter, 1, 2) + + check_intersections(tree) + end) + + itp('works with intersections and marktree_move', function() + local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit + + local ids = {} + + for i = 1,1000 do + table.insert(ids, put(tree, 1, i, false, 2, 1000-i, false)) + if i % 10 == 1 then + check_intersections(tree) + end + end + + local iter = ffi.new("MarkTreeIter[1]") + for i = 1,1000 do + local which = i%2 + lib.marktree_lookup_ns(tree, ns, ids[i], which, iter) + lib.marktree_move(tree, iter, 1+which, 500+i) + if i % 10 == 1 then + check_intersections(tree) + end + end + + end) + itp('works with intersections with a even bigger tree', function() local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit @@ -435,4 +497,48 @@ describe('marktree', function() eq(0, tree[0].n_keys) end) + + itp('works with intersections with a even bigger tree and splice', function() + local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit + + -- too much overhead on ASAN + local size_factor = helpers.is_asan() and 3 or 10 + + local at_row = {} + for i = 1, 10 do + at_row[i] = {} + end + + local size = 1000*size_factor + local k = 1 + while k <= size do + for row1 = 1,9 do + for row2 = row1,10 do -- note row2 can be == row1, leads to empty ranges being tested when k > size/2 + if k > size then + break + end + local id = put(tree, row1, k, false, row2, size-k, false) + for i = row1+1, row2 do + table.insert(at_row[i], id) + end + --if tree[0].root.level == 4 then error("kk"..k) end + if k % 100*size_factor == 1 or (k < 2000 and k%100 == 1) then + check_intersections(tree) + end + k = k + 1 + end + end + end + + eq(2*size, tree[0].n_keys) + ok(tree[0].root.level >= 3) + check_intersections(tree) + + for _ = 1,10 do + for j = 3, 8 do + lib.marktree_splice(tree, j, 0, 0, 200, 0, 0) + check_intersections(tree) + end + end + end) end) -- cgit From 9afbfb4d646cd240e97dbaae109f12bfc853112c Mon Sep 17 00:00:00 2001 From: James McCoy Date: Wed, 27 Sep 2023 20:44:50 -0400 Subject: fix(unittests): ignore __s128 and __u128 types in ffi Linux added these types to their userspace headers in [6.5], which causes unit tests to fail like ``` -------- Running tests from test/unit/api/private_helpers_spec.lua RUN vim_to_object converts true: 17.00 ms ERR test/unit/helpers.lua:748: test/unit/helpers.lua:732: (string) ' test/unit/helpers.lua:264: ';' expected near '__s128' at line 194' exit code: 256 stack traceback: test/unit/helpers.lua:748: in function 'itp_parent' test/unit/helpers.lua:784: in function ``` Since we don't use these types, they can be ignored to avoid LuaJIT's C parser choking on them. [6.5]: https://github.com/torvalds/linux/commit/224d80c584d3016cb8d83d1c33914fdd3508aa8c --- test/unit/helpers.lua | 2 ++ 1 file changed, 2 insertions(+) (limited to 'test/unit') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 43b6980702..448209fe0b 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -137,6 +137,8 @@ local function filter_complex_blocks(body) if not (string.find(line, "(^)", 1, true) ~= nil or string.find(line, "_ISwupper", 1, true) or string.find(line, "_Float") + or string.find(line, "__s128") + or string.find(line, "__u128") or string.find(line, "msgpack_zone_push_finalizer") or string.find(line, "msgpack_unpacker_reserve_buffer") or string.find(line, "value_init_") -- cgit From dc6d0d2daf69e2fdadda81feb97906dbc962a239 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 14:41:34 +0800 Subject: refactor: reorganize option header files (#25437) - Move vimoption_T to option.h - option_defs.h is for option-related types - option_vars.h corresponds to Vim's option.h - option_defs.h and option_vars.h don't include each other --- test/unit/optionstr_spec.lua | 4 ++-- test/unit/os/fs_spec.lua | 4 ---- test/unit/os/shell_spec.lua | 2 +- test/unit/path_spec.lua | 2 +- test/unit/undo_spec.lua | 5 +---- 5 files changed, 5 insertions(+), 12 deletions(-) (limited to 'test/unit') diff --git a/test/unit/optionstr_spec.lua b/test/unit/optionstr_spec.lua index f8122f4fe0..2e7198a63a 100644 --- a/test/unit/optionstr_spec.lua +++ b/test/unit/optionstr_spec.lua @@ -4,10 +4,10 @@ local itp = helpers.gen_itp(it) local to_cstr = helpers.to_cstr local eq = helpers.eq -local option = helpers.cimport("./src/nvim/optionstr.h") +local optionstr = helpers.cimport("./src/nvim/optionstr.h") local check_ff_value = function(ff) - return option.check_ff_value(to_cstr(ff)) + return optionstr.check_ff_value(to_cstr(ff)) end describe('check_ff_value', function() diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua index 3a40e97755..8f45d2b0c7 100644 --- a/test/unit/os/fs_spec.lua +++ b/test/unit/os/fs_spec.lua @@ -22,10 +22,6 @@ local endswith = helpers.endswith local NODE_NORMAL = 0 local NODE_WRITABLE = 1 -cimport('./src/nvim/os/shell.h') -cimport('./src/nvim/option_defs.h') -cimport('./src/nvim/main.h') -cimport('./src/nvim/fileio.h') local fs = cimport('./src/nvim/os/os.h', './src/nvim/path.h') cppimport('sys/stat.h') cppimport('fcntl.h') diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua index 29a2b78491..3fb1afed44 100644 --- a/test/unit/os/shell_spec.lua +++ b/test/unit/os/shell_spec.lua @@ -2,7 +2,7 @@ local helpers = require('test.unit.helpers')(after_each) local itp = helpers.gen_itp(it) local cimported = helpers.cimport( './src/nvim/os/shell.h', - './src/nvim/option_defs.h', + './src/nvim/option_vars.h', './src/nvim/main.h', './src/nvim/memory.h' ) diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index f9ce1ff099..23f71cfe78 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -15,7 +15,7 @@ local mkdir = helpers.mkdir cimport('string.h') local cimp = cimport('./src/nvim/os/os.h', './src/nvim/path.h') -local options = cimport('./src/nvim/option_defs.h') +local options = cimport('./src/nvim/option_vars.h') local length = 0 local buffer = nil diff --git a/test/unit/undo_spec.lua b/test/unit/undo_spec.lua index 9261eca19d..ee4203b94c 100644 --- a/test/unit/undo_spec.lua +++ b/test/unit/undo_spec.lua @@ -11,10 +11,7 @@ local neq = helpers.neq local eq = helpers.eq local mkdir = helpers.mkdir -cimport('./src/nvim/ex_cmds_defs.h') -cimport('./src/nvim/buffer_defs.h') -local options = cimport('./src/nvim/option_defs.h') --- TODO: remove: local vim = cimport('./src/nvim/vim.h') +local options = cimport('./src/nvim/option_vars.h') local undo = cimport('./src/nvim/undo.h') local buffer = cimport('./src/nvim/buffer.h') -- cgit From a4132e1d62c5ef542a05b5ca2c6704f6d992c818 Mon Sep 17 00:00:00 2001 From: zeertzjq Date: Sat, 30 Sep 2023 20:38:04 +0800 Subject: test(unit): move statusline tests to statusline_spec.lua (#25441) --- test/unit/buffer_spec.lua | 276 ----------------------------------------- test/unit/keycodes_spec.lua | 22 ++-- test/unit/statusline_spec.lua | 282 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 293 insertions(+), 287 deletions(-) create mode 100644 test/unit/statusline_spec.lua (limited to 'test/unit') diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua index a54ea8c656..6e08a09295 100644 --- a/test/unit/buffer_spec.lua +++ b/test/unit/buffer_spec.lua @@ -1,15 +1,11 @@ - local helpers = require("test.unit.helpers")(after_each) local itp = helpers.gen_itp(it) local to_cstr = helpers.to_cstr -local get_str = helpers.ffi.string local eq = helpers.eq local NULL = helpers.NULL -local globals = helpers.cimport("./src/nvim/globals.h") local buffer = helpers.cimport("./src/nvim/buffer.h") -local stl = helpers.cimport("./src/nvim/statusline.h") describe('buffer functions', function() @@ -210,276 +206,4 @@ describe('buffer functions', function() close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0, 0) end) end) - - describe('build_stl_str_hl', function() - local buffer_byte_size = 100 - local STL_INITIAL_ITEMS = 20 - local output_buffer = '' - - -- This function builds the statusline - -- - -- @param arg Optional arguments are: - -- .pat The statusline format string - -- .fillchar The fill character used in the statusline - -- .maximum_cell_count The number of cells available in the statusline - local function build_stl_str_hl(arg) - output_buffer = to_cstr(string.rep(" ", buffer_byte_size)) - - local pat = arg.pat or '' - local fillchar = arg.fillchar or (' '):byte() - local maximum_cell_count = arg.maximum_cell_count or buffer_byte_size - - return stl.build_stl_str_hl(globals.curwin, - output_buffer, - buffer_byte_size, - to_cstr(pat), - NULL, - 0, - fillchar, - maximum_cell_count, - NULL, - NULL, - NULL) - end - - -- Use this function to simplify testing the comparison between - -- the format string and the resulting statusline. - -- - -- @param description The description of what the test should be doing - -- @param statusline_cell_count The number of cells available in the statusline - -- @param input_stl The format string for the statusline - -- @param expected_stl The expected result string for the statusline - -- - -- @param arg Options can be placed in an optional dictionary as the last parameter - -- .expected_cell_count The expected number of cells build_stl_str_hl will return - -- .expected_byte_length The expected byte length of the string (defaults to byte length of expected_stl) - -- .file_name The name of the file to be tested (useful in %f type tests) - -- .fillchar The character that will be used to fill any 'extra' space in the stl - local function statusline_test (description, - statusline_cell_count, - input_stl, - expected_stl, - arg) - - -- arg is the optional parameter - -- so we either fill in option with arg or an empty dictionary - local option = arg or {} - - local fillchar = option.fillchar or (' '):byte() - local expected_cell_count = option.expected_cell_count or statusline_cell_count - local expected_byte_length = option.expected_byte_length or #expected_stl - - itp(description, function() - if option.file_name then - buffer.setfname(globals.curbuf, to_cstr(option.file_name), NULL, 1) - else - buffer.setfname(globals.curbuf, nil, NULL, 1) - end - - local result_cell_count = build_stl_str_hl{pat=input_stl, - maximum_cell_count=statusline_cell_count, - fillchar=fillchar} - - eq(expected_stl, get_str(output_buffer, expected_byte_length)) - eq(expected_cell_count, result_cell_count) - end) - end - - -- expression testing - statusline_test('Should expand expression', 2, - '%!expand(20+1)', '21') - statusline_test('Should expand broken expression to itself', 11, - '%!expand(20+1', 'expand(20+1') - - -- file name testing - statusline_test('should print no file name', 10, - '%f', '[No Name]', - {expected_cell_count=9}) - statusline_test('should print the relative file name', 30, - '%f', 'test/unit/buffer_spec.lua', - {file_name='test/unit/buffer_spec.lua', expected_cell_count=25}) - statusline_test('should print the full file name', 40, - '%F', '/test/unit/buffer_spec.lua', - {file_name='/test/unit/buffer_spec.lua', expected_cell_count=26}) - - -- fillchar testing - statusline_test('should handle `!` as a fillchar', 10, - 'abcde%=', 'abcde!!!!!', - {fillchar=('!'):byte()}) - statusline_test('should handle `~` as a fillchar', 10, - '%=abcde', '~~~~~abcde', - {fillchar=('~'):byte()}) - statusline_test('should put fillchar `!` in between text', 10, - 'abc%=def', 'abc!!!!def', - {fillchar=('!'):byte()}) - statusline_test('should put fillchar `~` in between text', 10, - 'abc%=def', 'abc~~~~def', - {fillchar=('~'):byte()}) - statusline_test('should put fillchar `━` in between text', 10, - 'abc%=def', 'abc━━━━def', - {fillchar=0x2501}) - statusline_test('should handle zero-fillchar as a space', 10, - 'abcde%=', 'abcde ', - {fillchar=0}) - statusline_test('should print the tail file name', 80, - '%t', 'buffer_spec.lua', - {file_name='test/unit/buffer_spec.lua', expected_cell_count=15}) - - -- standard text testing - statusline_test('should copy plain text', 80, - 'this is a test', 'this is a test', - {expected_cell_count=14}) - - -- line number testing - statusline_test('should print the buffer number', 80, - '%n', '1', - {expected_cell_count=1}) - statusline_test('should print the current line number in the buffer', 80, - '%l', '0', - {expected_cell_count=1}) - statusline_test('should print the number of lines in the buffer', 80, - '%L', '1', - {expected_cell_count=1}) - - -- truncation testing - statusline_test('should truncate when standard text pattern is too long', 10, - '0123456789abcde', '<6789abcde') - statusline_test('should truncate when using =', 10, - 'abcdef%=ghijkl', 'abcdef') - statusline_test('should truncate at `<` with one `=`, test 3', 10, - 'abc%') + statusline_test('should truncate at `<` with one `=`, test 3', 10, + 'abc% Date: Fri, 15 Sep 2023 09:43:48 +0200 Subject: docs: small fixes Co-authored-by: Wansmer Co-authored-by: Andrew Voynov Co-authored-by: David Moberg --- test/unit/marktree_spec.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit') diff --git a/test/unit/marktree_spec.lua b/test/unit/marktree_spec.lua index 97b97b47bb..3f9dd4df12 100644 --- a/test/unit/marktree_spec.lua +++ b/test/unit/marktree_spec.lua @@ -391,7 +391,7 @@ describe('marktree', function() local iter = ffi.new("MarkTreeIter[1]") local ids = {} - -- new index and old index look the same, but still have to move becase + -- new index and old index look the same, but still have to move because -- pos will get updated table.insert(ids, put(tree, 1, 1, false, 1, 3, false)) table.insert(ids, put(tree, 1, 3, false, 1, 3, false)) -- cgit From 468292dcb743c79714b030557cf2754b7b5bf07d Mon Sep 17 00:00:00 2001 From: LW Date: Fri, 3 Nov 2023 15:56:45 -0700 Subject: fix(rpc): "grid_line" event parsing crashes (#25581) refactor: use a more idiomatic loop to iterate over the cells There are two cases in which the following assertion would fail: ```c assert(g->icell < g->ncells); ``` 1. If `g->ncells = 0`. Update this to be legal. 2. If an EOF is reached while parsing `wrap`. In this case, the unpacker attempts to resume from `cells`, which is a bug. Create a new state for parsing `wrap`. Reference: https://neovim.io/doc/user/ui.html#ui-event-grid_line --- test/unit/helpers.lua | 3 ++ test/unit/msgpack_spec.lua | 75 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 test/unit/msgpack_spec.lua (limited to 'test/unit') diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 448209fe0b..8d581dac49 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -861,6 +861,7 @@ local function is_asan() end end +--- @class test.unit.helpers.module local module = { cimport = cimport, cppimport = cppimport, @@ -890,7 +891,9 @@ local module = { debug_log = debug_log, is_asan = is_asan, } +--- @class test.unit.helpers: test.unit.helpers.module, test.helpers module = global_helpers.tbl_extend('error', module, global_helpers) + return function() return module end diff --git a/test/unit/msgpack_spec.lua b/test/unit/msgpack_spec.lua new file mode 100644 index 0000000000..c573714714 --- /dev/null +++ b/test/unit/msgpack_spec.lua @@ -0,0 +1,75 @@ +local helpers = require('test.unit.helpers')(after_each) +local cimport = helpers.cimport +local itp = helpers.gen_itp(it) +local lib = cimport('./src/nvim/msgpack_rpc/unpacker.h', './src/nvim/memory.h') +local ffi = helpers.ffi +local eq = helpers.eq +local to_cstr = helpers.to_cstr + +--- @class Unpacker +--- @field read_ptr ffi.cdata* +--- @field read_size number + +--- @alias Unpacker* table +--- @return Unpacker* unpacker `unpacker[0]` to dereference +local function make_unpacker() + return ffi.gc(ffi.cast('Unpacker*', lib.xcalloc(1, ffi.sizeof('Unpacker'))), function(unpacker) + lib.unpacker_teardown(unpacker, nil, nil) + lib.xfree(unpacker) + end) +end + +--- @param unpacker Unpacker* +--- @param data string +--- @param size number? *default: data:len()* +local function unpacker_goto(unpacker, data, size) + unpacker[0].read_ptr = to_cstr(data) + unpacker[0].read_size = size or data:len() +end + +--- @param unpacker Unpacker* +--- @return boolean +local function unpacker_advance(unpacker) + return lib.unpacker_advance(unpacker) +end + +describe('msgpack', function() + describe('unpacker', function() + itp('does not crash when paused between `cells` and `wrap` params of `grid_line` #25184', function() + -- [kMessageTypeNotification, "redraw", [ + -- ["grid_line", + -- [2, 0, 0, [[" " , 0, 77]], false] + -- ] + -- ]] + local payload = + '\x93\x02\xa6\x72\x65\x64\x72\x61\x77\x91\x92\xa9\x67\x72\x69\x64\x5f\x6c\x69\x6e\x65\x95\x02\x00\x00\x91\x93\xa1\x20\x00\x4d\xc2' + + local unpacker = make_unpacker() + lib.unpacker_init(unpacker) + + unpacker_goto(unpacker, payload, payload:len() - 1) + local finished = unpacker_advance(unpacker) + eq(finished, false) + + unpacker[0].read_size = unpacker[0].read_size + 1 + finished = unpacker_advance(unpacker) + eq(finished, true) + end) + + itp('does not crash when parsing grid_line event with 0 `cells` #25184', function() + local unpacker = make_unpacker() + lib.unpacker_init(unpacker) + + unpacker_goto(unpacker, + -- [kMessageTypeNotification, "redraw", [ + -- ["grid_line", + -- [2, 0, 0, [], false] + -- ] + -- ]] + '\x93\x02\xa6\x72\x65\x64\x72\x61\x77\x91\x92\xa9\x67\x72\x69\x64\x5f\x6c\x69\x6e\x65\x95\x02\x00\x00\x90\xc2' + ) + local finished = unpacker_advance(unpacker) + eq(finished, true) + end) + end) +end) -- cgit From 353a4be7e84fdc101318215bdcc8a7e780d737fe Mon Sep 17 00:00:00 2001 From: dundargoc Date: Sun, 12 Nov 2023 13:13:58 +0100 Subject: build: remove PVS We already have an extensive suite of static analysis tools we use, which causes a fair bit of redundancy as we get duplicate warnings. PVS is also prone to give false warnings which creates a lot of work to identify and disable. --- test/unit/fixtures/multiqueue.c | 3 --- test/unit/fixtures/rbuffer.c | 5 +---- 2 files changed, 1 insertion(+), 7 deletions(-) (limited to 'test/unit') diff --git a/test/unit/fixtures/multiqueue.c b/test/unit/fixtures/multiqueue.c index 4f4f5989d9..3a5ddab4b8 100644 --- a/test/unit/fixtures/multiqueue.c +++ b/test/unit/fixtures/multiqueue.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include #include #include "nvim/event/multiqueue.h" diff --git a/test/unit/fixtures/rbuffer.c b/test/unit/fixtures/rbuffer.c index efa7ab1986..d587d6b054 100644 --- a/test/unit/fixtures/rbuffer.c +++ b/test/unit/fixtures/rbuffer.c @@ -1,6 +1,3 @@ -// This is an open source non-commercial project. Dear PVS-Studio, please check -// it. PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com - #include "nvim/rbuffer.h" #include "rbuffer.h" @@ -15,7 +12,7 @@ void ut_rbuffer_each_read_chunk(RBuffer *buf, each_ptr_cb cb) void ut_rbuffer_each_write_chunk(RBuffer *buf, each_ptr_cb cb) { - RBUFFER_UNTIL_FULL(buf, wptr, wcnt) { // -V1044 + RBUFFER_UNTIL_FULL(buf, wptr, wcnt) { cb(wptr, wcnt); rbuffer_produced(buf, wcnt); } -- cgit From ab102f188e86bdbfce1d4de2ef633092a906e8fe Mon Sep 17 00:00:00 2001 From: Gregory Anders Date: Mon, 6 Nov 2023 15:46:44 -0600 Subject: refactor: move background color detection into Lua --- test/unit/tui_spec.lua | 162 ------------------------------------------------- 1 file changed, 162 deletions(-) delete mode 100644 test/unit/tui_spec.lua (limited to 'test/unit') diff --git a/test/unit/tui_spec.lua b/test/unit/tui_spec.lua deleted file mode 100644 index 192e35a485..0000000000 --- a/test/unit/tui_spec.lua +++ /dev/null @@ -1,162 +0,0 @@ -local helpers = require("test.unit.helpers")(after_each) -local cimport = helpers.cimport -local eq = helpers.eq -local ffi = helpers.ffi -local itp = helpers.gen_itp(it) -local to_cstr = helpers.to_cstr - -local cinput = cimport("./src/nvim/tui/input.h") -local rbuffer = cimport("./test/unit/fixtures/rbuffer.h") -local globals = cimport("./src/nvim/globals.h") -local multiqueue = cimport("./test/unit/fixtures/multiqueue.h") -local ui_client = cimport("./src/nvim/ui_client.h") - -itp('handle_background_color', function() - local handle_background_color = cinput.handle_background_color - local term_input = ffi.new('TermInput', {}) - local events = globals.main_loop.thread_events - local kIncomplete = cinput.kIncomplete - local kNotApplicable = cinput.kNotApplicable - local kComplete = cinput.kComplete - - -- Short-circuit when not waiting for response. - term_input.waiting_for_bg_response = 0 - eq(kNotApplicable, handle_background_color(term_input)) - - local capacity = 100 - local rbuf = ffi.gc(rbuffer.rbuffer_new(capacity), rbuffer.rbuffer_free) - term_input.read_stream.buffer = rbuf - - local function assert_bg(colorspace, color, bg) - local term_response = '\027]11;'..colorspace..':'..color..'\007' - rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response) - - term_input.waiting_for_bg_response = 1 - eq(kComplete, handle_background_color(term_input)) - eq(0, term_input.waiting_for_bg_response) - eq(0, multiqueue.multiqueue_size(events)) - eq(bg, ({[0]="light", [1] = "dark", [-1] = "none"}) - [tonumber(ui_client.ui_client_bg_response)]) - - -- Buffer has been consumed. - eq(0, rbuf.size) - end - - assert_bg('rgb', '0000/0000/0000', 'dark') - assert_bg('rgb', 'ffff/ffff/ffff', 'light') - assert_bg('rgb', '000/000/000', 'dark') - assert_bg('rgb', 'fff/fff/fff', 'light') - assert_bg('rgb', '00/00/00', 'dark') - assert_bg('rgb', 'ff/ff/ff', 'light') - assert_bg('rgb', '0/0/0', 'dark') - assert_bg('rgb', 'f/f/f', 'light') - - assert_bg('rgb', 'f/0/0', 'dark') - assert_bg('rgb', '0/f/0', 'light') - assert_bg('rgb', '0/0/f', 'dark') - - assert_bg('rgb', '1/1/1', 'dark') - assert_bg('rgb', '2/2/2', 'dark') - assert_bg('rgb', '3/3/3', 'dark') - assert_bg('rgb', '4/4/4', 'dark') - assert_bg('rgb', '5/5/5', 'dark') - assert_bg('rgb', '6/6/6', 'dark') - assert_bg('rgb', '7/7/7', 'dark') - assert_bg('rgb', '8/8/8', 'light') - assert_bg('rgb', '9/9/9', 'light') - assert_bg('rgb', 'a/a/a', 'light') - assert_bg('rgb', 'b/b/b', 'light') - assert_bg('rgb', 'c/c/c', 'light') - assert_bg('rgb', 'd/d/d', 'light') - assert_bg('rgb', 'e/e/e', 'light') - - assert_bg('rgb', '0/e/0', 'light') - assert_bg('rgb', '0/d/0', 'light') - assert_bg('rgb', '0/c/0', 'dark') - assert_bg('rgb', '0/b/0', 'dark') - - assert_bg('rgb', 'f/0/f', 'dark') - assert_bg('rgb', 'f/1/f', 'dark') - assert_bg('rgb', 'f/2/f', 'dark') - assert_bg('rgb', 'f/3/f', 'light') - assert_bg('rgb', 'f/4/f', 'light') - - assert_bg('rgba', '0000/0000/0000/0000', 'dark') - assert_bg('rgba', '0000/0000/0000/ffff', 'dark') - assert_bg('rgba', 'ffff/ffff/ffff/0000', 'light') - assert_bg('rgba', 'ffff/ffff/ffff/ffff', 'light') - assert_bg('rgba', '000/000/000/000', 'dark') - assert_bg('rgba', '000/000/000/fff', 'dark') - assert_bg('rgba', 'fff/fff/fff/000', 'light') - assert_bg('rgba', 'fff/fff/fff/fff', 'light') - assert_bg('rgba', '00/00/00/00', 'dark') - assert_bg('rgba', '00/00/00/ff', 'dark') - assert_bg('rgba', 'ff/ff/ff/00', 'light') - assert_bg('rgba', 'ff/ff/ff/ff', 'light') - assert_bg('rgba', '0/0/0/0', 'dark') - assert_bg('rgba', '0/0/0/f', 'dark') - assert_bg('rgba', 'f/f/f/0', 'light') - assert_bg('rgba', 'f/f/f/f', 'light') - - - -- Incomplete sequence: necessarily correct behavior. - local term_response = '\027]11;rgba:f/f/f/f' -- missing '\007 - rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response) - - term_input.waiting_for_bg_response = 1 - eq(kIncomplete, handle_background_color(term_input)) - eq(1, term_input.waiting_for_bg_response) - eq(#term_response, rbuf.size) - - term_response = '\007' - rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response) - eq(kComplete, handle_background_color(term_input)) - eq(0, term_input.waiting_for_bg_response) - - eq(0, tonumber(ui_client.ui_client_bg_response)) - eq(0, multiqueue.multiqueue_size(events)) - eq(0, rbuf.size) - - term_response = '\027]11;rg' - rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response) - - term_input.waiting_for_bg_response = 1 - eq(kIncomplete, handle_background_color(term_input)) - eq(1, term_input.waiting_for_bg_response) - eq(#term_response, rbuf.size) - - term_response = 'ba:f/f/f/f\007' - rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response) - eq(kComplete, handle_background_color(term_input)) - eq(0, term_input.waiting_for_bg_response) - - eq(0, tonumber(ui_client.ui_client_bg_response)) - eq(0, multiqueue.multiqueue_size(events)) - eq(0, rbuf.size) - - - -- Does nothing when not at start of buffer. - term_response = '123\027]11;rgba:f/f/f/f\007456' - rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response) - - term_input.waiting_for_bg_response = 3 - eq(kNotApplicable, handle_background_color(term_input)) - eq(2, term_input.waiting_for_bg_response) - - eq(0, multiqueue.multiqueue_size(events)) - eq(#term_response, rbuf.size) - rbuffer.rbuffer_consumed(rbuf, #term_response) - - - -- Keeps trailing buffer. - term_response = '\027]11;rgba:f/f/f/f\007456' - rbuffer.rbuffer_write(rbuf, to_cstr(term_response), #term_response) - - term_input.waiting_for_bg_response = 1 - eq(kComplete, handle_background_color(term_input)) - eq(0, term_input.waiting_for_bg_response) - - eq(0, multiqueue.multiqueue_size(events)) - eq(3, rbuf.size) - rbuffer.rbuffer_consumed(rbuf, rbuf.size) -end) -- cgit From b522cb1ac3fbdf6e68eed5d0b6e1cbeaf3ac2254 Mon Sep 17 00:00:00 2001 From: bfredl Date: Mon, 6 Nov 2023 14:52:27 +0100 Subject: refactor(grid): make screen rendering more multibyte than ever before Problem: buffer text with composing chars are converted from UTF-8 to an array of up to seven UTF-32 values and then converted back to UTF-8 strings. Solution: Convert buffer text directly to UTF-8 based schar_T values. The limit of the text size is now in schar_T bytes, which is currently 31+1 but easily could be raised as it no longer multiplies the size of the entire screen grid when not used, the full size is only required for temporary scratch buffers. Also does some general cleanup to win_line text handling, which was unnecessarily complicated due to multibyte rendering being an "opt-in" feature long ago. Nowadays, a char is just a char, regardless if it consists of one ASCII byte or multiple bytes. --- test/unit/mbyte_spec.lua | 243 +++++++++++++---------------------------------- 1 file changed, 64 insertions(+), 179 deletions(-) (limited to 'test/unit') diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua index fdb1bceab0..cd94624570 100644 --- a/test/unit/mbyte_spec.lua +++ b/test/unit/mbyte_spec.lua @@ -4,17 +4,9 @@ local itp = helpers.gen_itp(it) local ffi = helpers.ffi local eq = helpers.eq -local mbyte = helpers.cimport("./src/nvim/mbyte.h") -local charset = helpers.cimport('./src/nvim/charset.h') +local lib = helpers.cimport('./src/nvim/mbyte.h', './src/nvim/charset.h', './src/nvim/grid.h') describe('mbyte', function() - -- Array for composing characters - local intp = ffi.typeof('int[?]') - local function to_intp() - -- how to get MAX_MCO from globals.h? - return intp(7, 1) - end - -- Convert from bytes to string local function to_string(bytes) local s = {} @@ -30,14 +22,14 @@ describe('mbyte', function() itp('utf_ptr2char', function() -- For strings with length 1 the first byte is returned. for c = 0, 255 do - eq(c, mbyte.utf_ptr2char(to_string({c, 0}))) + eq(c, lib.utf_ptr2char(to_string({c, 0}))) end -- Some ill formed byte sequences that should not be recognized as UTF-8 -- First byte: 0xc0 or 0xc1 -- Second byte: 0x80 .. 0xbf - --eq(0x00c0, mbyte.utf_ptr2char(to_string({0xc0, 0x80}))) - --eq(0x00c1, mbyte.utf_ptr2char(to_string({0xc1, 0xbf}))) + --eq(0x00c0, lib.utf_ptr2char(to_string({0xc0, 0x80}))) + --eq(0x00c1, lib.utf_ptr2char(to_string({0xc1, 0xbf}))) -- -- Sequences with more than four bytes end) @@ -47,240 +39,133 @@ describe('mbyte', function() local char_p = ffi.typeof('char[?]') for c = n * 0x1000, n * 0x1000 + 0xFFF do local p = char_p(4, 0) - mbyte.utf_char2bytes(c, p) - eq(c, mbyte.utf_ptr2char(p)) - eq(charset.vim_iswordc(c), charset.vim_iswordp(p)) + lib.utf_char2bytes(c, p) + eq(c, lib.utf_ptr2char(p)) + eq(lib.vim_iswordc(c), lib.vim_iswordp(p)) end end) end - describe('utfc_ptr2char_len', function() + describe('utfc_ptr2schar_len', function() + local function test_seq(seq) + local firstc = ffi.new("int[1]") + local buf = ffi.new("char[32]") + lib.schar_get(buf, lib.utfc_ptr2schar_len(to_string(seq), #seq, firstc)) + return {ffi.string(buf), firstc[0]} + end + + local function byte(val) + return {string.char(val), val} + end itp('1-byte sequences', function() - local pcc = to_intp() - for c = 0, 255 do - eq(c, mbyte.utfc_ptr2char_len(to_string({c}), pcc, 1)) - eq(0, pcc[0]) + eq({'', 0}, test_seq{0}) + for c = 1, 127 do + eq(byte(c), test_seq{c}) + end + for c = 128, 255 do + eq({'', c}, test_seq{c}) end end) itp('2-byte sequences', function() - local pcc = to_intp() -- No combining characters - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f}), pcc, 2)) - eq(0, pcc[0]) + eq(byte(0x7f), test_seq{0x7f, 0x7f}) -- No combining characters - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x80}), pcc, 2)) - eq(0, pcc[0]) + eq(byte(0x7f), test_seq{0x7f, 0x80}) -- No UTF-8 sequence - pcc = to_intp() - eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f}), pcc, 2)) - eq(0, pcc[0]) + eq({'', 0xc2}, test_seq{0xc2, 0x7f}) -- One UTF-8 character - pcc = to_intp() - eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80}), pcc, 2)) - eq(0, pcc[0]) + eq({'\xc2\x80', 0x80}, test_seq{0xc2, 0x80}) -- No UTF-8 sequence - pcc = to_intp() - eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0xc0}), pcc, 2)) - eq(0, pcc[0]) + eq({'', 0xc2}, test_seq{0xc2, 0xc0}) end) itp('3-byte sequences', function() - local pcc = to_intp() - -- No second UTF-8 character - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x80, 0x80}), pcc, 3)) - eq(0, pcc[0]) + eq(byte(0x7f), test_seq{0x7f, 0x80, 0x80}) -- No combining character - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0x80}), pcc, 3)) - eq(0, pcc[0]) + eq(byte(0x7f), test_seq{0x7f, 0xc2, 0x80}) -- Combining character is U+0300 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80}), pcc, 3)) - eq(0x0300, pcc[0]) - eq(0x0000, pcc[1]) + eq({"\x7f\xcc\x80", 0x7f}, test_seq{0x7f, 0xcc, 0x80}) -- No UTF-8 sequence - pcc = to_intp() - eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc}), pcc, 3)) - eq(0, pcc[0]) + eq({'', 0xc2}, test_seq{0xc2, 0x7f, 0xcc}) -- Incomplete combining character - pcc = to_intp() - eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc}), pcc, 3)) - eq(0, pcc[0]) + eq({"\xc2\x80", 0x80}, test_seq{0xc2, 0x80, 0xcc}) - -- One UTF-8 character - pcc = to_intp() - eq(0x20d0, mbyte.utfc_ptr2char_len(to_string({0xe2, 0x83, 0x90}), pcc, 3)) - eq(0, pcc[0]) + -- One UTF-8 character (composing only) + eq({" \xe2\x83\x90", 0x20d0}, test_seq{0xe2, 0x83, 0x90}) end) itp('4-byte sequences', function() - local pcc = to_intp() -- No following combining character - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f, 0xcc, 0x80}), pcc, 4)) - eq(0, pcc[0]) + eq(byte(0x7f), test_seq{0x7f, 0x7f, 0xcc, 0x80}) -- No second UTF-8 character - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0xcc, 0x80}), pcc, 4)) - eq(0, pcc[0]) + eq(byte(0x7f), test_seq{0x7f, 0xc2, 0xcc, 0x80}) -- Combining character U+0300 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc}), pcc, 4)) - eq(0x0300, pcc[0]) - eq(0x0000, pcc[1]) + eq({"\x7f\xcc\x80", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc}) -- No UTF-8 sequence - pcc = to_intp() - eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc, 0x80}), pcc, 4)) - eq(0, pcc[0]) + eq({'', 0xc2}, test_seq{0xc2, 0x7f, 0xcc, 0x80}) -- No following UTF-8 character - pcc = to_intp() - eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0xcc}), pcc, 4)) - eq(0, pcc[0]) + eq({"\xc2\x80", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0xcc}) -- Combining character U+0301 - pcc = to_intp() - eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0x81}), pcc, 4)) - eq(0x0301, pcc[0]) - eq(0x0000, pcc[1]) + eq({"\xc2\x80\xcc\x81", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0x81}) -- One UTF-8 character - pcc = to_intp() - eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80}), pcc, 4)) - eq(0, pcc[0]) + eq({"\xf4\x80\x80\x80", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80}) end) itp('5+-byte sequences', function() - local pcc = to_intp() - -- No following combining character - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f, 0xcc, 0x80, 0x80}), pcc, 5)) - eq(0, pcc[0]) + eq(byte(0x7f), test_seq{0x7f, 0x7f, 0xcc, 0x80, 0x80}) -- No second UTF-8 character - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0xcc, 0x80, 0x80}), pcc, 5)) - eq(0, pcc[0]) + eq(byte(0x7f), test_seq{0x7f, 0xc2, 0xcc, 0x80, 0x80}) -- Combining character U+0300 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc}), pcc, 5)) - eq(0x0300, pcc[0]) - eq(0x0000, pcc[1]) + eq({"\x7f\xcc\x80", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x00}) -- Combining characters U+0300 and U+0301 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc, 0x81}), pcc, 5)) - eq(0x0300, pcc[0]) - eq(0x0301, pcc[1]) - eq(0x0000, pcc[2]) + eq({"\x7f\xcc\x80\xcc\x81", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81}) -- Combining characters U+0300, U+0301, U+0302 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82}), pcc, 7)) - eq(0x0300, pcc[0]) - eq(0x0301, pcc[1]) - eq(0x0302, pcc[2]) - eq(0x0000, pcc[3]) + eq({"\x7f\xcc\x80\xcc\x81\xcc\x82", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82}) -- Combining characters U+0300, U+0301, U+0302, U+0303 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83}), pcc, 9)) - eq(0x0300, pcc[0]) - eq(0x0301, pcc[1]) - eq(0x0302, pcc[2]) - eq(0x0303, pcc[3]) - eq(0x0000, pcc[4]) + eq({"\x7f\xcc\x80\xcc\x81\xcc\x82\xcc\x83", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83}) -- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string( - {0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84}), pcc, 11)) - eq(0x0300, pcc[0]) - eq(0x0301, pcc[1]) - eq(0x0302, pcc[2]) - eq(0x0303, pcc[3]) - eq(0x0304, pcc[4]) - eq(0x0000, pcc[5]) - -- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304, - -- U+0305 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string( - {0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84, 0xcc, 0x85}), pcc, 13)) - eq(0x0300, pcc[0]) - eq(0x0301, pcc[1]) - eq(0x0302, pcc[2]) - eq(0x0303, pcc[3]) - eq(0x0304, pcc[4]) - eq(0x0305, pcc[5]) - eq(1, pcc[6]) - - -- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304, - -- U+0305, U+0306, but only save six (= MAX_MCO). - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string( - {0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84, 0xcc, 0x85, 0xcc, 0x86}), pcc, 15)) - eq(0x0300, pcc[0]) - eq(0x0301, pcc[1]) - eq(0x0302, pcc[2]) - eq(0x0303, pcc[3]) - eq(0x0304, pcc[4]) - eq(0x0305, pcc[5]) - eq(0x0001, pcc[6]) + eq({"\x7f\xcc\x80\xcc\x81\xcc\x82\xcc\x83\xcc\x84", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84}) + -- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304, U+0305 + eq({"\x7f\xcc\x80\xcc\x81\xcc\x82\xcc\x83\xcc\x84\xcc\x85", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84, 0xcc, 0x85}) - -- Only three following combining characters U+0300, U+0301, U+0302 - pcc = to_intp() - eq(0x007f, mbyte.utfc_ptr2char_len(to_string( - {0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xc2, 0x80, 0xcc, 0x84, 0xcc, 0x85}), pcc, 13)) - eq(0x0300, pcc[0]) - eq(0x0301, pcc[1]) - eq(0x0302, pcc[2]) - eq(0x0000, pcc[3]) + -- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304, U+0305, U+0306 + eq({"\x7f\xcc\x80\xcc\x81\xcc\x82\xcc\x83\xcc\x84\xcc\x85\xcc\x86", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83, 0xcc, 0x84, 0xcc, 0x85, 0xcc, 0x86}) + -- Only three following combining characters U+0300, U+0301, U+0302 + eq({"\x7f\xcc\x80\xcc\x81\xcc\x82", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xc2, 0x80, 0xcc, 0x84, 0xcc, 0x85}) -- No UTF-8 sequence - pcc = to_intp() - eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc, 0x80, 0x80}), pcc, 5)) - eq(0, pcc[0]) + eq({'', 0xc2}, test_seq{0xc2, 0x7f, 0xcc, 0x80, 0x80}) -- No following UTF-8 character - pcc = to_intp() - eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0xcc, 0x80}), pcc, 5)) - eq(0, pcc[0]) + eq({"\xc2\x80", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0xcc, 0x80}) -- Combining character U+0301 - pcc = to_intp() - eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0x81, 0x7f}), pcc, 5)) - eq(0x0301, pcc[0]) - eq(0x0000, pcc[1]) + eq({"\xc2\x80\xcc\x81", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0x81, 0x7f}) -- Combining character U+0301 - pcc = to_intp() - eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0x81, 0xcc}), pcc, 5)) - eq(0x0301, pcc[0]) - eq(0x0000, pcc[1]) + eq({"\xc2\x80\xcc\x81", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0x81, 0xcc}) -- One UTF-8 character - pcc = to_intp() - eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0x7f}), pcc, 5)) - eq(0, pcc[0]) + eq({"\xf4\x80\x80\x80", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80, 0x7f}) -- One UTF-8 character - pcc = to_intp() - eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0x80}), pcc, 5)) - eq(0, pcc[0]) + eq({"\xf4\x80\x80\x80", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80, 0x80}) -- One UTF-8 character - pcc = to_intp() - eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0xcc}), pcc, 5)) - eq(0, pcc[0]) + eq({"\xf4\x80\x80\x80", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80, 0xcc}) -- Combining characters U+1AB0 and U+0301 - pcc = to_intp() - eq(0x100000, mbyte.utfc_ptr2char_len(to_string( - {0xf4, 0x80, 0x80, 0x80, 0xe1, 0xaa, 0xb0, 0xcc, 0x81}), pcc, 9)) - eq(0x1ab0, pcc[0]) - eq(0x0301, pcc[1]) - eq(0x0000, pcc[2]) + eq({"\xf4\x80\x80\x80\xe1\xaa\xb0\xcc\x81", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80, 0xe1, 0xaa, 0xb0, 0xcc, 0x81}) end) end) -- cgit From 79b6ff28ad1204fbb4199b9092f5c578d88cb28e Mon Sep 17 00:00:00 2001 From: dundargoc Date: Tue, 28 Nov 2023 20:31:00 +0100 Subject: refactor: fix headers with IWYU --- test/unit/eval/typval_spec.lua | 2 +- test/unit/preprocess.lua | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test/unit') diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua index 6fb8ba5a1c..34a1299725 100644 --- a/test/unit/eval/typval_spec.lua +++ b/test/unit/eval/typval_spec.lua @@ -43,7 +43,7 @@ local dict_watchers = eval_helpers.dict_watchers local lib = cimport('./src/nvim/eval/typval.h', './src/nvim/memory.h', './src/nvim/mbyte.h', './src/nvim/garray.h', - './src/nvim/eval.h', './src/nvim/vim.h', + './src/nvim/eval.h', './src/nvim/vim_defs.h', './src/nvim/globals.h') local function vimconv_alloc() diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua index c5fb62dce5..e356695c14 100644 --- a/test/unit/preprocess.lua +++ b/test/unit/preprocess.lua @@ -66,9 +66,9 @@ end --- #include --- #include --- ---- headerize({"vim.h", "memory.h"}, false) +--- headerize({"vim_defs.h", "memory.h"}, false) --- produces: ---- #include "vim.h" +--- #include "vim_defs.h" --- #include "memory.h" --- @param headers string[] --- @param global? boolean -- cgit