aboutsummaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/eval/helpers.lua4
-rw-r--r--test/unit/formatc.lua2
-rw-r--r--test/unit/helpers.lua1
-rw-r--r--test/unit/mbyte_spec.lua67
-rw-r--r--test/unit/os/fs_spec.lua2
-rw-r--r--test/unit/os/shell_spec.lua31
-rw-r--r--test/unit/tempfile_spec.lua5
7 files changed, 57 insertions, 55 deletions
diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua
index da2f5626ff..2367f03e0d 100644
--- a/test/unit/eval/helpers.lua
+++ b/test/unit/eval/helpers.lua
@@ -12,7 +12,7 @@ local null_list = {[true]='NULL list'}
local type_key = {[true]='type key'}
local list_type = {[true]='list type'}
-local list = function(...)
+local function list(...)
local ret = ffi.gc(eval.list_alloc(), eval.list_unref)
eq(0, ret.lv_refcount)
ret.lv_refcount = 1
@@ -47,7 +47,7 @@ local lst2tbl = function(l)
while li ~= nil do
local typ = li.li_tv.v_type
if typ == eval.VAR_STRING then
- str = li.li_tv.vval.v_string
+ local str = li.li_tv.vval.v_string
if str == nil then
ret[#ret + 1] = null_string
else
diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua
index 3f86c5f1b1..00637e0b8d 100644
--- a/test/unit/formatc.lua
+++ b/test/unit/formatc.lua
@@ -238,7 +238,7 @@ local function standalone(...) -- luacheck: ignore
end
-- uncomment this line (and comment the `return`) for standalone debugging
-- example usage:
--- ../../.deps/usr/bin/luajit formatc.lua ../../include/tempfile.h.generated.h
+-- ../../.deps/usr/bin/luajit formatc.lua ../../include/fileio.h.generated.h
-- ../../.deps/usr/bin/luajit formatc.lua /usr/include/malloc.h
-- standalone(...)
return formatc
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index 9b9c1fef0f..426ae2d9e0 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -140,6 +140,7 @@ do
local time = cimport('./src/nvim/os/time.h')
time.time_init()
main.early_init()
+ main.event_init()
end
-- C constants.
diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua
index e1b401c76d..9b2415a93f 100644
--- a/test/unit/mbyte_spec.lua
+++ b/test/unit/mbyte_spec.lua
@@ -3,7 +3,6 @@ local helpers = require("test.unit.helpers")
local ffi = helpers.ffi
local eq = helpers.eq
-local globals = helpers.cimport("./src/nvim/globals.h")
local mbyte = helpers.cimport("./src/nvim/mbyte.h")
describe('mbyte', function()
@@ -17,7 +16,7 @@ describe('mbyte', function()
-- Convert from bytes to string
local function to_string(bytes)
- s = {}
+ local s = {}
for i = 1, #bytes do
s[i] = string.char(bytes[i])
end
@@ -59,20 +58,20 @@ describe('mbyte', function()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f}), pcc, 2))
eq(0, pcc[0])
-- No combining characters
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x80}), pcc, 2))
eq(0, pcc[0])
-- No UTF-8 sequence
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f}), pcc, 2))
eq(0, pcc[0])
-- One UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80}), pcc, 2))
eq(0, pcc[0])
-- No UTF-8 sequence
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0xc0}), pcc, 2))
eq(0, pcc[0])
end)
@@ -84,27 +83,27 @@ describe('mbyte', function()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x80, 0x80}), pcc, 3))
eq(0, pcc[0])
-- No combining character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0x80}), pcc, 3))
eq(0, pcc[0])
-- Combining character is U+0300
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xcc, 0x80}), pcc, 3))
eq(0x0300, pcc[0])
eq(0x0000, pcc[1])
-- No UTF-8 sequence
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc}), pcc, 3))
eq(0, pcc[0])
-- Incomplete combining character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc}), pcc, 3))
eq(0, pcc[0])
-- One UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x20d0, mbyte.utfc_ptr2char_len(to_string({0xe2, 0x83, 0x90}), pcc, 3))
eq(0, pcc[0])
end)
@@ -116,32 +115,32 @@ describe('mbyte', function()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f, 0xcc, 0x80}), pcc, 4))
eq(0, pcc[0])
-- No second UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0xcc, 0x80}), pcc, 4))
eq(0, pcc[0])
-- Combining character U+0300
- local pcc = to_intp()
+ 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])
-- No UTF-8 sequence
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc, 0x80}), pcc, 4))
eq(0, pcc[0])
-- No following UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0xcc}), pcc, 4))
eq(0, pcc[0])
-- Combining character U+0301
- local pcc = to_intp()
+ 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])
-- One UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80}), pcc, 4))
eq(0, pcc[0])
end)
@@ -153,31 +152,31 @@ describe('mbyte', function()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0x7f, 0xcc, 0x80, 0x80}), pcc, 5))
eq(0, pcc[0])
-- No second UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x007f, mbyte.utfc_ptr2char_len(to_string({0x7f, 0xc2, 0xcc, 0x80, 0x80}), pcc, 5))
eq(0, pcc[0])
-- Combining character U+0300
- local pcc = to_intp()
+ 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])
-- Combining characters U+0300 and U+0301
- local pcc = to_intp()
+ 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])
-- Combining characters U+0300, U+0301, U+0302
- local pcc = to_intp()
+ 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])
-- Combining characters U+0300, U+0301, U+0302, U+0303
- local pcc = to_intp()
+ 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])
@@ -185,7 +184,7 @@ describe('mbyte', function()
eq(0x0303, pcc[3])
eq(0x0000, pcc[4])
-- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304
- local pcc = to_intp()
+ 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])
@@ -196,7 +195,7 @@ describe('mbyte', function()
eq(0x0000, pcc[5])
-- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304,
-- U+0305
- local pcc = to_intp()
+ 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])
@@ -209,7 +208,7 @@ describe('mbyte', function()
-- Combining characters U+0300, U+0301, U+0302, U+0303, U+0304,
-- U+0305, U+0306, but only save six (= MAX_MCO).
- local pcc = to_intp()
+ 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])
@@ -221,7 +220,7 @@ describe('mbyte', function()
eq(0x0001, pcc[6])
-- Only three following combining characters U+0300, U+0301, U+0302
- local pcc = to_intp()
+ 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])
@@ -231,40 +230,40 @@ describe('mbyte', function()
-- No UTF-8 sequence
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x00c2, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x7f, 0xcc, 0x80, 0x80}), pcc, 5))
eq(0, pcc[0])
-- No following UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x0080, mbyte.utfc_ptr2char_len(to_string({0xc2, 0x80, 0xcc, 0xcc, 0x80}), pcc, 5))
eq(0, pcc[0])
-- Combining character U+0301
- local pcc = to_intp()
+ 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])
-- Combining character U+0301
- local pcc = to_intp()
+ 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])
-- One UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0x7f}), pcc, 5))
eq(0, pcc[0])
-- One UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0x80}), pcc, 5))
eq(0, pcc[0])
-- One UTF-8 character
- local pcc = to_intp()
+ pcc = to_intp()
eq(0x100000, mbyte.utfc_ptr2char_len(to_string({0xf4, 0x80, 0x80, 0x80, 0xcc}), pcc, 5))
eq(0, pcc[0])
-- Combining characters U+1AB0 and U+0301
- local pcc = to_intp()
+ 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])
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua
index 2f393d353d..71b5e7f576 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -148,7 +148,7 @@ describe('fs function', function()
local function os_can_exe(name)
local buf = ffi.new('char *[1]')
buf[0] = NULL
- local ok = fs.os_can_exe(to_cstr(name), buf)
+ local ok = fs.os_can_exe(to_cstr(name), buf, true)
-- When os_can_exe returns true, it must set the path.
-- When it returns false, the path must be NULL.
diff --git a/test/unit/os/shell_spec.lua b/test/unit/os/shell_spec.lua
index 6d1a9f3589..93103e4e8c 100644
--- a/test/unit/os/shell_spec.lua
+++ b/test/unit/os/shell_spec.lua
@@ -11,7 +11,7 @@ if allowed_os[jit.os] ~= true then
end
local helpers = require('test.unit.helpers')
-local shell = helpers.cimport(
+local cimported = helpers.cimport(
'./src/nvim/os/shell.h',
'./src/nvim/option_defs.h',
'./src/nvim/main.h',
@@ -25,18 +25,17 @@ local NULL = ffi.cast('void *', 0)
describe('shell functions', function()
setup(function()
- shell.event_init()
-- os_system() can't work when the p_sh and p_shcf variables are unset
- shell.p_sh = to_cstr('/bin/bash')
- shell.p_shcf = to_cstr('-c')
+ cimported.p_sh = to_cstr('/bin/bash')
+ cimported.p_shcf = to_cstr('-c')
end)
teardown(function()
- shell.event_teardown()
+ cimported.event_teardown()
end)
local function shell_build_argv(cmd, extra_args)
- local res = shell.shell_build_argv(
+ local res = cimported.shell_build_argv(
cmd and to_cstr(cmd),
extra_args and to_cstr(extra_args))
local argc = 0
@@ -45,10 +44,10 @@ describe('shell functions', function()
-- crash.
while res[argc] ~= nil do
ret[#ret + 1] = ffi.string(res[argc])
- shell.xfree(res[argc])
+ cimported.xfree(res[argc])
argc = argc + 1
end
- shell.xfree(res)
+ cimported.xfree(res)
return ret
end
@@ -59,8 +58,8 @@ describe('shell functions', function()
local nread = ffi.new('size_t[1]')
local argv = ffi.cast('char**',
- shell.shell_build_argv(to_cstr(cmd), nil))
- local status = shell.os_system(argv, input_or, input_len, output, nread)
+ cimported.shell_build_argv(to_cstr(cmd), nil))
+ local status = cimported.os_system(argv, input_or, input_len, output, nread)
return status, intern(output[0], nread[0])
end
@@ -97,13 +96,13 @@ describe('shell functions', function()
local saved_opts = {}
setup(function()
- saved_opts.p_sh = shell.p_sh
- saved_opts.p_shcf = shell.p_shcf
+ saved_opts.p_sh = cimported.p_sh
+ saved_opts.p_shcf = cimported.p_shcf
end)
teardown(function()
- shell.p_sh = saved_opts.p_sh
- shell.p_shcf = saved_opts.p_shcf
+ cimported.p_sh = saved_opts.p_sh
+ cimported.p_shcf = saved_opts.p_shcf
end)
it('works with NULL arguments', function()
@@ -123,8 +122,8 @@ describe('shell functions', function()
end)
it('splits and unquotes &shell and &shellcmdflag', function()
- shell.p_sh = to_cstr('/Program" "Files/zsh -f')
- shell.p_shcf = to_cstr('-x -o "sh word split" "-"c')
+ cimported.p_sh = to_cstr('/Program" "Files/zsh -f')
+ cimported.p_shcf = to_cstr('-x -o "sh word split" "-"c')
eq({'/Program Files/zsh', '-f',
'ghi jkl',
'-x', '-o', 'sh word split',
diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua
index e558ff04c8..7975d11aed 100644
--- a/test/unit/tempfile_spec.lua
+++ b/test/unit/tempfile_spec.lua
@@ -2,9 +2,12 @@ local lfs = require 'lfs'
local helpers = require 'test.unit.helpers'
local os = helpers.cimport './src/nvim/os/os.h'
-local tempfile = helpers.cimport './src/nvim/tempfile.h'
+local tempfile = helpers.cimport './src/nvim/fileio.h'
describe('tempfile related functions', function()
+ before_each(function()
+ tempfile.vim_deltempdir()
+ end)
after_each(function()
tempfile.vim_deltempdir()
end)