aboutsummaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/helpers.lua4
-rw-r--r--test/unit/mbyte_spec.lua5
-rw-r--r--test/unit/os/env_spec.lua2
-rw-r--r--test/unit/os/fs_spec.lua2
-rw-r--r--test/unit/path_spec.lua6
-rw-r--r--test/unit/preprocess.lua4
-rw-r--r--test/unit/tui_spec.lua136
7 files changed, 147 insertions, 12 deletions
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index 24dbc65bd0..bacdc54416 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -545,7 +545,7 @@ 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 = 1
+ trace_level = 0
else
trace_level = tonumber(trace_level)
end
@@ -708,7 +708,7 @@ local function check_child_err(rd)
local eres = sc.read(rd, 2)
if eres ~= '$\n' then
if #trace == 0 then
- err = '\nTest crashed, no trace available\n'
+ err = '\nTest crashed, no trace available (check NVIM_TEST_TRACE_LEVEL)\n'
else
err = '\nTest crashed, trace:\n' .. tracehelp
for i = 1, #trace do
diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua
index d27f52923a..fdb1bceab0 100644
--- a/test/unit/mbyte_spec.lua
+++ b/test/unit/mbyte_spec.lua
@@ -8,11 +8,6 @@ local mbyte = helpers.cimport("./src/nvim/mbyte.h")
local charset = helpers.cimport('./src/nvim/charset.h')
describe('mbyte', function()
- if helpers.isCI('quickbuild') then
- pending("crashes on quickbuild", function() end)
- return
- end
-
-- Array for composing characters
local intp = ffi.typeof('int[?]')
local function to_intp()
diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua
index c543551607..e24a389d69 100644
--- a/test/unit/os/env_spec.lua
+++ b/test/unit/os/env_spec.lua
@@ -121,7 +121,7 @@ describe('env.c', function()
local name = 'NVIM_UNIT_TEST_GETENV_1N'
local value = 'NVIM_UNIT_TEST_GETENV_1V'
eq(NULL, os_getenv(name))
- -- Use os_setenv because Lua dosen't have setenv.
+ -- Use os_setenv because Lua doesn't have setenv.
os_setenv(name, value, 1)
eq(value, os_getenv(name))
diff --git a/test/unit/os/fs_spec.lua b/test/unit/os/fs_spec.lua
index 526a09e845..7fd71cb1ae 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -110,7 +110,7 @@ describe('fs.c', function()
describe('os_chdir', function()
itp('fails with path="~"', function()
- eq(false, os_isdir('~')) -- sanity check: no literal "~" directory.
+ eq(false, os_isdir('~'), 'sanity check: no literal "~" directory')
local length = 4096
local expected_cwd = cstr(length, '')
local cwd = cstr(length, '')
diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua
index e8ce660ce1..356c4997fa 100644
--- a/test/unit/path_spec.lua
+++ b/test/unit/path_spec.lua
@@ -66,10 +66,10 @@ describe('path.c', function()
end)
describe('path_full_compare', function()
- local function path_full_compare(s1, s2, cn)
+ local function path_full_compare(s1, s2, cn, ee)
s1 = to_cstr(s1)
s2 = to_cstr(s2)
- return cimp.path_full_compare(s1, s2, cn or 0)
+ return cimp.path_full_compare(s1, s2, cn or 0, ee or 1)
end
local f1 = 'f1.o'
@@ -456,7 +456,7 @@ describe('path.c', function()
end)
itp('fails and uses filename when the path is relative to HOME', function()
- eq(false, cimp.os_isdir('~')) -- sanity check: no literal "~" directory.
+ eq(false, cimp.os_isdir('~'), 'sanity check: no literal "~" directory')
local absolute_path = '~/home.file'
local buflen = string.len(absolute_path) + 1
local do_expand = 1
diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua
index 1073855a7d..3786bc2122 100644
--- a/test/unit/preprocess.lua
+++ b/test/unit/preprocess.lua
@@ -89,6 +89,10 @@ local Gcc = {
get_defines_extra_flags = {'-std=c99', '-dM', '-E'},
get_declarations_extra_flags = {'-std=c99', '-P', '-E'},
}
+if ffi.abi("32bit") then
+ table.insert(Gcc.get_defines_extra_flags, '-m32')
+ table.insert(Gcc.get_declarations_extra_flags, '-m32')
+end
function Gcc:define(name, args, val)
local define = '-D' .. name
diff --git a/test/unit/tui_spec.lua b/test/unit/tui_spec.lua
new file mode 100644
index 0000000000..e6b5c889d7
--- /dev/null
+++ b/test/unit/tui_spec.lua
@@ -0,0 +1,136 @@
+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")
+
+itp('handle_background_color', function()
+ local handle_background_color = cinput.ut_handle_background_color
+ local term_input = ffi.new('TermInput', {})
+ local events = globals.main_loop.thread_events
+
+ -- Short-circuit when not waiting for response.
+ term_input.waiting_for_bg_response = 0
+ eq(false, 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(true, handle_background_color(term_input))
+ eq(0, term_input.waiting_for_bg_response)
+ eq(1, multiqueue.multiqueue_size(events))
+
+ local event = multiqueue.multiqueue_get(events)
+ local bg_event = ffi.cast("Event*", event.argv[1])
+ eq(bg, ffi.string(bg_event.argv[0]))
+
+ -- 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: not necessarily correct behavior, but tests it.
+ 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(false, handle_background_color(term_input))
+ eq(0, term_input.waiting_for_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(false, 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(true, handle_background_color(term_input))
+ eq(0, term_input.waiting_for_bg_response)
+
+ eq(1, multiqueue.multiqueue_size(events))
+ eq(3, rbuf.size)
+ rbuffer.rbuffer_consumed(rbuf, rbuf.size)
+end)