diff options
Diffstat (limited to 'test/unit')
-rw-r--r-- | test/unit/buffer_spec.lua | 187 | ||||
-rw-r--r-- | test/unit/fixtures/rbuffer.c | 2 | ||||
-rw-r--r-- | test/unit/helpers.lua | 6 | ||||
-rw-r--r-- | test/unit/keycodes_spec.lua (renamed from test/unit/keymap_spec.lua) | 25 | ||||
-rw-r--r-- | test/unit/marktree_spec.lua | 44 | ||||
-rw-r--r-- | test/unit/os/env_spec.lua | 4 | ||||
-rw-r--r-- | test/unit/os/users_spec.lua | 12 | ||||
-rw-r--r-- | test/unit/path_spec.lua | 16 | ||||
-rw-r--r-- | test/unit/search_spec.lua | 24 | ||||
-rw-r--r-- | test/unit/strings_spec.lua | 47 | ||||
-rw-r--r-- | test/unit/tempfile_spec.lua | 12 | ||||
-rw-r--r-- | test/unit/viml/expressions/parser_spec.lua | 1 |
12 files changed, 248 insertions, 132 deletions
diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua index 3692e19379..204d713fb7 100644 --- a/test/unit/buffer_spec.lua +++ b/test/unit/buffer_spec.lua @@ -17,22 +17,22 @@ describe('buffer functions', function() return buffer.buflist_new(c_file, c_file, 1, flags) end - local close_buffer = function(win, buf, action, abort_if_last) - return buffer.close_buffer(win, buf, action, abort_if_last) + local close_buffer = function(win, buf, action, abort_if_last, ignore_abort) + return buffer.close_buffer(win, buf, action, abort_if_last, ignore_abort) end local path1 = 'test_file_path' local path2 = 'file_path_test' local path3 = 'path_test_file' - before_each(function() + setup(function() -- create the files io.open(path1, 'w').close() io.open(path2, 'w').close() io.open(path3, 'w').close() end) - after_each(function() + teardown(function() os.remove(path1) os.remove(path2) os.remove(path3) @@ -53,7 +53,7 @@ describe('buffer functions', function() itp('should view a closed and hidden buffer as valid', function() local buf = buflist_new(path1, buffer.BLN_LISTED) - close_buffer(NULL, buf, 0, 0) + close_buffer(NULL, buf, 0, 0, 0) eq(true, buffer.buf_valid(buf)) end) @@ -61,7 +61,7 @@ describe('buffer functions', function() itp('should view a closed and unloaded buffer as valid', function() local buf = buflist_new(path1, buffer.BLN_LISTED) - close_buffer(NULL, buf, buffer.DOBUF_UNLOAD, 0) + close_buffer(NULL, buf, buffer.DOBUF_UNLOAD, 0, 0) eq(true, buffer.buf_valid(buf)) end) @@ -69,7 +69,7 @@ describe('buffer functions', function() itp('should view a closed and wiped buffer as invalid', function() local buf = buflist_new(path1, buffer.BLN_LISTED) - close_buffer(NULL, buf, buffer.DOBUF_WIPE, 0) + close_buffer(NULL, buf, buffer.DOBUF_WIPE, 0, 0) eq(false, buffer.buf_valid(buf)) end) @@ -90,7 +90,7 @@ describe('buffer functions', function() eq(buf.handle, buflist_findpat(path1, ONLY_LISTED)) - close_buffer(NULL, buf, buffer.DOBUF_WIPE, 0) + close_buffer(NULL, buf, buffer.DOBUF_WIPE, 0, 0) end) itp('should prefer to match the start of a file path', function() @@ -102,9 +102,9 @@ describe('buffer functions', function() eq(buf2.handle, buflist_findpat("file", ONLY_LISTED)) eq(buf3.handle, buflist_findpat("path", ONLY_LISTED)) - close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0) - close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0) - close_buffer(NULL, buf3, buffer.DOBUF_WIPE, 0) + close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0, 0) + close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0, 0) + close_buffer(NULL, buf3, buffer.DOBUF_WIPE, 0, 0) end) itp('should prefer to match the end of a file over the middle', function() @@ -118,7 +118,7 @@ describe('buffer functions', function() --} --{ When: We close buf2 - close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0) + close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0, 0) -- And: Open buf1, which has 'file' in the middle of its name local buf1 = buflist_new(path1, buffer.BLN_LISTED) @@ -127,8 +127,8 @@ describe('buffer functions', function() eq(buf3.handle, buflist_findpat("file", ONLY_LISTED)) --} - close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0) - close_buffer(NULL, buf3, buffer.DOBUF_WIPE, 0) + close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0, 0) + close_buffer(NULL, buf3, buffer.DOBUF_WIPE, 0, 0) end) itp('should match a unique fragment of a file path', function() @@ -138,9 +138,9 @@ describe('buffer functions', function() eq(buf3.handle, buflist_findpat("_test_", ONLY_LISTED)) - close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0) - close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0) - close_buffer(NULL, buf3, buffer.DOBUF_WIPE, 0) + close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0, 0) + close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0, 0) + close_buffer(NULL, buf3, buffer.DOBUF_WIPE, 0, 0) end) itp('should include / ignore unlisted buffers based on the flag.', function() @@ -152,7 +152,7 @@ describe('buffer functions', function() --} --{ When: We unlist the buffer - close_buffer(NULL, buf3, buffer.DOBUF_DEL, 0) + close_buffer(NULL, buf3, buffer.DOBUF_DEL, 0, 0) -- Then: It should not find the buffer when searching only listed buffers eq(-1, buflist_findpat("_test_", ONLY_LISTED)) @@ -162,7 +162,7 @@ describe('buffer functions', function() --} --{ When: We wipe the buffer - close_buffer(NULL, buf3, buffer.DOBUF_WIPE, 0) + close_buffer(NULL, buf3, buffer.DOBUF_WIPE, 0, 0) -- Then: It should not find the buffer at all eq(-1, buflist_findpat("_test_", ONLY_LISTED)) @@ -180,7 +180,7 @@ describe('buffer functions', function() --} --{ When: The first buffer is unlisted - close_buffer(NULL, buf1, buffer.DOBUF_DEL, 0) + close_buffer(NULL, buf1, buffer.DOBUF_DEL, 0, 0) -- Then: The second buffer is preferred because -- unlisted buffers are not allowed @@ -194,7 +194,7 @@ describe('buffer functions', function() --} --{ When: We unlist the second buffer - close_buffer(NULL, buf2, buffer.DOBUF_DEL, 0) + close_buffer(NULL, buf2, buffer.DOBUF_DEL, 0, 0) -- Then: The first buffer is preferred again -- because buf1 matches better which takes precedence @@ -205,8 +205,8 @@ describe('buffer functions', function() eq(-1, buflist_findpat("test", ONLY_LISTED)) --} - close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0) - close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0) + close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0, 0) + close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0, 0) end) end) @@ -249,7 +249,7 @@ describe('buffer functions', function() -- -- @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 + -- .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, @@ -264,7 +264,7 @@ describe('buffer functions', function() 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_cell_count + local expected_byte_length = option.expected_byte_length or #expected_stl itp(description, function() if option.file_name then @@ -312,12 +312,12 @@ describe('buffer functions', function() 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 handle multibyte-fillchar as a dash', 10, - 'abcde%=', 'abcde-----', - {fillchar=0x80}) statusline_test('should print the tail file name', 80, '%t', 'buffer_spec.lua', {file_name='test/unit/buffer_spec.lua', expected_cell_count=15}) @@ -366,70 +366,86 @@ describe('buffer functions', function() statusline_test('should ignore trailing %', 3, 'abc%', 'abc') - -- alignment testing - statusline_test('should right align when using =', 20, - 'neo%=vim', 'neo vim') - statusline_test('should, when possible, center text when using %=text%=', 20, - 'abc%=neovim%=def', 'abc neovim def') - statusline_test('should handle uneven spacing in the buffer when using %=text%=', 20, - 'abc%=neo_vim%=def', 'abc neo_vim def') - statusline_test('should have equal spaces even with non-equal sides when using =', 20, - 'foobar%=test%=baz', 'foobar test baz') - statusline_test('should have equal spaces even with longer right side when using =', 20, - 'a%=test%=longtext', 'a test longtext') - statusline_test('should handle an empty left side when using ==', 20, - '%=test%=baz', ' test baz') - statusline_test('should handle an empty right side when using ==', 20, - 'foobar%=test%=', 'foobar test ') - statusline_test('should handle consecutive empty ==', 20, - '%=%=test%=', ' test ') - statusline_test('should handle an = alone', 20, - '%=', ' ') - statusline_test('should right align text when it is alone with =', 20, - '%=foo', ' foo') - statusline_test('should left align text when it is alone with =', 20, - 'foo%=', 'foo ') - - statusline_test('should approximately center text when using %=text%=', 21, - 'abc%=neovim%=def', 'abc neovim def') - statusline_test('should completely fill the buffer when using %=text%=', 21, - 'abc%=neo_vim%=def', 'abc neo_vim def') - statusline_test('should have equal spaces even with non-equal sides when using =', 21, - 'foobar%=test%=baz', 'foobar test baz') - statusline_test('should have equal spaces even with longer right side when using =', 21, - 'a%=test%=longtext', 'a test longtext') - statusline_test('should handle an empty left side when using ==', 21, - '%=test%=baz', ' test baz') - statusline_test('should handle an empty right side when using ==', 21, - 'foobar%=test%=', 'foobar test ') - - statusline_test('should quadrant the text when using 3 %=', 40, - 'abcd%=n%=eovim%=ef', 'abcd n eovim ef') - statusline_test('should work well with %t', 40, - '%t%=right_aligned', 'buffer_spec.lua right_aligned', + -- alignment testing with fillchar + local function statusline_test_align (description, + statusline_cell_count, + input_stl, + expected_stl, + arg) + arg = arg or {} + statusline_test(description .. ' without fillchar', + statusline_cell_count, input_stl, expected_stl:gsub('%~', ' '), arg) + arg.fillchar = ('!'):byte() + statusline_test(description .. ' with fillchar `!`', + statusline_cell_count, input_stl, expected_stl:gsub('%~', '!'), arg) + arg.fillchar = 0x2501 + statusline_test(description .. ' with fillchar `━`', + statusline_cell_count, input_stl, expected_stl:gsub('%~', '━'), arg) + end + + statusline_test_align('should right align when using =', 20, + 'neo%=vim', 'neo~~~~~~~~~~~~~~vim') + statusline_test_align('should, when possible, center text when using %=text%=', 20, + 'abc%=neovim%=def', 'abc~~~~neovim~~~~def') + statusline_test_align('should handle uneven spacing in the buffer when using %=text%=', 20, + 'abc%=neo_vim%=def', 'abc~~~neo_vim~~~~def') + statusline_test_align('should have equal spaces even with non-equal sides when using =', 20, + 'foobar%=test%=baz', 'foobar~~~test~~~~baz') + statusline_test_align('should have equal spaces even with longer right side when using =', 20, + 'a%=test%=longtext', 'a~~~test~~~~longtext') + statusline_test_align('should handle an empty left side when using ==', 20, + '%=test%=baz', '~~~~~~test~~~~~~~baz') + statusline_test_align('should handle an empty right side when using ==', 20, + 'foobar%=test%=', 'foobar~~~~~test~~~~~') + statusline_test_align('should handle consecutive empty ==', 20, + '%=%=test%=', '~~~~~~~~~~test~~~~~~') + statusline_test_align('should handle an = alone', 20, + '%=', '~~~~~~~~~~~~~~~~~~~~') + statusline_test_align('should right align text when it is alone with =', 20, + '%=foo', '~~~~~~~~~~~~~~~~~foo') + statusline_test_align('should left align text when it is alone with =', 20, + 'foo%=', 'foo~~~~~~~~~~~~~~~~~') + + statusline_test_align('should approximately center text when using %=text%=', 21, + 'abc%=neovim%=def', 'abc~~~~neovim~~~~~def') + statusline_test_align('should completely fill the buffer when using %=text%=', 21, + 'abc%=neo_vim%=def', 'abc~~~~neo_vim~~~~def') + statusline_test_align('should have equal spacing even with non-equal sides when using =', 21, + 'foobar%=test%=baz', 'foobar~~~~test~~~~baz') + statusline_test_align('should have equal spacing even with longer right side when using =', 21, + 'a%=test%=longtext', 'a~~~~test~~~~longtext') + statusline_test_align('should handle an empty left side when using ==', 21, + '%=test%=baz', '~~~~~~~test~~~~~~~baz') + statusline_test_align('should handle an empty right side when using ==', 21, + 'foobar%=test%=', 'foobar~~~~~test~~~~~~') + + statusline_test_align('should quadrant the text when using 3 %=', 40, + 'abcd%=n%=eovim%=ef', 'abcd~~~~~~~~~n~~~~~~~~~eovim~~~~~~~~~~ef') + statusline_test_align('should work well with %t', 40, + '%t%=right_aligned', 'buffer_spec.lua~~~~~~~~~~~~right_aligned', {file_name='test/unit/buffer_spec.lua'}) - statusline_test('should work well with %t and regular text', 40, - 'l%=m_l %t m_r%=r', 'l m_l buffer_spec.lua m_r r', + statusline_test_align('should work well with %t and regular text', 40, + 'l%=m_l %t m_r%=r', 'l~~~~~~~m_l buffer_spec.lua m_r~~~~~~~~r', {file_name='test/unit/buffer_spec.lua'}) - statusline_test('should work well with %=, %t, %L, and %l', 40, - '%t %= %L %= %l', 'buffer_spec.lua 1 0', + statusline_test_align('should work well with %=, %t, %L, and %l', 40, + '%t %= %L %= %l', 'buffer_spec.lua ~~~~~~~~~ 1 ~~~~~~~~~~ 0', {file_name='test/unit/buffer_spec.lua'}) - statusline_test('should quadrant the text when using 3 %=', 41, - 'abcd%=n%=eovim%=ef', 'abcd n eovim ef') - statusline_test('should work well with %t', 41, - '%t%=right_aligned', 'buffer_spec.lua right_aligned', + statusline_test_align('should quadrant the text when using 3 %=', 41, + 'abcd%=n%=eovim%=ef', 'abcd~~~~~~~~~n~~~~~~~~~eovim~~~~~~~~~~~ef') + statusline_test_align('should work well with %t', 41, + '%t%=right_aligned', 'buffer_spec.lua~~~~~~~~~~~~~right_aligned', {file_name='test/unit/buffer_spec.lua'}) - statusline_test('should work well with %t and regular text', 41, - 'l%=m_l %t m_r%=r', 'l m_l buffer_spec.lua m_r r', + statusline_test_align('should work well with %t and regular text', 41, + 'l%=m_l %t m_r%=r', 'l~~~~~~~~m_l buffer_spec.lua m_r~~~~~~~~r', {file_name='test/unit/buffer_spec.lua'}) - statusline_test('should work well with %=, %t, %L, and %l', 41, - '%t %= %L %= %l', 'buffer_spec.lua 1 0', + statusline_test_align('should work well with %=, %t, %L, and %l', 41, + '%t %= %L %= %l', 'buffer_spec.lua ~~~~~~~~~~ 1 ~~~~~~~~~~ 0', {file_name='test/unit/buffer_spec.lua'}) - statusline_test('should work with 10 %=', 50, + statusline_test_align('should work with 10 %=', 50, 'aaaa%=b%=c%=d%=e%=fg%=hi%=jk%=lmnop%=qrstuv%=wxyz', - 'aaaa b c d e fg hi jk lmnop qrstuv wxyz') + 'aaaa~~b~~c~~d~~e~~fg~~hi~~jk~~lmnop~~qrstuv~~~wxyz') -- stl item testing local tabline = '' @@ -452,11 +468,10 @@ describe('buffer functions', function() -- multi-byte testing statusline_test('should handle multibyte characters', 10, - 'Ĉ%=x', 'Ĉ x', - {expected_byte_length=11}) + 'Ĉ%=x', 'Ĉ x') statusline_test('should handle multibyte characters and different fillchars', 10, 'Ą%=mid%=end', 'Ą@mid@@end', - {fillchar=('@'):byte(), expected_byte_length=11}) + {fillchar=('@'):byte()}) -- escaping % testing statusline_test('should handle escape of %', 4, 'abc%%', 'abc%') diff --git a/test/unit/fixtures/rbuffer.c b/test/unit/fixtures/rbuffer.c index 3f4062fa18..efa7ab1986 100644 --- a/test/unit/fixtures/rbuffer.c +++ b/test/unit/fixtures/rbuffer.c @@ -15,7 +15,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) { + RBUFFER_UNTIL_FULL(buf, wptr, wcnt) { // -V1044 cb(wptr, wcnt); rbuffer_produced(buf, wcnt); } diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index 465b553693..29ea0235be 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -2,7 +2,7 @@ local ffi = require('ffi') local formatc = require('test.unit.formatc') local Set = require('test.unit.set') local Preprocess = require('test.unit.preprocess') -local Paths = require('test.config.paths') +local Paths = require('test.cmakeconfig.paths') local global_helpers = require('test.helpers') local assert = require('luassert') local say = require('say') @@ -96,6 +96,7 @@ local init = only_separate(function() c.func(unpack(c.args)) end libnvim.time_init() + libnvim.fs_init() libnvim.event_init() libnvim.early_init(nil) if child_calls_mod then @@ -778,7 +779,8 @@ local function cppimport(path) return cimport(Paths.test_source_path .. '/test/includes/pre/' .. path) end -cimport('./src/nvim/types.h', './src/nvim/main.h', './src/nvim/os/time.h') +cimport('./src/nvim/types.h', './src/nvim/main.h', './src/nvim/os/time.h', + './src/nvim/os/fs.h') local function conv_enum(etab, eval) local n = tonumber(eval) diff --git a/test/unit/keymap_spec.lua b/test/unit/keycodes_spec.lua index 595a19eb17..5bf27c9232 100644 --- a/test/unit/keymap_spec.lua +++ b/test/unit/keycodes_spec.lua @@ -5,9 +5,10 @@ local ffi = helpers.ffi local eq = helpers.eq local neq = helpers.neq -local keymap = helpers.cimport("./src/nvim/keymap.h") +local keymap = helpers.cimport('./src/nvim/keycodes.h') +local NULL = helpers.NULL -describe('keymap.c', function() +describe('keycodes.c', function() describe('find_special_key()', function() local srcp = ffi.new('const unsigned char *[1]') @@ -15,12 +16,12 @@ describe('keymap.c', function() itp('no keycode', function() srcp[0] = 'abc' - eq(0, keymap.find_special_key(srcp, 3, modp, false, false, false)) + eq(0, keymap.find_special_key(srcp, 3, modp, 0, NULL)) end) itp('keycode with multiple modifiers', function() srcp[0] = '<C-M-S-A>' - neq(0, keymap.find_special_key(srcp, 9, modp, false, false, false)) + neq(0, keymap.find_special_key(srcp, 9, modp, 0, NULL)) neq(0, modp[0]) end) @@ -28,22 +29,22 @@ describe('keymap.c', function() -- Compare other capitalizations to this. srcp[0] = '<C-A>' local all_caps_key = - keymap.find_special_key(srcp, 5, modp, false, false, false) + keymap.find_special_key(srcp, 5, modp, 0, NULL) local all_caps_mod = modp[0] srcp[0] = '<C-a>' eq(all_caps_key, - keymap.find_special_key(srcp, 5, modp, false, false, false)) + keymap.find_special_key(srcp, 5, modp, 0, NULL)) eq(all_caps_mod, modp[0]) srcp[0] = '<c-A>' eq(all_caps_key, - keymap.find_special_key(srcp, 5, modp, false, false, false)) + keymap.find_special_key(srcp, 5, modp, 0, NULL)) eq(all_caps_mod, modp[0]) srcp[0] = '<c-a>' eq(all_caps_key, - keymap.find_special_key(srcp, 5, modp, false, false, false)) + keymap.find_special_key(srcp, 5, modp, 0, NULL)) eq(all_caps_mod, modp[0]) end) @@ -51,20 +52,20 @@ describe('keymap.c', function() -- Unescaped with in_string=false srcp[0] = '<C-">' eq(string.byte('"'), - keymap.find_special_key(srcp, 5, modp, false, false, false)) + keymap.find_special_key(srcp, 5, modp, 0, NULL)) -- Unescaped with in_string=true - eq(0, keymap.find_special_key(srcp, 5, modp, false, false, true)) + eq(0, keymap.find_special_key(srcp, 5, modp, keymap.FSK_IN_STRING, NULL)) -- Escaped with in_string=false srcp[0] = '<C-\\">' -- Should fail because the key is invalid -- (more than 1 non-modifier character). - eq(0, keymap.find_special_key(srcp, 6, modp, false, false, false)) + eq(0, keymap.find_special_key(srcp, 6, modp, 0, NULL)) -- Escaped with in_string=true eq(string.byte('"'), - keymap.find_special_key(srcp, 6, modp, false, false, true)) + keymap.find_special_key(srcp, 6, modp, keymap.FSK_IN_STRING, NULL)) end) end) diff --git a/test/unit/marktree_spec.lua b/test/unit/marktree_spec.lua index 10d02d2eb4..3c96bc5f58 100644 --- a/test/unit/marktree_spec.lua +++ b/test/unit/marktree_spec.lua @@ -32,11 +32,11 @@ local function shadoworder(tree, shadow, iter, giveorder) local mark = lib.marktree_itr_current(iter) local id = tonumber(mark.id) local spos = shadow[id] - if (mark.row ~= spos[1] or mark.col ~= spos[2]) then - error("invalid pos for "..id..":("..mark.row..", "..mark.col..") instead of ("..spos[1]..", "..spos[2]..")") + if (mark.pos.row ~= spos[1] or mark.pos.col ~= spos[2]) then + error("invalid pos for "..id..":("..mark.pos.row..", "..mark.pos.col..") instead of ("..spos[1]..", "..spos[2]..")") end - if mark.right_gravity ~= spos[3] then - error("invalid gravity for "..id..":("..mark.row..", "..mark.col..")") + if lib.mt_right_test(mark) ~= spos[3] then + error("invalid gravity for "..id..":("..mark.pos.row..", "..mark.pos.col..")") end if count > 0 then if not pos_leq(last, spos) then @@ -87,7 +87,21 @@ local function dosplice(tree, shadow, start, old_extent, new_extent) shadowsplice(shadow, start, old_extent, new_extent) end +local last_id = nil + +local function put(tree, row, col, gravitate) + last_id = last_id + 1 + local my_id = last_id + + lib.marktree_put_test(tree, my_id, row, col, gravitate); + return my_id +end + describe('marktree', function() + before_each(function() + last_id = 0 + end) + itp('works', function() local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit local shadow = {} @@ -97,7 +111,7 @@ describe('marktree', function() for i = 1,100 do for j = 1,100 do local gravitate = (i%2) > 0 - local id = tonumber(lib.marktree_put(tree, j, i, gravitate, 0)) + local id = put(tree, j, i, gravitate) ok(id > 0) eq(nil, shadow[id]) shadow[id] = {j,i,gravitate} @@ -115,12 +129,12 @@ describe('marktree', function() eq({}, id2pos) for i,ipos in pairs(shadow) do - local pos = lib.marktree_lookup(tree, i, iter) - eq(ipos[1], pos.row) - eq(ipos[2], pos.col) + local p = lib.marktree_lookup_ns(tree, -1, i, false, iter) + eq(ipos[1], p.pos.row) + eq(ipos[2], p.pos.col) local k = lib.marktree_itr_current(iter) - eq(ipos[1], k.row) - eq(ipos[2], k.col, ipos[1]) + eq(ipos[1], k.pos.row) + eq(ipos[2], k.pos.col, ipos[1]) lib.marktree_itr_next(tree, iter) -- TODO(bfredl): use id2pos to check neighbour? -- local k2 = lib.marktree_itr_current(iter) @@ -130,8 +144,8 @@ describe('marktree', function() lib.marktree_itr_get(tree, ipos[1], ipos[2], iter) local k = lib.marktree_itr_current(iter) eq(i, tonumber(k.id)) - eq(ipos[1], k.row) - eq(ipos[2], k.col) + eq(ipos[1], k.pos.row) + eq(ipos[2], k.pos.col) end ok(lib.marktree_itr_first(tree, iter)) @@ -146,8 +160,8 @@ describe('marktree', function() lib.marktree_itr_get(tree, i, 50+ci, iter) local k = lib.marktree_itr_current(iter) local id = tonumber(k.id) - eq(shadow[id][1], k.row) - eq(shadow[id][2], k.col) + eq(shadow[id][1], k.pos.row) + eq(shadow[id][2], k.pos.col) lib.marktree_del_itr(tree, iter, false) shadow[id] = nil end @@ -191,7 +205,7 @@ describe('marktree', function() -- https://github.com/neovim/neovim/pull/14719 lib.marktree_clear(tree) for i = 1,20 do - lib.marktree_put(tree, i, i, false, 0) + put(tree, i, i, false) end lib.marktree_itr_get(tree, 10, 10, iter) diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua index a0e02b6624..71177f4c65 100644 --- a/test/unit/os/env_spec.lua +++ b/test/unit/os/env_spec.lua @@ -154,7 +154,7 @@ describe('env.c', function() local value = 'TESTVALUE' os_setenv(name, value, 1) eq(OK, os_unsetenv(name)) - neq(os_getenv(name), value) + neq(value, os_getenv(name)) -- Depending on the platform the var might be unset or set as '' assert.True(os_getenv(name) == nil or os_getenv(name) == '') if os_getenv(name) == nil then @@ -266,7 +266,7 @@ describe('env.c', function() itp('does not crash #3725', function() local name_out = ffi.new('char[100]') - cimp.os_get_user_name(name_out, 100) + cimp.os_get_username(name_out, 100) local curuser = ffi.string(name_out) local src = to_cstr("~"..curuser.."/Vcs/django-rest-framework/rest_framework/renderers.py") diff --git a/test/unit/os/users_spec.lua b/test/unit/os/users_spec.lua index f92413c7de..679e76fae1 100644 --- a/test/unit/os/users_spec.lua +++ b/test/unit/os/users_spec.lua @@ -48,10 +48,10 @@ describe('users function', function() end) end) - describe('os_get_user_name', function() + describe('os_get_username', function() itp('should write the username into the buffer and return OK', function() local name_out = ffi.new('char[100]') - eq(OK, users.os_get_user_name(name_out, 100)) + eq(OK, users.os_get_username(name_out, 100)) eq(current_username, ffi.string(name_out)) end) end) @@ -73,18 +73,18 @@ describe('users function', function() end) end) - describe('os_get_user_directory', function() + describe('os_get_userdir', function() itp('should return NULL if called with NULL', function() - eq(NULL, users.os_get_user_directory(NULL)) + eq(NULL, users.os_get_userdir(NULL)) end) itp('should return $HOME for the current user', function() local home = os.getenv('HOME') - eq(home, ffi.string((users.os_get_user_directory(current_username)))) + eq(home, ffi.string((users.os_get_userdir(current_username)))) end) itp('should return NULL if the user is not found', function() - eq(NULL, users.os_get_user_directory('neovim_user_not_found_test')) + eq(NULL, users.os_get_userdir('neovim_user_not_found_test')) end) end) end) diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua index 15ce59747e..fb476397e6 100644 --- a/test/unit/path_spec.lua +++ b/test/unit/path_spec.lua @@ -626,4 +626,20 @@ describe('path.c', function() eq(false, path_with_extension('/some/path/file', 'lua')) end) end) + + describe('path_with_url', function() + itp('scheme is alpha and inner hyphen only', function() + local function path_with_url(fname) + return cimp.path_with_url(to_cstr(fname)) + end + eq(1, path_with_url([[test://xyz/foo/b0]])) + eq(2, path_with_url([[test:\\xyz\foo\b0]])) + eq(0, path_with_url([[test+abc://xyz/foo/b1]])) + eq(0, path_with_url([[test_abc://xyz/foo/b2]])) + eq(1, path_with_url([[test-abc://xyz/foo/b3]])) + eq(2, path_with_url([[test-abc:\\xyz\foo\b3]])) + eq(0, path_with_url([[-test://xyz/foo/b4]])) + eq(0, path_with_url([[test-://xyz/foo/b5]])) + end) + end) end) diff --git a/test/unit/search_spec.lua b/test/unit/search_spec.lua index 3c2d485e0e..ce37ebfc3a 100644 --- a/test/unit/search_spec.lua +++ b/test/unit/search_spec.lua @@ -5,6 +5,8 @@ local to_cstr = helpers.to_cstr local eq = helpers.eq local search = helpers.cimport("./src/nvim/search.h") +local globals = helpers.cimport('./src/nvim/globals.h') +local ffi = helpers.ffi itp('pat_has_uppercase', function() -- works on empty string @@ -31,3 +33,25 @@ itp('pat_has_uppercase', function() eq(false, search.pat_has_uppercase(to_cstr("aa\\%Ab"))) eq(true, search.pat_has_uppercase(to_cstr("aab\\%AU"))) end) + +describe('search_regcomp', function() + local search_regcomp = function(pat, pat_save, pat_use, options ) + local regmatch = ffi.new("regmmatch_T") + local fail = search.search_regcomp(to_cstr(pat), pat_save, pat_use, options, regmatch) + return fail, regmatch + end + + local get_search_pat = function() + return helpers.internalize(search.get_search_pat()) + end + + itp("accepts regexp pattern with invalid utf", function() + --crafted to call reverse_text with invalid utf + globals.curwin.w_onebuf_opt.wo_rl = 1 + globals.curwin.w_onebuf_opt.wo_rlc = to_cstr('s') + globals.cmdmod.cmod_flags = globals.CMOD_KEEPPATTERNS + local fail = search_regcomp("a\192", 0,0,0) + eq(1, fail) + eq("\192a", get_search_pat()) + end) +end) diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua index e54c82b26a..b2c839f25c 100644 --- a/test/unit/strings_spec.lua +++ b/test/unit/strings_spec.lua @@ -138,3 +138,50 @@ describe('vim_strchr()', function() eq(nil, vim_strchr('«\237\175\191\237\188\128»', 0x10FF00)) end) end) + +describe('strcase_save()' , function() + local strcase_save = function(input_string, upper) + local res = strings.strcase_save(to_cstr(input_string), upper) + return ffi.string(res) + end + + itp('decodes overlong encoded characters.', function() + eq("A", strcase_save("\xc1\x81", true)) + eq("a", strcase_save("\xc1\x81", false)) + end) +end) + +describe("reverse_text", function() + local reverse_text = function(str) + return helpers.internalize(strings.reverse_text(to_cstr(str))) + end + + itp("handles empty string", function() + eq("", reverse_text("")) + end) + + itp("handles simple cases", function() + eq("a", reverse_text("a")) + eq("ba", reverse_text("ab")) + end) + + itp("handles multibyte characters", function() + eq("bα", reverse_text("αb")) + eq("Yötön yö", reverse_text("öy nötöY")) + end) + + itp("handles combining chars", function() + local utf8_COMBINING_RING_ABOVE = "\204\138" + local utf8_COMBINING_RING_BELOW = "\204\165" + eq("bba" .. utf8_COMBINING_RING_ABOVE .. utf8_COMBINING_RING_BELOW .. "aa", + reverse_text("aaa" .. utf8_COMBINING_RING_ABOVE .. utf8_COMBINING_RING_BELOW .. "bb")) + end) + + itp("treats invalid utf as separate characters", function() + eq("\192ba", reverse_text("ab\192")) + end) + + itp("treats an incomplete utf continuation sequence as valid", function() + eq("\194ba", reverse_text("ab\194")) + end) +end) diff --git a/test/unit/tempfile_spec.lua b/test/unit/tempfile_spec.lua index c05abfd640..44bd19c1d2 100644 --- a/test/unit/tempfile_spec.lua +++ b/test/unit/tempfile_spec.lua @@ -24,7 +24,7 @@ describe('tempfile related functions', function() end describe('vim_gettempdir', function() - itp('returns path to Neovim own temp directory', function() + itp('returns path to Nvim own temp directory', function() local dir = vim_gettempdir() assert.True(dir ~= nil and dir:len() > 0) -- os_file_is_writable returns 2 for a directory which we have rights @@ -36,9 +36,7 @@ describe('tempfile related functions', function() end) itp('returns the same directory on each call', function() - local dir1 = vim_gettempdir() - local dir2 = vim_gettempdir() - eq(dir1, dir2) + eq(vim_gettempdir(), vim_gettempdir()) end) end) @@ -54,12 +52,10 @@ describe('tempfile related functions', function() end) itp('generate different names on each call', function() - local fst = vim_tempname() - local snd = vim_tempname() - neq(fst, snd) + neq(vim_tempname(), vim_tempname()) end) - itp('generate file name in Neovim own temp directory', function() + itp('generate file name in Nvim own temp directory', function() local dir = vim_gettempdir() local file = vim_tempname() eq(string.sub(file, 1, string.len(dir)), dir) diff --git a/test/unit/viml/expressions/parser_spec.lua b/test/unit/viml/expressions/parser_spec.lua index 8342044b5e..51a703b593 100644 --- a/test/unit/viml/expressions/parser_spec.lua +++ b/test/unit/viml/expressions/parser_spec.lua @@ -48,6 +48,7 @@ local predefined_hl_defs = { TermCursor=true, VertSplit=true, WildMenu=true, + WinSeparator=true, EndOfBuffer=true, QuickFixLine=true, Substitute=true, |