aboutsummaryrefslogtreecommitdiff
path: root/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'test/unit')
-rw-r--r--test/unit/api/helpers.lua99
-rw-r--r--test/unit/api/private_helpers_spec.lua80
-rw-r--r--test/unit/buffer_spec.lua46
-rw-r--r--test/unit/charset/vim_str2nr_spec.lua584
-rw-r--r--test/unit/eval/decode_spec.lua41
-rw-r--r--test/unit/eval/encode_spec.lua39
-rw-r--r--test/unit/eval/helpers.lua285
-rw-r--r--test/unit/eval/tricks_spec.lua3
-rw-r--r--test/unit/eval/tv_clear_spec.lua14
-rw-r--r--test/unit/eval/typval_spec.lua1549
-rw-r--r--test/unit/fileio_spec.lua25
-rw-r--r--test/unit/fixtures/multiqueue.c2
-rw-r--r--test/unit/formatc.lua201
-rw-r--r--test/unit/garray_spec.lua57
-rw-r--r--test/unit/helpers.lua180
-rw-r--r--test/unit/indent_spec.lua38
-rw-r--r--test/unit/keycodes_spec.lua28
-rw-r--r--test/unit/marktree_spec.lua358
-rw-r--r--test/unit/mbyte_spec.lua205
-rw-r--r--test/unit/memory_spec.lua30
-rw-r--r--test/unit/message_spec.lua9
-rw-r--r--test/unit/msgpack_spec.lua40
-rw-r--r--test/unit/multiqueue_spec.lua6
-rw-r--r--test/unit/optionstr_spec.lua17
-rw-r--r--test/unit/os/env_spec.lua19
-rw-r--r--test/unit/os/fileio_spec.lua155
-rw-r--r--test/unit/os/fs_spec.lua285
-rw-r--r--test/unit/os/shell_spec.lua50
-rw-r--r--test/unit/path_spec.lua125
-rw-r--r--test/unit/preprocess.lua101
-rw-r--r--test/unit/profile_spec.lua92
-rw-r--r--test/unit/rbuffer_spec.lua54
-rw-r--r--test/unit/search_spec.lua40
-rw-r--r--test/unit/set.lua6
-rw-r--r--test/unit/statusline_spec.lua555
-rw-r--r--test/unit/strings_spec.lua89
-rw-r--r--test/unit/undo_spec.lua77
-rw-r--r--test/unit/viml/expressions/lexer_spec.lua603
-rw-r--r--test/unit/viml/expressions/parser_spec.lua384
-rw-r--r--test/unit/viml/expressions/parser_tests.lua239
-rw-r--r--test/unit/viml/helpers.lua59
41 files changed, 4067 insertions, 2802 deletions
diff --git a/test/unit/api/helpers.lua b/test/unit/api/helpers.lua
index 3d306d2b1b..23c5db43f7 100644
--- a/test/unit/api/helpers.lua
+++ b/test/unit/api/helpers.lua
@@ -13,9 +13,11 @@ local int_type = eval_helpers.int_type
local flt_type = eval_helpers.flt_type
local type_key = eval_helpers.type_key
-local api = cimport('./src/nvim/api/private/defs.h',
- './src/nvim/api/private/helpers.h',
- './src/nvim/memory.h')
+local api = cimport(
+ './src/nvim/api/private/defs.h',
+ './src/nvim/api/private/helpers.h',
+ './src/nvim/memory.h'
+)
local obj2lua
@@ -27,8 +29,8 @@ local function init_obj2lua_tab()
end
obj2lua_tab = {
[tonumber(api.kObjectTypeArray)] = function(obj)
- local ret = {[type_key]=list_type}
- for i = 1,tonumber(obj.data.array.size) do
+ local ret = { [type_key] = list_type }
+ for i = 1, tonumber(obj.data.array.size) do
ret[i] = obj2lua(obj.data.array.items[i - 1])
end
if ret[1] then
@@ -38,7 +40,7 @@ local function init_obj2lua_tab()
end,
[tonumber(api.kObjectTypeDictionary)] = function(obj)
local ret = {}
- for i = 1,tonumber(obj.data.dictionary.size) do
+ for i = 1, tonumber(obj.data.dictionary.size) do
local kv_pair = obj.data.dictionary.items[i - 1]
ret[ffi.string(kv_pair.key.data, kv_pair.key.size)] = obj2lua(kv_pair.value)
end
@@ -58,7 +60,7 @@ local function init_obj2lua_tab()
return tonumber(obj.data.floating)
end,
[tonumber(api.kObjectTypeInteger)] = function(obj)
- return {[type_key]=int_type, value=tonumber(obj.data.integer)}
+ return { [type_key] = int_type, value = tonumber(obj.data.integer) }
end,
[tonumber(api.kObjectTypeString)] = function(obj)
return ffi.string(obj.data.string.data, obj.data.string.size)
@@ -68,32 +70,38 @@ end
obj2lua = function(obj)
init_obj2lua_tab()
- return ((obj2lua_tab[tonumber(obj['type'])] or function(obj_inner)
- assert(false, 'Converting ' .. tostring(tonumber(obj_inner['type'])) .. ' is not implementing yet')
- end)(obj))
+ return (
+ (obj2lua_tab[tonumber(obj['type'])] or function(obj_inner)
+ assert(
+ false,
+ 'Converting ' .. tostring(tonumber(obj_inner['type'])) .. ' is not implementing yet'
+ )
+ end)(obj)
+ )
end
local obj = function(typ, data)
- return ffi.gc(ffi.new('Object', {['type']=typ, data=data}),
- api.api_free_object)
+ return ffi.gc(ffi.new('Object', { ['type'] = typ, data = data }), api.api_free_object)
end
local lua2obj
local lua2obj_type_tab = {
[int_type] = function(l)
- return obj(api.kObjectTypeInteger, {integer=l.value})
+ return obj(api.kObjectTypeInteger, { integer = l.value })
end,
[flt_type] = function(l)
- return obj(api.kObjectTypeFloat, {floating=l})
+ return obj(api.kObjectTypeFloat, { floating = l })
end,
[list_type] = function(l)
local len = #l
- local arr = obj(api.kObjectTypeArray, {array={
- size=len,
- capacity=len,
- items=ffi.cast('Object *', api.xmalloc(len * ffi.sizeof('Object'))),
- }})
+ local arr = obj(api.kObjectTypeArray, {
+ array = {
+ size = len,
+ capacity = len,
+ items = ffi.cast('Object *', api.xmalloc(len * ffi.sizeof('Object'))),
+ },
+ })
for i = 1, len do
arr.data.array.items[i - 1] = ffi.gc(lua2obj(l[i]), nil)
end
@@ -103,21 +111,23 @@ local lua2obj_type_tab = {
local kvs = {}
for k, v in pairs(l) do
if type(k) == 'string' then
- kvs[#kvs + 1] = {k, v}
+ kvs[#kvs + 1] = { k, v }
end
end
local len = #kvs
- local dct = obj(api.kObjectTypeDictionary, {dictionary={
- size=len,
- capacity=len,
- items=ffi.cast('KeyValuePair *',
- api.xmalloc(len * ffi.sizeof('KeyValuePair'))),
- }})
+ local dct = obj(api.kObjectTypeDictionary, {
+ dictionary = {
+ size = len,
+ capacity = len,
+ items = ffi.cast('KeyValuePair *', api.xmalloc(len * ffi.sizeof('KeyValuePair'))),
+ },
+ })
for i = 1, len do
local key, val = unpack(kvs[i])
dct.data.dictionary.items[i - 1] = ffi.new(
- 'KeyValuePair', {key=ffi.gc(lua2obj(key), nil).data.string,
- value=ffi.gc(lua2obj(val), nil)})
+ 'KeyValuePair',
+ { key = ffi.gc(lua2obj(key), nil).data.string, value = ffi.gc(lua2obj(val), nil) }
+ )
end
return dct
end,
@@ -137,28 +147,31 @@ lua2obj = function(l)
elseif type(l) == 'number' then
return lua2obj_type_tab[flt_type](l)
elseif type(l) == 'boolean' then
- return obj(api.kObjectTypeBoolean, {boolean=l})
+ return obj(api.kObjectTypeBoolean, { boolean = l })
elseif type(l) == 'string' then
- return obj(api.kObjectTypeString, {string={
- size=#l,
- data=api.xmemdupz(to_cstr(l), #l),
- }})
+ return obj(
+ api.kObjectTypeString,
+ { string = {
+ size = #l,
+ data = api.xmemdupz(to_cstr(l), #l),
+ } }
+ )
elseif l == nil or l == nil_value then
- return obj(api.kObjectTypeNil, {integer=0})
+ return obj(api.kObjectTypeNil, { integer = 0 })
end
end
return {
- list_type=list_type,
- dict_type=dict_type,
- func_type=func_type,
- int_type=int_type,
- flt_type=flt_type,
+ list_type = list_type,
+ dict_type = dict_type,
+ func_type = func_type,
+ int_type = int_type,
+ flt_type = flt_type,
- nil_value=nil_value,
+ nil_value = nil_value,
- type_key=type_key,
+ type_key = type_key,
- obj2lua=obj2lua,
- lua2obj=lua2obj,
+ obj2lua = obj2lua,
+ lua2obj = lua2obj,
}
diff --git a/test/unit/api/private_helpers_spec.lua b/test/unit/api/private_helpers_spec.lua
index dbb4b3ae5a..9843bd5c9e 100644
--- a/test/unit/api/private_helpers_spec.lua
+++ b/test/unit/api/private_helpers_spec.lua
@@ -22,7 +22,7 @@ local api = cimport('./src/nvim/api/private/helpers.h', './src/nvim/api/private/
describe('vim_to_object', function()
local vim_to_object = function(l)
- return obj2lua(api.vim_to_object(lua2typvalt(l)))
+ return obj2lua(api.vim_to_object(lua2typvalt(l), nil, false))
end
local different_output_test = function(name, input, output)
@@ -42,65 +42,77 @@ describe('vim_to_object', function()
simple_test('converts -1.5', -1.5)
simple_test('converts empty string', '')
simple_test('converts non-empty string', 'foobar')
- simple_test('converts integer 10', {[type_key]=int_type, value=10})
+ simple_test('converts integer 10', { [type_key] = int_type, value = 10 })
simple_test('converts empty dictionary', {})
- simple_test('converts dictionary with scalar values', {test=10, test2=true, test3='test'})
- simple_test('converts dictionary with containers inside', {test={}, test2={1, 2}})
- simple_test('converts empty list', {[type_key]=list_type})
- simple_test('converts list with scalar values', {1, 2, 'test', 'foo'})
- simple_test('converts list with containers inside', {{}, {test={}, test3={test4=true}}})
+ simple_test('converts dictionary with scalar values', { test = 10, test2 = true, test3 = 'test' })
+ simple_test('converts dictionary with containers inside', { test = {}, test2 = { 1, 2 } })
+ simple_test('converts empty list', { [type_key] = list_type })
+ simple_test('converts list with scalar values', { 1, 2, 'test', 'foo' })
+ simple_test(
+ 'converts list with containers inside',
+ { {}, { test = {}, test3 = { test4 = true } } }
+ )
local dct = {}
dct.dct = dct
- different_output_test('outputs nil for nested dictionaries (1 level)', dct, {dct=nil_value})
+ different_output_test('outputs nil for nested dictionaries (1 level)', dct, { dct = nil_value })
local lst = {}
lst[1] = lst
- different_output_test('outputs nil for nested lists (1 level)', lst, {nil_value})
-
- local dct2 = {test=true, dict=nil_value}
- dct2.dct = {dct2}
- different_output_test('outputs nil for nested dictionaries (2 level, in list)',
- dct2, {dct={nil_value}, test=true, dict=nil_value})
-
- local dct3 = {test=true, dict=nil_value}
- dct3.dct = {dctin=dct3}
- different_output_test('outputs nil for nested dictionaries (2 level, in dict)',
- dct3, {dct={dctin=nil_value}, test=true, dict=nil_value})
+ different_output_test('outputs nil for nested lists (1 level)', lst, { nil_value })
+
+ local dct2 = { test = true, dict = nil_value }
+ dct2.dct = { dct2 }
+ different_output_test(
+ 'outputs nil for nested dictionaries (2 level, in list)',
+ dct2,
+ { dct = { nil_value }, test = true, dict = nil_value }
+ )
+
+ local dct3 = { test = true, dict = nil_value }
+ dct3.dct = { dctin = dct3 }
+ different_output_test(
+ 'outputs nil for nested dictionaries (2 level, in dict)',
+ dct3,
+ { dct = { dctin = nil_value }, test = true, dict = nil_value }
+ )
local lst2 = {}
- lst2[1] = {lst2}
- different_output_test('outputs nil for nested lists (2 level, in list)', lst2, {{nil_value}})
+ lst2[1] = { lst2 }
+ different_output_test('outputs nil for nested lists (2 level, in list)', lst2, { { nil_value } })
- local lst3 = {nil, true, false, 'ttest'}
- lst3[1] = {lst=lst3}
- different_output_test('outputs nil for nested lists (2 level, in dict)',
- lst3, {{lst=nil_value}, true, false, 'ttest'})
+ local lst3 = { nil, true, false, 'ttest' }
+ lst3[1] = { lst = lst3 }
+ different_output_test(
+ 'outputs nil for nested lists (2 level, in dict)',
+ lst3,
+ { { lst = nil_value }, true, false, 'ttest' }
+ )
itp('outputs empty list for NULL list', function()
- local tt = typvalt('VAR_LIST', {v_list=NULL})
+ local tt = typvalt('VAR_LIST', { v_list = NULL })
eq(nil, tt.vval.v_list)
- eq({[type_key]=list_type}, obj2lua(api.vim_to_object(tt)))
+ eq({ [type_key] = list_type }, obj2lua(api.vim_to_object(tt, nil, false)))
end)
itp('outputs empty dict for NULL dict', function()
- local tt = typvalt('VAR_DICT', {v_dict=NULL})
+ local tt = typvalt('VAR_DICT', { v_dict = NULL })
eq(nil, tt.vval.v_dict)
- eq({}, obj2lua(api.vim_to_object(tt)))
+ eq({}, obj2lua(api.vim_to_object(tt, nil, false)))
end)
itp('regression: partials in a list', function()
local llist = {
{
- [type_key]=func_type,
- value='printf',
- args={'%s'},
- dict={v=1},
+ [type_key] = func_type,
+ value = 'printf',
+ args = { '%s' },
+ dict = { v = 1 },
},
{},
}
local list = lua2typvalt(llist)
eq(llist, typvalt2lua(list))
- eq({nil_value, {}}, obj2lua(api.vim_to_object(list)))
+ eq({ nil_value, {} }, obj2lua(api.vim_to_object(list, nil, false)))
end)
end)
diff --git a/test/unit/buffer_spec.lua b/test/unit/buffer_spec.lua
index 6e08a09295..1ef3e97165 100644
--- a/test/unit/buffer_spec.lua
+++ b/test/unit/buffer_spec.lua
@@ -1,14 +1,13 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local to_cstr = helpers.to_cstr
-local eq = helpers.eq
-local NULL = helpers.NULL
+local eq = helpers.eq
+local NULL = helpers.NULL
-local buffer = helpers.cimport("./src/nvim/buffer.h")
+local buffer = helpers.cimport('./src/nvim/buffer.h')
describe('buffer functions', function()
-
local buflist_new = function(file, flags)
local c_file = to_cstr(file)
return buffer.buflist_new(c_file, c_file, 1, flags)
@@ -36,7 +35,6 @@ describe('buffer functions', function()
end)
describe('buf_valid', function()
-
itp('should view NULL as an invalid buffer', function()
eq(false, buffer.buf_valid(NULL))
end)
@@ -72,11 +70,9 @@ describe('buffer functions', function()
end)
end)
-
describe('buflist_findpat', function()
-
local ALLOW_UNLISTED = 1
- local ONLY_LISTED = 0
+ local ONLY_LISTED = 0
local buflist_findpat = function(pat, allow_unlisted)
return buffer.buflist_findpat(to_cstr(pat), NULL, allow_unlisted, 0, 0)
@@ -95,9 +91,9 @@ describe('buffer functions', function()
local buf2 = buflist_new(path2, buffer.BLN_LISTED)
local buf3 = buflist_new(path3, buffer.BLN_LISTED)
- eq(buf1.handle, buflist_findpat("test", ONLY_LISTED))
- eq(buf2.handle, buflist_findpat("file", ONLY_LISTED))
- eq(buf3.handle, buflist_findpat("path", ONLY_LISTED))
+ eq(buf1.handle, buflist_findpat('test', ONLY_LISTED))
+ eq(buf2.handle, buflist_findpat('file', ONLY_LISTED))
+ eq(buf3.handle, buflist_findpat('path', ONLY_LISTED))
close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0, 0)
close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0, 0)
@@ -111,7 +107,7 @@ describe('buffer functions', function()
local buf3 = buflist_new(path3, buffer.BLN_LISTED)
-- Then: buf2 is the buffer that is found
- eq(buf2.handle, buflist_findpat("test", ONLY_LISTED))
+ eq(buf2.handle, buflist_findpat('test', ONLY_LISTED))
--}
--{ When: We close buf2
@@ -121,7 +117,7 @@ describe('buffer functions', function()
local buf1 = buflist_new(path1, buffer.BLN_LISTED)
-- Then: buf3 is found since 'file' appears at the end of the name
- eq(buf3.handle, buflist_findpat("file", ONLY_LISTED))
+ eq(buf3.handle, buflist_findpat('file', ONLY_LISTED))
--}
close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0, 0)
@@ -133,7 +129,7 @@ describe('buffer functions', function()
local buf2 = buflist_new(path2, buffer.BLN_LISTED)
local buf3 = buflist_new(path3, buffer.BLN_LISTED)
- eq(buf3.handle, buflist_findpat("_test_", ONLY_LISTED))
+ eq(buf3.handle, buflist_findpat('_test_', ONLY_LISTED))
close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0, 0)
close_buffer(NULL, buf2, buffer.DOBUF_WIPE, 0, 0)
@@ -145,25 +141,25 @@ describe('buffer functions', function()
local buf3 = buflist_new(path3, buffer.BLN_LISTED)
-- Then: We should find the buffer when it is given a unique pattern
- eq(buf3.handle, buflist_findpat("_test_", ONLY_LISTED))
+ eq(buf3.handle, buflist_findpat('_test_', ONLY_LISTED))
--}
--{ When: We unlist the buffer
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))
+ eq(-1, buflist_findpat('_test_', ONLY_LISTED))
-- And: It should find the buffer when including unlisted buffers
- eq(buf3.handle, buflist_findpat("_test_", ALLOW_UNLISTED))
+ eq(buf3.handle, buflist_findpat('_test_', ALLOW_UNLISTED))
--}
--{ When: We wipe the buffer
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))
- eq(-1, buflist_findpat("_test_", ALLOW_UNLISTED))
+ eq(-1, buflist_findpat('_test_', ONLY_LISTED))
+ eq(-1, buflist_findpat('_test_', ALLOW_UNLISTED))
--}
end)
@@ -173,7 +169,7 @@ describe('buffer functions', function()
local buf2 = buflist_new(path2, buffer.BLN_LISTED)
-- Then: The first buffer is preferred when both are listed
- eq(buf1.handle, buflist_findpat("test", ONLY_LISTED))
+ eq(buf1.handle, buflist_findpat('test', ONLY_LISTED))
--}
--{ When: The first buffer is unlisted
@@ -181,13 +177,13 @@ describe('buffer functions', function()
-- Then: The second buffer is preferred because
-- unlisted buffers are not allowed
- eq(buf2.handle, buflist_findpat("test", ONLY_LISTED))
+ eq(buf2.handle, buflist_findpat('test', ONLY_LISTED))
--}
--{ When: We allow unlisted buffers
-- Then: The second buffer is still preferred
-- because listed buffers are preferred to unlisted
- eq(buf2.handle, buflist_findpat("test", ALLOW_UNLISTED))
+ eq(buf2.handle, buflist_findpat('test', ALLOW_UNLISTED))
--}
--{ When: We unlist the second buffer
@@ -196,10 +192,10 @@ describe('buffer functions', function()
-- Then: The first buffer is preferred again
-- because buf1 matches better which takes precedence
-- when both buffers have the same listing status.
- eq(buf1.handle, buflist_findpat("test", ALLOW_UNLISTED))
+ eq(buf1.handle, buflist_findpat('test', ALLOW_UNLISTED))
-- And: Neither buffer is returned when ignoring unlisted
- eq(-1, buflist_findpat("test", ONLY_LISTED))
+ eq(-1, buflist_findpat('test', ONLY_LISTED))
--}
close_buffer(NULL, buf1, buffer.DOBUF_WIPE, 0, 0)
diff --git a/test/unit/charset/vim_str2nr_spec.lua b/test/unit/charset/vim_str2nr_spec.lua
index fc40fa39d4..ad87d026e5 100644
--- a/test/unit/charset/vim_str2nr_spec.lua
+++ b/test/unit/charset/vim_str2nr_spec.lua
@@ -1,4 +1,4 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local bit = require('bit')
local itp = helpers.gen_itp(it)
@@ -26,10 +26,10 @@ local ucnt = 4242
local function arginit(arg)
if arg == 'unum' then
ucnt = ucnt + 1
- return ARGTYPES[arg]({ucnt})
+ return ARGTYPES[arg]({ ucnt })
else
icnt = icnt - 1
- return ARGTYPES[arg]({icnt})
+ return ARGTYPES[arg]({ icnt })
end
end
@@ -44,7 +44,9 @@ local function argreset(arg, args)
end
local function test_vim_str2nr(s, what, exp, maxlen, strict)
- if strict == nil then strict = true end
+ if strict == nil then
+ strict = true
+ end
local bits = {}
for k, _ in pairs(exp) do
bits[#bits + 1] = k
@@ -54,7 +56,7 @@ local function test_vim_str2nr(s, what, exp, maxlen, strict)
for k, _ in pairs(ARGTYPES) do
args[k] = arginit(k)
end
- for case = 0, ((2 ^ (#bits)) - 1) do
+ for case = 0, ((2 ^ #bits) - 1) do
local cv = {}
for b = 0, (#bits - 1) do
if bit.band(case, (2 ^ b)) == 0 then
@@ -66,9 +68,17 @@ local function test_vim_str2nr(s, what, exp, 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(
- cck, exp[cck], s, tonumber(what), maxlen, tostring(strict), tonumber(ccv[0])
- ))
+ error(
+ ('Failed check (%s = %d) in test (s=%s, w=%u, m=%d, strict=%s): %d'):format(
+ cck,
+ exp[cck],
+ s,
+ tonumber(what),
+ maxlen,
+ tostring(strict),
+ tonumber(ccv[0])
+ )
+ )
end
end
end
@@ -82,18 +92,48 @@ end
describe('vim_str2nr()', function()
itp('works fine when it has nothing to do', function()
- test_vim_str2nr('', 0, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_ALL, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_BIN, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_OCT, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_OOCT, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_HEX, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_FORCE + lib.STR2NR_DEC, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_FORCE + lib.STR2NR_BIN, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_FORCE + lib.STR2NR_OCT, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_FORCE + lib.STR2NR_OOCT, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_FORCE + lib.STR2NR_OCT + lib.STR2NR_OOCT, {len = 0, num = 0, unum = 0, pre = 0}, 0)
- test_vim_str2nr('', lib.STR2NR_FORCE + lib.STR2NR_HEX, {len = 0, num = 0, unum = 0, pre = 0}, 0)
+ test_vim_str2nr('', 0, { len = 0, num = 0, unum = 0, pre = 0 }, 0)
+ test_vim_str2nr('', lib.STR2NR_ALL, { len = 0, num = 0, unum = 0, pre = 0 }, 0)
+ test_vim_str2nr('', lib.STR2NR_BIN, { len = 0, num = 0, unum = 0, pre = 0 }, 0)
+ test_vim_str2nr('', lib.STR2NR_OCT, { len = 0, num = 0, unum = 0, pre = 0 }, 0)
+ test_vim_str2nr('', lib.STR2NR_OOCT, { len = 0, num = 0, unum = 0, pre = 0 }, 0)
+ test_vim_str2nr('', lib.STR2NR_HEX, { len = 0, num = 0, unum = 0, pre = 0 }, 0)
+ test_vim_str2nr(
+ '',
+ lib.STR2NR_FORCE + lib.STR2NR_DEC,
+ { len = 0, num = 0, unum = 0, pre = 0 },
+ 0
+ )
+ test_vim_str2nr(
+ '',
+ lib.STR2NR_FORCE + lib.STR2NR_BIN,
+ { len = 0, num = 0, unum = 0, pre = 0 },
+ 0
+ )
+ test_vim_str2nr(
+ '',
+ lib.STR2NR_FORCE + lib.STR2NR_OCT,
+ { len = 0, num = 0, unum = 0, pre = 0 },
+ 0
+ )
+ test_vim_str2nr(
+ '',
+ lib.STR2NR_FORCE + lib.STR2NR_OOCT,
+ { len = 0, num = 0, unum = 0, pre = 0 },
+ 0
+ )
+ test_vim_str2nr(
+ '',
+ lib.STR2NR_FORCE + lib.STR2NR_OCT + lib.STR2NR_OOCT,
+ { len = 0, num = 0, unum = 0, pre = 0 },
+ 0
+ )
+ test_vim_str2nr(
+ '',
+ lib.STR2NR_FORCE + lib.STR2NR_HEX,
+ { len = 0, num = 0, unum = 0, pre = 0 },
+ 0
+ )
end)
itp('works with decimal numbers', function()
for _, flags in ipairs({
@@ -110,30 +150,30 @@ describe('vim_str2nr()', function()
lib.STR2NR_FORCE + lib.STR2NR_DEC,
}) do
-- Check that all digits are recognized
- test_vim_str2nr( '12345', flags, {len = 5, num = 12345, unum = 12345, pre = 0}, 0)
- test_vim_str2nr( '67890', flags, {len = 5, num = 67890, unum = 67890, pre = 0}, 0)
- test_vim_str2nr( '12345A', flags, {len = 0}, 0)
- test_vim_str2nr( '67890A', flags, {len = 0}, 0)
- test_vim_str2nr( '12345A', flags, {len = 5, num = 12345, unum = 12345, pre = 0}, 0, false)
- test_vim_str2nr( '67890A', flags, {len = 5, num = 67890, unum = 67890, pre = 0}, 0, false)
-
- test_vim_str2nr( '42', flags, {len = 2, num = 42, unum = 42, pre = 0}, 0)
- test_vim_str2nr( '42', flags, {len = 1, num = 4, unum = 4, pre = 0}, 1)
- test_vim_str2nr( '42', flags, {len = 2, num = 42, unum = 42, pre = 0}, 2)
- test_vim_str2nr( '42', flags, {len = 2, num = 42, unum = 42, pre = 0}, 3) -- includes NUL byte in maxlen
-
- test_vim_str2nr( '42x', flags, {len = 0}, 0)
- test_vim_str2nr( '42x', flags, {len = 0}, 3)
- test_vim_str2nr( '42x', flags, {len = 2, num = 42, unum = 42, pre = 0}, 0, false)
- test_vim_str2nr( '42x', flags, {len = 2, num = 42, unum = 42, pre = 0}, 3, false)
-
- test_vim_str2nr('-42', flags, {len = 3, num = -42, unum = 42, pre = 0}, 3)
- test_vim_str2nr('-42', flags, {len = 1, num = 0, unum = 0, pre = 0}, 1)
-
- test_vim_str2nr('-42x', flags, {len = 0}, 0)
- test_vim_str2nr('-42x', flags, {len = 0}, 4)
- test_vim_str2nr('-42x', flags, {len = 3, num = -42, unum = 42, pre = 0}, 0, false)
- test_vim_str2nr('-42x', flags, {len = 3, num = -42, unum = 42, pre = 0}, 4, false)
+ test_vim_str2nr('12345', flags, { len = 5, num = 12345, unum = 12345, pre = 0 }, 0)
+ test_vim_str2nr('67890', flags, { len = 5, num = 67890, unum = 67890, pre = 0 }, 0)
+ test_vim_str2nr('12345A', flags, { len = 0 }, 0)
+ test_vim_str2nr('67890A', flags, { len = 0 }, 0)
+ test_vim_str2nr('12345A', flags, { len = 5, num = 12345, unum = 12345, pre = 0 }, 0, false)
+ test_vim_str2nr('67890A', flags, { len = 5, num = 67890, unum = 67890, pre = 0 }, 0, false)
+
+ test_vim_str2nr('42', flags, { len = 2, num = 42, unum = 42, pre = 0 }, 0)
+ test_vim_str2nr('42', flags, { len = 1, num = 4, unum = 4, pre = 0 }, 1)
+ test_vim_str2nr('42', flags, { len = 2, num = 42, unum = 42, pre = 0 }, 2)
+ test_vim_str2nr('42', flags, { len = 2, num = 42, unum = 42, pre = 0 }, 3) -- includes NUL byte in maxlen
+
+ test_vim_str2nr('42x', flags, { len = 0 }, 0)
+ test_vim_str2nr('42x', flags, { len = 0 }, 3)
+ test_vim_str2nr('42x', flags, { len = 2, num = 42, unum = 42, pre = 0 }, 0, false)
+ test_vim_str2nr('42x', flags, { len = 2, num = 42, unum = 42, pre = 0 }, 3, false)
+
+ test_vim_str2nr('-42', flags, { len = 3, num = -42, unum = 42, pre = 0 }, 3)
+ test_vim_str2nr('-42', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+
+ test_vim_str2nr('-42x', flags, { len = 0 }, 0)
+ test_vim_str2nr('-42x', flags, { len = 0 }, 4)
+ test_vim_str2nr('-42x', flags, { len = 3, num = -42, unum = 42, pre = 0 }, 0, false)
+ test_vim_str2nr('-42x', flags, { len = 3, num = -42, unum = 42, pre = 0 }, 4, false)
end
end)
itp('works with binary numbers', function()
@@ -154,66 +194,66 @@ describe('vim_str2nr()', function()
BIN = ('B'):byte()
end
- test_vim_str2nr( '0b101', flags, {len = 5, num = 5, unum = 5, pre = bin}, 0)
- test_vim_str2nr( '0b101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr( '0b101', flags, {len = 0}, 2)
- test_vim_str2nr( '0b101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 2, false)
- test_vim_str2nr( '0b101', flags, {len = 3, num = 1, unum = 1, pre = bin}, 3)
- test_vim_str2nr( '0b101', flags, {len = 4, num = 2, unum = 2, pre = bin}, 4)
- test_vim_str2nr( '0b101', flags, {len = 5, num = 5, unum = 5, pre = bin}, 5)
- test_vim_str2nr( '0b101', flags, {len = 5, num = 5, unum = 5, pre = bin}, 6)
-
- test_vim_str2nr( '0b1012', flags, {len = 0}, 0)
- test_vim_str2nr( '0b1012', flags, {len = 0}, 6)
- test_vim_str2nr( '0b1012', flags, {len = 5, num = 5, unum = 5, pre = bin}, 0, false)
- test_vim_str2nr( '0b1012', flags, {len = 5, num = 5, unum = 5, pre = bin}, 6, false)
-
- test_vim_str2nr('-0b101', flags, {len = 6, num = -5, unum = 5, pre = bin}, 0)
- test_vim_str2nr('-0b101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr('-0b101', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 2)
- test_vim_str2nr('-0b101', flags, {len = 0}, 3)
- test_vim_str2nr('-0b101', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 3, false)
- test_vim_str2nr('-0b101', flags, {len = 4, num = -1, unum = 1, pre = bin}, 4)
- test_vim_str2nr('-0b101', flags, {len = 5, num = -2, unum = 2, pre = bin}, 5)
- test_vim_str2nr('-0b101', flags, {len = 6, num = -5, unum = 5, pre = bin}, 6)
- test_vim_str2nr('-0b101', flags, {len = 6, num = -5, unum = 5, pre = bin}, 7)
-
- test_vim_str2nr('-0b1012', flags, {len = 0}, 0)
- test_vim_str2nr('-0b1012', flags, {len = 0}, 7)
- test_vim_str2nr('-0b1012', flags, {len = 6, num = -5, unum = 5, pre = bin}, 0, false)
- test_vim_str2nr('-0b1012', flags, {len = 6, num = -5, unum = 5, pre = bin}, 7, false)
-
- test_vim_str2nr( '0B101', flags, {len = 5, num = 5, unum = 5, pre = BIN}, 0)
- test_vim_str2nr( '0B101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr( '0B101', flags, {len = 0}, 2)
- test_vim_str2nr( '0B101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 2, false)
- test_vim_str2nr( '0B101', flags, {len = 3, num = 1, unum = 1, pre = BIN}, 3)
- test_vim_str2nr( '0B101', flags, {len = 4, num = 2, unum = 2, pre = BIN}, 4)
- test_vim_str2nr( '0B101', flags, {len = 5, num = 5, unum = 5, pre = BIN}, 5)
- test_vim_str2nr( '0B101', flags, {len = 5, num = 5, unum = 5, pre = BIN}, 6)
-
- test_vim_str2nr( '0B1012', flags, {len = 0}, 0)
- test_vim_str2nr( '0B1012', flags, {len = 0}, 6)
- test_vim_str2nr( '0B1012', flags, {len = 5, num = 5, unum = 5, pre = BIN}, 0, false)
- test_vim_str2nr( '0B1012', flags, {len = 5, num = 5, unum = 5, pre = BIN}, 6, false)
-
- test_vim_str2nr('-0B101', flags, {len = 6, num = -5, unum = 5, pre = BIN}, 0)
- test_vim_str2nr('-0B101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr('-0B101', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 2)
- test_vim_str2nr('-0B101', flags, {len = 0}, 3)
- test_vim_str2nr('-0B101', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 3, false)
- test_vim_str2nr('-0B101', flags, {len = 4, num = -1, unum = 1, pre = BIN}, 4)
- test_vim_str2nr('-0B101', flags, {len = 5, num = -2, unum = 2, pre = BIN}, 5)
- test_vim_str2nr('-0B101', flags, {len = 6, num = -5, unum = 5, pre = BIN}, 6)
- test_vim_str2nr('-0B101', flags, {len = 6, num = -5, unum = 5, pre = BIN}, 7)
-
- test_vim_str2nr('-0B1012', flags, {len = 0}, 0)
- test_vim_str2nr('-0B1012', flags, {len = 0}, 7)
- test_vim_str2nr('-0B1012', flags, {len = 6, num = -5, unum = 5, pre = BIN}, 0, false)
- test_vim_str2nr('-0B1012', flags, {len = 6, num = -5, unum = 5, pre = BIN}, 7, false)
+ test_vim_str2nr('0b101', flags, { len = 5, num = 5, unum = 5, pre = bin }, 0)
+ test_vim_str2nr('0b101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('0b101', flags, { len = 0 }, 2)
+ test_vim_str2nr('0b101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 2, false)
+ test_vim_str2nr('0b101', flags, { len = 3, num = 1, unum = 1, pre = bin }, 3)
+ test_vim_str2nr('0b101', flags, { len = 4, num = 2, unum = 2, pre = bin }, 4)
+ test_vim_str2nr('0b101', flags, { len = 5, num = 5, unum = 5, pre = bin }, 5)
+ test_vim_str2nr('0b101', flags, { len = 5, num = 5, unum = 5, pre = bin }, 6)
+
+ test_vim_str2nr('0b1012', flags, { len = 0 }, 0)
+ test_vim_str2nr('0b1012', flags, { len = 0 }, 6)
+ test_vim_str2nr('0b1012', flags, { len = 5, num = 5, unum = 5, pre = bin }, 0, false)
+ test_vim_str2nr('0b1012', flags, { len = 5, num = 5, unum = 5, pre = bin }, 6, false)
+
+ test_vim_str2nr('-0b101', flags, { len = 6, num = -5, unum = 5, pre = bin }, 0)
+ test_vim_str2nr('-0b101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('-0b101', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 2)
+ test_vim_str2nr('-0b101', flags, { len = 0 }, 3)
+ test_vim_str2nr('-0b101', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 3, false)
+ test_vim_str2nr('-0b101', flags, { len = 4, num = -1, unum = 1, pre = bin }, 4)
+ test_vim_str2nr('-0b101', flags, { len = 5, num = -2, unum = 2, pre = bin }, 5)
+ test_vim_str2nr('-0b101', flags, { len = 6, num = -5, unum = 5, pre = bin }, 6)
+ test_vim_str2nr('-0b101', flags, { len = 6, num = -5, unum = 5, pre = bin }, 7)
+
+ test_vim_str2nr('-0b1012', flags, { len = 0 }, 0)
+ test_vim_str2nr('-0b1012', flags, { len = 0 }, 7)
+ test_vim_str2nr('-0b1012', flags, { len = 6, num = -5, unum = 5, pre = bin }, 0, false)
+ test_vim_str2nr('-0b1012', flags, { len = 6, num = -5, unum = 5, pre = bin }, 7, false)
+
+ test_vim_str2nr('0B101', flags, { len = 5, num = 5, unum = 5, pre = BIN }, 0)
+ test_vim_str2nr('0B101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('0B101', flags, { len = 0 }, 2)
+ test_vim_str2nr('0B101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 2, false)
+ test_vim_str2nr('0B101', flags, { len = 3, num = 1, unum = 1, pre = BIN }, 3)
+ test_vim_str2nr('0B101', flags, { len = 4, num = 2, unum = 2, pre = BIN }, 4)
+ test_vim_str2nr('0B101', flags, { len = 5, num = 5, unum = 5, pre = BIN }, 5)
+ test_vim_str2nr('0B101', flags, { len = 5, num = 5, unum = 5, pre = BIN }, 6)
+
+ test_vim_str2nr('0B1012', flags, { len = 0 }, 0)
+ test_vim_str2nr('0B1012', flags, { len = 0 }, 6)
+ test_vim_str2nr('0B1012', flags, { len = 5, num = 5, unum = 5, pre = BIN }, 0, false)
+ test_vim_str2nr('0B1012', flags, { len = 5, num = 5, unum = 5, pre = BIN }, 6, false)
+
+ test_vim_str2nr('-0B101', flags, { len = 6, num = -5, unum = 5, pre = BIN }, 0)
+ test_vim_str2nr('-0B101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('-0B101', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 2)
+ test_vim_str2nr('-0B101', flags, { len = 0 }, 3)
+ test_vim_str2nr('-0B101', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 3, false)
+ test_vim_str2nr('-0B101', flags, { len = 4, num = -1, unum = 1, pre = BIN }, 4)
+ test_vim_str2nr('-0B101', flags, { len = 5, num = -2, unum = 2, pre = BIN }, 5)
+ test_vim_str2nr('-0B101', flags, { len = 6, num = -5, unum = 5, pre = BIN }, 6)
+ test_vim_str2nr('-0B101', flags, { len = 6, num = -5, unum = 5, pre = BIN }, 7)
+
+ test_vim_str2nr('-0B1012', flags, { len = 0 }, 0)
+ test_vim_str2nr('-0B1012', flags, { len = 0 }, 7)
+ test_vim_str2nr('-0B1012', flags, { len = 6, num = -5, unum = 5, pre = BIN }, 0, false)
+ test_vim_str2nr('-0B1012', flags, { len = 6, num = -5, unum = 5, pre = BIN }, 7, false)
if flags > lib.STR2NR_FORCE then
- test_vim_str2nr('-101', flags, {len = 4, num = -5, unum = 5, pre = 0}, 0)
+ test_vim_str2nr('-101', flags, { len = 4, num = -5, unum = 5, pre = 0 }, 0)
end
end
end)
@@ -236,42 +276,42 @@ describe('vim_str2nr()', function()
end
-- Check that all digits are recognized
- test_vim_str2nr( '012345670', flags, {len = 9, num = 2739128, unum = 2739128, pre = oct}, 0)
-
- test_vim_str2nr( '054', flags, {len = 3, num = 44, unum = 44, pre = oct}, 0)
- test_vim_str2nr( '054', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr( '054', flags, {len = 2, num = 5, unum = 5, pre = oct}, 2)
- test_vim_str2nr( '054', flags, {len = 3, num = 44, unum = 44, pre = oct}, 3)
- test_vim_str2nr( '0548', flags, {len = 3, num = 44, unum = 44, pre = oct}, 3)
- test_vim_str2nr( '054', flags, {len = 3, num = 44, unum = 44, pre = oct}, 4)
-
- test_vim_str2nr( '054x', flags, {len = 0}, 4)
- test_vim_str2nr( '054x', flags, {len = 0}, 0)
- test_vim_str2nr( '054x', flags, {len = 3, num = 44, unum = 44, pre = oct}, 4, false)
- test_vim_str2nr( '054x', flags, {len = 3, num = 44, unum = 44, pre = oct}, 0, false)
-
- test_vim_str2nr('-054', flags, {len = 4, num = -44, unum = 44, pre = oct}, 0)
- test_vim_str2nr('-054', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr('-054', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 2)
- test_vim_str2nr('-054', flags, {len = 3, num = -5, unum = 5, pre = oct}, 3)
- test_vim_str2nr('-054', flags, {len = 4, num = -44, unum = 44, pre = oct}, 4)
- test_vim_str2nr('-0548', flags, {len = 4, num = -44, unum = 44, pre = oct}, 4)
- test_vim_str2nr('-054', flags, {len = 4, num = -44, unum = 44, pre = oct}, 5)
-
- test_vim_str2nr('-054x', flags, {len = 0}, 5)
- test_vim_str2nr('-054x', flags, {len = 0}, 0)
- test_vim_str2nr('-054x', flags, {len = 4, num = -44, unum = 44, pre = oct}, 5, false)
- test_vim_str2nr('-054x', flags, {len = 4, num = -44, unum = 44, pre = oct}, 0, false)
+ test_vim_str2nr('012345670', flags, { len = 9, num = 2739128, unum = 2739128, pre = oct }, 0)
+
+ test_vim_str2nr('054', flags, { len = 3, num = 44, unum = 44, pre = oct }, 0)
+ test_vim_str2nr('054', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('054', flags, { len = 2, num = 5, unum = 5, pre = oct }, 2)
+ test_vim_str2nr('054', flags, { len = 3, num = 44, unum = 44, pre = oct }, 3)
+ test_vim_str2nr('0548', flags, { len = 3, num = 44, unum = 44, pre = oct }, 3)
+ test_vim_str2nr('054', flags, { len = 3, num = 44, unum = 44, pre = oct }, 4)
+
+ test_vim_str2nr('054x', flags, { len = 0 }, 4)
+ test_vim_str2nr('054x', flags, { len = 0 }, 0)
+ test_vim_str2nr('054x', flags, { len = 3, num = 44, unum = 44, pre = oct }, 4, false)
+ test_vim_str2nr('054x', flags, { len = 3, num = 44, unum = 44, pre = oct }, 0, false)
+
+ test_vim_str2nr('-054', flags, { len = 4, num = -44, unum = 44, pre = oct }, 0)
+ test_vim_str2nr('-054', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('-054', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 2)
+ test_vim_str2nr('-054', flags, { len = 3, num = -5, unum = 5, pre = oct }, 3)
+ test_vim_str2nr('-054', flags, { len = 4, num = -44, unum = 44, pre = oct }, 4)
+ test_vim_str2nr('-0548', flags, { len = 4, num = -44, unum = 44, pre = oct }, 4)
+ test_vim_str2nr('-054', flags, { len = 4, num = -44, unum = 44, pre = oct }, 5)
+
+ test_vim_str2nr('-054x', flags, { len = 0 }, 5)
+ test_vim_str2nr('-054x', flags, { len = 0 }, 0)
+ test_vim_str2nr('-054x', flags, { len = 4, num = -44, unum = 44, pre = oct }, 5, false)
+ test_vim_str2nr('-054x', flags, { len = 4, num = -44, unum = 44, pre = oct }, 0, false)
if flags > lib.STR2NR_FORCE then
- test_vim_str2nr('-54', flags, {len = 3, num = -44, unum = 44, pre = 0}, 0)
- test_vim_str2nr('-0548', flags, {len = 0}, 5)
- test_vim_str2nr('-0548', flags, {len = 0}, 0)
- test_vim_str2nr('-0548', flags, {len = 4, num = -44, unum = 44, pre = 0}, 5, false)
- test_vim_str2nr('-0548', flags, {len = 4, num = -44, unum = 44, pre = 0}, 0, false)
+ test_vim_str2nr('-54', flags, { len = 3, num = -44, unum = 44, pre = 0 }, 0)
+ test_vim_str2nr('-0548', flags, { len = 0 }, 5)
+ test_vim_str2nr('-0548', flags, { len = 0 }, 0)
+ test_vim_str2nr('-0548', flags, { len = 4, num = -44, unum = 44, pre = 0 }, 5, false)
+ test_vim_str2nr('-0548', flags, { len = 4, num = -44, unum = 44, pre = 0 }, 0, false)
else
- test_vim_str2nr('-0548', flags, {len = 5, num = -548, unum = 548, pre = 0}, 5)
- test_vim_str2nr('-0548', flags, {len = 5, num = -548, unum = 548, pre = 0}, 0)
+ test_vim_str2nr('-0548', flags, { len = 5, num = -548, unum = 548, pre = 0 }, 5)
+ test_vim_str2nr('-0548', flags, { len = 5, num = -548, unum = 548, pre = 0 }, 0)
end
end
end)
@@ -298,73 +338,73 @@ describe('vim_str2nr()', function()
OCT = ('O'):byte()
end
- test_vim_str2nr( '0o054', flags, {len = 5, num = 44, unum = 44, pre = oct}, 0)
- test_vim_str2nr( '0o054', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr( '0o054', flags, {len = 0}, 2)
- test_vim_str2nr( '0o054', flags, {len = 3, num = 0, unum = 0, pre = oct}, 3)
- test_vim_str2nr( '0o054', flags, {len = 4, num = 5, unum = 5, pre = oct}, 4)
- test_vim_str2nr( '0o054', flags, {len = 5, num = 44, unum = 44, pre = oct}, 5)
- test_vim_str2nr( '0o0548', flags, {len = 5, num = 44, unum = 44, pre = oct}, 5)
- test_vim_str2nr( '0o054', flags, {len = 5, num = 44, unum = 44, pre = oct}, 6)
-
- test_vim_str2nr( '0o054x', flags, {len = 0}, 6)
- test_vim_str2nr( '0o054x', flags, {len = 0}, 0)
- test_vim_str2nr( '0o054x', flags, {len = 5, num = 44, unum = 44, pre = oct}, 6, false)
- test_vim_str2nr( '0o054x', flags, {len = 5, num = 44, unum = 44, pre = oct}, 0, false)
-
- test_vim_str2nr('-0o054', flags, {len = 6, num = -44, unum = 44, pre = oct}, 0)
- test_vim_str2nr('-0o054', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr('-0o054', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 2)
- test_vim_str2nr('-0o054', flags, {len = 0}, 3)
- test_vim_str2nr('-0o054', flags, {len = 4, num = 0, unum = 0, pre = oct}, 4)
- test_vim_str2nr('-0o054', flags, {len = 5, num = -5, unum = 5, pre = oct}, 5)
- test_vim_str2nr('-0o054', flags, {len = 6, num = -44, unum = 44, pre = oct}, 6)
- test_vim_str2nr('-0o0548', flags, {len = 6, num = -44, unum = 44, pre = oct}, 6)
- test_vim_str2nr('-0o054', flags, {len = 6, num = -44, unum = 44, pre = oct}, 7)
-
- test_vim_str2nr('-0o054x', flags, {len = 0}, 7)
- test_vim_str2nr('-0o054x', flags, {len = 0}, 0)
- test_vim_str2nr('-0o054x', flags, {len = 6, num = -44, unum = 44, pre = oct}, 7, false)
- test_vim_str2nr('-0o054x', flags, {len = 6, num = -44, unum = 44, pre = oct}, 0, false)
-
- test_vim_str2nr( '0O054', flags, {len = 5, num = 44, unum = 44, pre = OCT}, 0)
- test_vim_str2nr( '0O054', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr( '0O054', flags, {len = 0}, 2)
- test_vim_str2nr( '0O054', flags, {len = 3, num = 0, unum = 0, pre = OCT}, 3)
- test_vim_str2nr( '0O054', flags, {len = 4, num = 5, unum = 5, pre = OCT}, 4)
- test_vim_str2nr( '0O054', flags, {len = 5, num = 44, unum = 44, pre = OCT}, 5)
- test_vim_str2nr( '0O0548', flags, {len = 5, num = 44, unum = 44, pre = OCT}, 5)
- test_vim_str2nr( '0O054', flags, {len = 5, num = 44, unum = 44, pre = OCT}, 6)
-
- test_vim_str2nr( '0O054x', flags, {len = 0}, 6)
- test_vim_str2nr( '0O054x', flags, {len = 0}, 0)
- test_vim_str2nr( '0O054x', flags, {len = 5, num = 44, unum = 44, pre = OCT}, 6, false)
- test_vim_str2nr( '0O054x', flags, {len = 5, num = 44, unum = 44, pre = OCT}, 0, false)
-
- test_vim_str2nr('-0O054', flags, {len = 6, num = -44, unum = 44, pre = OCT}, 0)
- test_vim_str2nr('-0O054', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr('-0O054', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 2)
- test_vim_str2nr('-0O054', flags, {len = 0}, 3)
- test_vim_str2nr('-0O054', flags, {len = 4, num = 0, unum = 0, pre = OCT}, 4)
- test_vim_str2nr('-0O054', flags, {len = 5, num = -5, unum = 5, pre = OCT}, 5)
- test_vim_str2nr('-0O054', flags, {len = 6, num = -44, unum = 44, pre = OCT}, 6)
- test_vim_str2nr('-0O0548', flags, {len = 6, num = -44, unum = 44, pre = OCT}, 6)
- test_vim_str2nr('-0O054', flags, {len = 6, num = -44, unum = 44, pre = OCT}, 7)
-
- test_vim_str2nr('-0O054x', flags, {len = 0}, 7)
- test_vim_str2nr('-0O054x', flags, {len = 0}, 0)
- test_vim_str2nr('-0O054x', flags, {len = 6, num = -44, unum = 44, pre = OCT}, 7, false)
- test_vim_str2nr('-0O054x', flags, {len = 6, num = -44, unum = 44, pre = OCT}, 0, false)
+ test_vim_str2nr('0o054', flags, { len = 5, num = 44, unum = 44, pre = oct }, 0)
+ test_vim_str2nr('0o054', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('0o054', flags, { len = 0 }, 2)
+ test_vim_str2nr('0o054', flags, { len = 3, num = 0, unum = 0, pre = oct }, 3)
+ test_vim_str2nr('0o054', flags, { len = 4, num = 5, unum = 5, pre = oct }, 4)
+ test_vim_str2nr('0o054', flags, { len = 5, num = 44, unum = 44, pre = oct }, 5)
+ test_vim_str2nr('0o0548', flags, { len = 5, num = 44, unum = 44, pre = oct }, 5)
+ test_vim_str2nr('0o054', flags, { len = 5, num = 44, unum = 44, pre = oct }, 6)
+
+ test_vim_str2nr('0o054x', flags, { len = 0 }, 6)
+ test_vim_str2nr('0o054x', flags, { len = 0 }, 0)
+ test_vim_str2nr('0o054x', flags, { len = 5, num = 44, unum = 44, pre = oct }, 6, false)
+ test_vim_str2nr('0o054x', flags, { len = 5, num = 44, unum = 44, pre = oct }, 0, false)
+
+ test_vim_str2nr('-0o054', flags, { len = 6, num = -44, unum = 44, pre = oct }, 0)
+ test_vim_str2nr('-0o054', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('-0o054', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 2)
+ test_vim_str2nr('-0o054', flags, { len = 0 }, 3)
+ test_vim_str2nr('-0o054', flags, { len = 4, num = 0, unum = 0, pre = oct }, 4)
+ test_vim_str2nr('-0o054', flags, { len = 5, num = -5, unum = 5, pre = oct }, 5)
+ test_vim_str2nr('-0o054', flags, { len = 6, num = -44, unum = 44, pre = oct }, 6)
+ test_vim_str2nr('-0o0548', flags, { len = 6, num = -44, unum = 44, pre = oct }, 6)
+ test_vim_str2nr('-0o054', flags, { len = 6, num = -44, unum = 44, pre = oct }, 7)
+
+ test_vim_str2nr('-0o054x', flags, { len = 0 }, 7)
+ test_vim_str2nr('-0o054x', flags, { len = 0 }, 0)
+ test_vim_str2nr('-0o054x', flags, { len = 6, num = -44, unum = 44, pre = oct }, 7, false)
+ test_vim_str2nr('-0o054x', flags, { len = 6, num = -44, unum = 44, pre = oct }, 0, false)
+
+ test_vim_str2nr('0O054', flags, { len = 5, num = 44, unum = 44, pre = OCT }, 0)
+ test_vim_str2nr('0O054', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('0O054', flags, { len = 0 }, 2)
+ test_vim_str2nr('0O054', flags, { len = 3, num = 0, unum = 0, pre = OCT }, 3)
+ test_vim_str2nr('0O054', flags, { len = 4, num = 5, unum = 5, pre = OCT }, 4)
+ test_vim_str2nr('0O054', flags, { len = 5, num = 44, unum = 44, pre = OCT }, 5)
+ test_vim_str2nr('0O0548', flags, { len = 5, num = 44, unum = 44, pre = OCT }, 5)
+ test_vim_str2nr('0O054', flags, { len = 5, num = 44, unum = 44, pre = OCT }, 6)
+
+ test_vim_str2nr('0O054x', flags, { len = 0 }, 6)
+ test_vim_str2nr('0O054x', flags, { len = 0 }, 0)
+ test_vim_str2nr('0O054x', flags, { len = 5, num = 44, unum = 44, pre = OCT }, 6, false)
+ test_vim_str2nr('0O054x', flags, { len = 5, num = 44, unum = 44, pre = OCT }, 0, false)
+
+ test_vim_str2nr('-0O054', flags, { len = 6, num = -44, unum = 44, pre = OCT }, 0)
+ test_vim_str2nr('-0O054', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('-0O054', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 2)
+ test_vim_str2nr('-0O054', flags, { len = 0 }, 3)
+ test_vim_str2nr('-0O054', flags, { len = 4, num = 0, unum = 0, pre = OCT }, 4)
+ test_vim_str2nr('-0O054', flags, { len = 5, num = -5, unum = 5, pre = OCT }, 5)
+ test_vim_str2nr('-0O054', flags, { len = 6, num = -44, unum = 44, pre = OCT }, 6)
+ test_vim_str2nr('-0O0548', flags, { len = 6, num = -44, unum = 44, pre = OCT }, 6)
+ test_vim_str2nr('-0O054', flags, { len = 6, num = -44, unum = 44, pre = OCT }, 7)
+
+ test_vim_str2nr('-0O054x', flags, { len = 0 }, 7)
+ test_vim_str2nr('-0O054x', flags, { len = 0 }, 0)
+ test_vim_str2nr('-0O054x', flags, { len = 6, num = -44, unum = 44, pre = OCT }, 7, false)
+ test_vim_str2nr('-0O054x', flags, { len = 6, num = -44, unum = 44, pre = OCT }, 0, false)
if flags > lib.STR2NR_FORCE then
- test_vim_str2nr('-0548', flags, {len = 0}, 5)
- test_vim_str2nr('-0548', flags, {len = 0}, 0)
- test_vim_str2nr('-0548', flags, {len = 4, num = -44, unum = 44, pre = 0}, 5, false)
- test_vim_str2nr('-0548', flags, {len = 4, num = -44, unum = 44, pre = 0}, 0, false)
- test_vim_str2nr('-055', flags, {len = 4, num = -45, unum = 45, pre = 0}, 0)
+ test_vim_str2nr('-0548', flags, { len = 0 }, 5)
+ test_vim_str2nr('-0548', flags, { len = 0 }, 0)
+ test_vim_str2nr('-0548', flags, { len = 4, num = -44, unum = 44, pre = 0 }, 5, false)
+ test_vim_str2nr('-0548', flags, { len = 4, num = -44, unum = 44, pre = 0 }, 0, false)
+ test_vim_str2nr('-055', flags, { len = 4, num = -45, unum = 45, pre = 0 }, 0)
else
- test_vim_str2nr('-0548', flags, {len = 5, num = -548, unum = 548, pre = 0}, 5)
- test_vim_str2nr('-0548', flags, {len = 5, num = -548, unum = 548, pre = 0}, 0)
+ test_vim_str2nr('-0548', flags, { len = 5, num = -548, unum = 548, pre = 0 }, 5)
+ test_vim_str2nr('-0548', flags, { len = 5, num = -548, unum = 548, pre = 0 }, 0)
end
end
end)
@@ -387,92 +427,92 @@ describe('vim_str2nr()', function()
end
-- Check that all digits are recognized
- test_vim_str2nr('0x12345', flags, {len = 7, num = 74565, unum = 74565, pre = hex}, 0)
- test_vim_str2nr('0x67890', flags, {len = 7, num = 424080, unum = 424080, pre = hex}, 0)
- test_vim_str2nr('0xABCDEF', flags, {len = 8, num = 11259375, unum = 11259375, pre = hex}, 0)
- test_vim_str2nr('0xabcdef', flags, {len = 8, num = 11259375, unum = 11259375, pre = hex}, 0)
-
- test_vim_str2nr( '0x101', flags, {len = 5, num = 257, unum =257, pre = hex}, 0)
- test_vim_str2nr( '0x101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr( '0x101', flags, {len = 0}, 2)
- test_vim_str2nr( '0x101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 2, false)
- test_vim_str2nr( '0x101', flags, {len = 3, num = 1, unum = 1, pre = hex}, 3)
- test_vim_str2nr( '0x101', flags, {len = 4, num = 16, unum = 16, pre = hex}, 4)
- test_vim_str2nr( '0x101', flags, {len = 5, num = 257, unum =257, pre = hex}, 5)
- test_vim_str2nr( '0x101', flags, {len = 5, num = 257, unum =257, pre = hex}, 6)
-
- test_vim_str2nr( '0x101G', flags, {len = 0}, 0)
- test_vim_str2nr( '0x101G', flags, {len = 0}, 6)
- test_vim_str2nr( '0x101G', flags, {len = 5, num = 257, unum =257, pre = hex}, 0, false)
- test_vim_str2nr( '0x101G', flags, {len = 5, num = 257, unum =257, pre = hex}, 6, false)
-
- test_vim_str2nr('-0x101', flags, {len = 6, num =-257, unum =257, pre = hex}, 0)
- test_vim_str2nr('-0x101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr('-0x101', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 2)
- test_vim_str2nr('-0x101', flags, {len = 0}, 3)
- test_vim_str2nr('-0x101', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 3, false)
- test_vim_str2nr('-0x101', flags, {len = 4, num = -1, unum = 1, pre = hex}, 4)
- test_vim_str2nr('-0x101', flags, {len = 5, num = -16, unum = 16, pre = hex}, 5)
- test_vim_str2nr('-0x101', flags, {len = 6, num =-257, unum =257, pre = hex}, 6)
- test_vim_str2nr('-0x101', flags, {len = 6, num =-257, unum =257, pre = hex}, 7)
-
- test_vim_str2nr('-0x101G', flags, {len = 0}, 0)
- test_vim_str2nr('-0x101G', flags, {len = 0}, 7)
- test_vim_str2nr('-0x101G', flags, {len = 6, num =-257, unum =257, pre = hex}, 0, false)
- test_vim_str2nr('-0x101G', flags, {len = 6, num =-257, unum =257, pre = hex}, 7, false)
-
- test_vim_str2nr( '0X101', flags, {len = 5, num = 257, unum =257, pre = HEX}, 0)
- test_vim_str2nr( '0X101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr( '0X101', flags, {len = 0}, 2)
- test_vim_str2nr( '0X101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 2, false)
- test_vim_str2nr( '0X101', flags, {len = 3, num = 1, unum = 1, pre = HEX}, 3)
- test_vim_str2nr( '0X101', flags, {len = 4, num = 16, unum = 16, pre = HEX}, 4)
- test_vim_str2nr( '0X101', flags, {len = 5, num = 257, unum =257, pre = HEX}, 5)
- test_vim_str2nr( '0X101', flags, {len = 5, num = 257, unum =257, pre = HEX}, 6)
-
- test_vim_str2nr( '0X101G', flags, {len = 0}, 0)
- test_vim_str2nr( '0X101G', flags, {len = 0}, 6)
- test_vim_str2nr( '0X101G', flags, {len = 5, num = 257, unum =257, pre = HEX}, 0, false)
- test_vim_str2nr( '0X101G', flags, {len = 5, num = 257, unum =257, pre = HEX}, 6, false)
-
- test_vim_str2nr('-0X101', flags, {len = 6, num =-257, unum =257, pre = HEX}, 0)
- test_vim_str2nr('-0X101', flags, {len = 1, num = 0, unum = 0, pre = 0 }, 1)
- test_vim_str2nr('-0X101', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 2)
- test_vim_str2nr('-0X101', flags, {len = 0}, 3)
- test_vim_str2nr('-0X101', flags, {len = 2, num = 0, unum = 0, pre = 0 }, 3, false)
- test_vim_str2nr('-0X101', flags, {len = 4, num = -1, unum = 1, pre = HEX}, 4)
- test_vim_str2nr('-0X101', flags, {len = 5, num = -16, unum = 16, pre = HEX}, 5)
- test_vim_str2nr('-0X101', flags, {len = 6, num =-257, unum =257, pre = HEX}, 6)
- test_vim_str2nr('-0X101', flags, {len = 6, num =-257, unum =257, pre = HEX}, 7)
-
- test_vim_str2nr('-0X101G', flags, {len = 0}, 0)
- test_vim_str2nr('-0X101G', flags, {len = 0}, 7)
- test_vim_str2nr('-0X101G', flags, {len = 6, num =-257, unum =257, pre = HEX}, 0, false)
- test_vim_str2nr('-0X101G', flags, {len = 6, num =-257, unum =257, pre = HEX}, 7, false)
+ test_vim_str2nr('0x12345', flags, { len = 7, num = 74565, unum = 74565, pre = hex }, 0)
+ test_vim_str2nr('0x67890', flags, { len = 7, num = 424080, unum = 424080, pre = hex }, 0)
+ test_vim_str2nr('0xABCDEF', flags, { len = 8, num = 11259375, unum = 11259375, pre = hex }, 0)
+ test_vim_str2nr('0xabcdef', flags, { len = 8, num = 11259375, unum = 11259375, pre = hex }, 0)
+
+ test_vim_str2nr('0x101', flags, { len = 5, num = 257, unum = 257, pre = hex }, 0)
+ test_vim_str2nr('0x101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('0x101', flags, { len = 0 }, 2)
+ test_vim_str2nr('0x101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 2, false)
+ test_vim_str2nr('0x101', flags, { len = 3, num = 1, unum = 1, pre = hex }, 3)
+ test_vim_str2nr('0x101', flags, { len = 4, num = 16, unum = 16, pre = hex }, 4)
+ test_vim_str2nr('0x101', flags, { len = 5, num = 257, unum = 257, pre = hex }, 5)
+ test_vim_str2nr('0x101', flags, { len = 5, num = 257, unum = 257, pre = hex }, 6)
+
+ test_vim_str2nr('0x101G', flags, { len = 0 }, 0)
+ test_vim_str2nr('0x101G', flags, { len = 0 }, 6)
+ test_vim_str2nr('0x101G', flags, { len = 5, num = 257, unum = 257, pre = hex }, 0, false)
+ test_vim_str2nr('0x101G', flags, { len = 5, num = 257, unum = 257, pre = hex }, 6, false)
+
+ test_vim_str2nr('-0x101', flags, { len = 6, num = -257, unum = 257, pre = hex }, 0)
+ test_vim_str2nr('-0x101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('-0x101', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 2)
+ test_vim_str2nr('-0x101', flags, { len = 0 }, 3)
+ test_vim_str2nr('-0x101', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 3, false)
+ test_vim_str2nr('-0x101', flags, { len = 4, num = -1, unum = 1, pre = hex }, 4)
+ test_vim_str2nr('-0x101', flags, { len = 5, num = -16, unum = 16, pre = hex }, 5)
+ test_vim_str2nr('-0x101', flags, { len = 6, num = -257, unum = 257, pre = hex }, 6)
+ test_vim_str2nr('-0x101', flags, { len = 6, num = -257, unum = 257, pre = hex }, 7)
+
+ test_vim_str2nr('-0x101G', flags, { len = 0 }, 0)
+ test_vim_str2nr('-0x101G', flags, { len = 0 }, 7)
+ test_vim_str2nr('-0x101G', flags, { len = 6, num = -257, unum = 257, pre = hex }, 0, false)
+ test_vim_str2nr('-0x101G', flags, { len = 6, num = -257, unum = 257, pre = hex }, 7, false)
+
+ test_vim_str2nr('0X101', flags, { len = 5, num = 257, unum = 257, pre = HEX }, 0)
+ test_vim_str2nr('0X101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('0X101', flags, { len = 0 }, 2)
+ test_vim_str2nr('0X101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 2, false)
+ test_vim_str2nr('0X101', flags, { len = 3, num = 1, unum = 1, pre = HEX }, 3)
+ test_vim_str2nr('0X101', flags, { len = 4, num = 16, unum = 16, pre = HEX }, 4)
+ test_vim_str2nr('0X101', flags, { len = 5, num = 257, unum = 257, pre = HEX }, 5)
+ test_vim_str2nr('0X101', flags, { len = 5, num = 257, unum = 257, pre = HEX }, 6)
+
+ test_vim_str2nr('0X101G', flags, { len = 0 }, 0)
+ test_vim_str2nr('0X101G', flags, { len = 0 }, 6)
+ test_vim_str2nr('0X101G', flags, { len = 5, num = 257, unum = 257, pre = HEX }, 0, false)
+ test_vim_str2nr('0X101G', flags, { len = 5, num = 257, unum = 257, pre = HEX }, 6, false)
+
+ test_vim_str2nr('-0X101', flags, { len = 6, num = -257, unum = 257, pre = HEX }, 0)
+ test_vim_str2nr('-0X101', flags, { len = 1, num = 0, unum = 0, pre = 0 }, 1)
+ test_vim_str2nr('-0X101', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 2)
+ test_vim_str2nr('-0X101', flags, { len = 0 }, 3)
+ test_vim_str2nr('-0X101', flags, { len = 2, num = 0, unum = 0, pre = 0 }, 3, false)
+ test_vim_str2nr('-0X101', flags, { len = 4, num = -1, unum = 1, pre = HEX }, 4)
+ test_vim_str2nr('-0X101', flags, { len = 5, num = -16, unum = 16, pre = HEX }, 5)
+ test_vim_str2nr('-0X101', flags, { len = 6, num = -257, unum = 257, pre = HEX }, 6)
+ test_vim_str2nr('-0X101', flags, { len = 6, num = -257, unum = 257, pre = HEX }, 7)
+
+ test_vim_str2nr('-0X101G', flags, { len = 0 }, 0)
+ test_vim_str2nr('-0X101G', flags, { len = 0 }, 7)
+ test_vim_str2nr('-0X101G', flags, { len = 6, num = -257, unum = 257, pre = HEX }, 0, false)
+ test_vim_str2nr('-0X101G', flags, { len = 6, num = -257, unum = 257, pre = HEX }, 7, false)
if flags > lib.STR2NR_FORCE then
- test_vim_str2nr('-101', flags, {len = 4, num = -257, unum = 257, pre = 0}, 0)
+ test_vim_str2nr('-101', flags, { len = 4, num = -257, unum = 257, pre = 0 }, 0)
end
end
end)
-- Test_str2nr() in test_functions.vim already tests normal usage
itp('works with weirdly quoted numbers', function()
local flags = lib.STR2NR_DEC + lib.STR2NR_QUOTE
- test_vim_str2nr("'027", flags, {len = 0}, 0)
- test_vim_str2nr("'027", flags, {len = 0}, 0, false)
- test_vim_str2nr("1'2'3'4", flags, {len = 7, num = 1234, unum = 1234, pre = 0}, 0)
+ test_vim_str2nr("'027", flags, { len = 0 }, 0)
+ test_vim_str2nr("'027", flags, { len = 0 }, 0, false)
+ test_vim_str2nr("1'2'3'4", flags, { len = 7, num = 1234, unum = 1234, pre = 0 }, 0)
-- counter-intuitive, but like Vim, strict=true should partially accept
-- these: (' and - are not alphanumeric)
- test_vim_str2nr("7''331", flags, {len = 1, num = 7, unum = 7, pre = 0}, 0)
- test_vim_str2nr("123'x4", flags, {len = 3, num = 123, unum = 123, pre = 0}, 0)
- test_vim_str2nr("1337'", flags, {len = 4, num = 1337, unum = 1337, pre = 0}, 0)
- test_vim_str2nr("-'", flags, {len = 1, num = 0, unum = 0, pre = 0}, 0)
+ test_vim_str2nr("7''331", flags, { len = 1, num = 7, unum = 7, pre = 0 }, 0)
+ test_vim_str2nr("123'x4", flags, { len = 3, num = 123, unum = 123, pre = 0 }, 0)
+ test_vim_str2nr("1337'", flags, { len = 4, num = 1337, unum = 1337, pre = 0 }, 0)
+ test_vim_str2nr("-'", flags, { len = 1, num = 0, unum = 0, pre = 0 }, 0)
flags = lib.STR2NR_HEX + lib.STR2NR_QUOTE
local hex = ('x'):byte()
- test_vim_str2nr("0x'abcd", flags, {len = 0}, 0)
- test_vim_str2nr("0x'abcd", flags, {len = 1, num = 0, unum = 0, pre = 0}, 0, false)
- test_vim_str2nr("0xab''cd", flags, {len = 4, num = 171, unum = 171, pre = hex}, 0)
+ test_vim_str2nr("0x'abcd", flags, { len = 0 }, 0)
+ test_vim_str2nr("0x'abcd", flags, { len = 1, num = 0, unum = 0, pre = 0 }, 0, false)
+ test_vim_str2nr("0xab''cd", flags, { len = 4, num = 171, unum = 171, pre = hex }, 0)
end)
end)
diff --git a/test/unit/eval/decode_spec.lua b/test/unit/eval/decode_spec.lua
index 0c444b33f2..5a8374a2a6 100644
--- a/test/unit/eval/decode_spec.lua
+++ b/test/unit/eval/decode_spec.lua
@@ -6,9 +6,13 @@ local eq = helpers.eq
local neq = helpers.neq
local ffi = helpers.ffi
-local decode = cimport('./src/nvim/eval/decode.h', './src/nvim/eval/typval.h',
- './src/nvim/globals.h', './src/nvim/memory.h',
- './src/nvim/message.h')
+local decode = cimport(
+ './src/nvim/eval/decode.h',
+ './src/nvim/eval/typval.h',
+ './src/nvim/globals.h',
+ './src/nvim/memory.h',
+ './src/nvim/message.h'
+)
describe('json_decode_string()', function()
local char = function(c)
@@ -16,7 +20,7 @@ describe('json_decode_string()', function()
end
itp('does not overflow when running with `n…`, `t…`, `f…`', function()
- local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
+ local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN })
decode.emsg_silent = 1
-- This will not crash, but if `len` argument will be ignored it will parse
-- `null` as `null` and if not it will parse `null` as `n`.
@@ -43,7 +47,7 @@ describe('json_decode_string()', function()
end)
itp('does not overflow and crash when running with `n`, `t`, `f`', function()
- local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
+ local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN })
decode.emsg_silent = 1
eq(0, decode.json_decode_string(char('n'), 1, rettv))
eq(decode.VAR_UNKNOWN, rettv.v_type)
@@ -54,7 +58,7 @@ describe('json_decode_string()', function()
end)
itp('does not overflow when running with `"…`', function()
- local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
+ local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN })
decode.emsg_silent = 1
eq(0, decode.json_decode_string('"t"', 2, rettv))
eq(decode.VAR_UNKNOWN, rettv.v_type)
@@ -63,7 +67,7 @@ describe('json_decode_string()', function()
end)
local check_failure = function(s, len, msg)
- local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
+ local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN })
eq(0, decode.json_decode_string(s, len, rettv))
eq(decode.VAR_UNKNOWN, rettv.v_type)
neq(nil, decode.last_msg_hist)
@@ -74,8 +78,7 @@ describe('json_decode_string()', function()
collectgarbage('restart')
check_failure(']test', 1, 'E474: No container to close: ]')
check_failure('[}test', 2, 'E474: Closing list with curly bracket: }')
- check_failure('{]test', 2,
- 'E474: Closing dictionary with square bracket: ]')
+ check_failure('{]test', 2, 'E474: Closing dictionary with square bracket: ]')
check_failure('[1,]test', 4, 'E474: Trailing comma: ]')
check_failure('{"1":}test', 6, 'E474: Expected value after colon: }')
check_failure('{"1"}test', 5, 'E474: Expected value: }')
@@ -93,16 +96,20 @@ describe('json_decode_string()', function()
check_failure('ttest', 1, 'E474: Expected true: t')
check_failure('ftest', 1, 'E474: Expected false: f')
check_failure('"\\test', 2, 'E474: Unfinished escape sequence: "\\')
- check_failure('"\\u"test', 4,
- 'E474: Unfinished unicode escape sequence: "\\u"')
- check_failure('"\\uXXXX"est', 8,
- 'E474: Expected four hex digits after \\u: \\uXXXX"')
+ check_failure('"\\u"test', 4, 'E474: Unfinished unicode escape sequence: "\\u"')
+ check_failure('"\\uXXXX"est', 8, 'E474: Expected four hex digits after \\u: \\uXXXX"')
check_failure('"\\?"test', 4, 'E474: Unknown escape sequence: \\?"')
check_failure(
- '"\t"test', 3,
- 'E474: ASCII control characters cannot be present inside string: \t"')
+ '"\t"test',
+ 3,
+ 'E474: ASCII control characters cannot be present inside string: \t"'
+ )
check_failure('"\194"test', 3, 'E474: Only UTF-8 strings allowed: \194"')
- check_failure('"\252\144\128\128\128\128"test', 8, 'E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"')
+ check_failure(
+ '"\252\144\128\128\128\128"test',
+ 8,
+ 'E474: Only UTF-8 code points up to U+10FFFF are allowed to appear unescaped: \252\144\128\128\128\128"'
+ )
check_failure('"test', 1, 'E474: Expected string end: "')
check_failure('-test', 1, 'E474: Missing number after minus sign: -')
check_failure('-1.test', 3, 'E474: Missing number after decimal dot: -1.')
@@ -117,7 +124,7 @@ describe('json_decode_string()', function()
end)
itp('does not overflow and crash when running with `"`', function()
- local rettv = ffi.new('typval_T', {v_type=decode.VAR_UNKNOWN})
+ local rettv = ffi.new('typval_T', { v_type = decode.VAR_UNKNOWN })
decode.emsg_silent = 1
eq(0, decode.json_decode_string(char('"'), 1, rettv))
eq(decode.VAR_UNKNOWN, rettv.v_type)
diff --git a/test/unit/eval/encode_spec.lua b/test/unit/eval/encode_spec.lua
index 058c55093e..498346d7cc 100644
--- a/test/unit/eval/encode_spec.lua
+++ b/test/unit/eval/encode_spec.lua
@@ -22,80 +22,83 @@ describe('encode_list_write()', function()
itp('writes empty string', function()
local l = list()
eq(0, encode_list_write(l, ''))
- eq({[type_key]=list_type}, lst2tbl(l))
+ eq({ [type_key] = list_type }, lst2tbl(l))
end)
itp('writes ASCII string literal with printable characters', function()
local l = list()
eq(0, encode_list_write(l, 'abc'))
- eq({'abc'}, lst2tbl(l))
+ eq({ 'abc' }, lst2tbl(l))
end)
itp('writes string starting with NL', function()
local l = list()
eq(0, encode_list_write(l, '\nabc'))
- eq({null_string, 'abc'}, lst2tbl(l))
+ eq({ null_string, 'abc' }, lst2tbl(l))
end)
itp('writes string starting with NL twice', function()
local l = list()
eq(0, encode_list_write(l, '\nabc'))
- eq({null_string, 'abc'}, lst2tbl(l))
+ eq({ null_string, 'abc' }, lst2tbl(l))
eq(0, encode_list_write(l, '\nabc'))
- eq({null_string, 'abc', 'abc'}, lst2tbl(l))
+ eq({ null_string, 'abc', 'abc' }, lst2tbl(l))
end)
itp('writes string ending with NL', function()
local l = list()
eq(0, encode_list_write(l, 'abc\n'))
- eq({'abc', null_string}, lst2tbl(l))
+ eq({ 'abc', null_string }, lst2tbl(l))
end)
itp('writes string ending with NL twice', function()
local l = list()
eq(0, encode_list_write(l, 'abc\n'))
- eq({'abc', null_string}, lst2tbl(l))
+ eq({ 'abc', null_string }, lst2tbl(l))
eq(0, encode_list_write(l, 'abc\n'))
- eq({'abc', 'abc', null_string}, lst2tbl(l))
+ eq({ 'abc', 'abc', null_string }, lst2tbl(l))
end)
itp('writes string starting, ending and containing NL twice', function()
local l = list()
eq(0, encode_list_write(l, '\na\nb\n'))
- eq({null_string, 'a', 'b', null_string}, lst2tbl(l))
+ eq({ null_string, 'a', 'b', null_string }, lst2tbl(l))
eq(0, encode_list_write(l, '\na\nb\n'))
- eq({null_string, 'a', 'b', null_string, 'a', 'b', null_string}, lst2tbl(l))
+ eq({ null_string, 'a', 'b', null_string, 'a', 'b', null_string }, lst2tbl(l))
end)
itp('writes string starting, ending and containing NUL with NL between twice', function()
local l = list()
eq(0, encode_list_write(l, '\0\n\0\n\0'))
- eq({'\n', '\n', '\n'}, lst2tbl(l))
+ eq({ '\n', '\n', '\n' }, lst2tbl(l))
eq(0, encode_list_write(l, '\0\n\0\n\0'))
- eq({'\n', '\n', '\n\n', '\n', '\n'}, lst2tbl(l))
+ eq({ '\n', '\n', '\n\n', '\n', '\n' }, lst2tbl(l))
end)
itp('writes string starting, ending and containing NL with NUL between twice', function()
local l = list()
eq(0, encode_list_write(l, '\n\0\n\0\n'))
- eq({null_string, '\n', '\n', null_string}, lst2tbl(l))
+ eq({ null_string, '\n', '\n', null_string }, lst2tbl(l))
eq(0, encode_list_write(l, '\n\0\n\0\n'))
- eq({null_string, '\n', '\n', null_string, '\n', '\n', null_string}, lst2tbl(l))
+ eq({ null_string, '\n', '\n', null_string, '\n', '\n', null_string }, lst2tbl(l))
end)
itp('writes string containing a single NL twice', function()
local l = list()
eq(0, encode_list_write(l, '\n'))
- eq({null_string, null_string}, lst2tbl(l))
+ eq({ null_string, null_string }, lst2tbl(l))
eq(0, encode_list_write(l, '\n'))
- eq({null_string, null_string, null_string}, lst2tbl(l))
+ eq({ null_string, null_string, null_string }, lst2tbl(l))
end)
itp('writes string containing a few NLs twice', function()
local l = list()
eq(0, encode_list_write(l, '\n\n\n'))
- eq({null_string, null_string, null_string, null_string}, lst2tbl(l))
+ eq({ null_string, null_string, null_string, null_string }, lst2tbl(l))
eq(0, encode_list_write(l, '\n\n\n'))
- eq({null_string, null_string, null_string, null_string, null_string, null_string, null_string}, lst2tbl(l))
+ eq(
+ { null_string, null_string, null_string, null_string, null_string, null_string, null_string },
+ lst2tbl(l)
+ )
end)
end)
diff --git a/test/unit/eval/helpers.lua b/test/unit/eval/helpers.lua
index 883f01bd84..6402e1f8c9 100644
--- a/test/unit/eval/helpers.lua
+++ b/test/unit/eval/helpers.lua
@@ -6,21 +6,25 @@ local to_cstr = helpers.to_cstr
local ffi = helpers.ffi
local eq = helpers.eq
-local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h',
- './src/nvim/hashtab.h', './src/nvim/memory.h')
-
-local null_string = {[true]='NULL string'}
-local null_list = {[true]='NULL list'}
-local null_dict = {[true]='NULL dict'}
-local type_key = {[true]='type key'}
-local locks_key = {[true]='locks key'}
-local list_type = {[true]='list type'}
-local dict_type = {[true]='dict type'}
-local func_type = {[true]='func type'}
-local int_type = {[true]='int type'}
-local flt_type = {[true]='flt type'}
-
-local nil_value = {[true]='nil'}
+local eval = cimport(
+ './src/nvim/eval.h',
+ './src/nvim/eval/typval.h',
+ './src/nvim/hashtab.h',
+ './src/nvim/memory.h'
+)
+
+local null_string = { [true] = 'NULL string' }
+local null_list = { [true] = 'NULL list' }
+local null_dict = { [true] = 'NULL dict' }
+local type_key = { [true] = 'type key' }
+local locks_key = { [true] = 'locks key' }
+local list_type = { [true] = 'list type' }
+local dict_type = { [true] = 'dict type' }
+local func_type = { [true] = 'func type' }
+local int_type = { [true] = 'int type' }
+local flt_type = { [true] = 'flt type' }
+
+local nil_value = { [true] = 'nil' }
local lua2typvalt
@@ -35,11 +39,13 @@ end
local function li_alloc(nogc)
local gcfunc = tv_list_item_free
- if nogc then gcfunc = nil end
+ if nogc then
+ gcfunc = nil
+ end
local li = ffi.gc(tv_list_item_alloc(), gcfunc)
li.li_next = nil
li.li_prev = nil
- li.li_tv = {v_type=eval.VAR_UNKNOWN, v_lock=eval.VAR_UNLOCKED}
+ li.li_tv = { v_type = eval.VAR_UNKNOWN, v_lock = eval.VAR_UNLOCKED }
return li
end
@@ -121,11 +127,11 @@ local function partial2lua(pt, processed)
end
end
return {
- [type_key]=func_type,
- value=value,
- auto=auto,
- args=argv,
- dict=dict,
+ [type_key] = func_type,
+ value = value,
+ auto = auto,
+ args = argv,
+ dict = dict,
}
end
@@ -148,7 +154,7 @@ local function typvalt2lua_tab_init()
})[tonumber(t.vval.v_special)]
end,
[tonumber(eval.VAR_NUMBER)] = function(t)
- return {[type_key]=int_type, value=tonumber(t.vval.v_number)}
+ return { [type_key] = int_type, value = tonumber(t.vval.v_number) }
end,
[tonumber(eval.VAR_FLOAT)] = function(t)
return tonumber(t.vval.v_float)
@@ -168,7 +174,7 @@ local function typvalt2lua_tab_init()
return dct2tbl(t.vval.v_dict, processed)
end,
[tonumber(eval.VAR_FUNC)] = function(t, processed)
- return {[type_key]=func_type, value=typvalt2lua_tab[eval.VAR_STRING](t, processed or {})}
+ return { [type_key] = func_type, value = typvalt2lua_tab[eval.VAR_STRING](t, processed or {}) }
end,
[tonumber(eval.VAR_PARTIAL)] = function(t, processed)
local p_key = ptr2key(t)
@@ -182,15 +188,17 @@ end
typvalt2lua = function(t, processed)
typvalt2lua_tab_init()
- return ((typvalt2lua_tab[tonumber(t.v_type)] or function(t_inner)
- assert(false, 'Converting ' .. tonumber(t_inner.v_type) .. ' was not implemented yet')
- end)(t, processed or {}))
+ return (
+ (typvalt2lua_tab[tonumber(t.v_type)] or function(t_inner)
+ assert(false, 'Converting ' .. tonumber(t_inner.v_type) .. ' was not implemented yet')
+ end)(t, processed or {})
+ )
end
local function list_iter(l)
local init_s = {
- idx=0,
- li=l.lv_first,
+ idx = 0,
+ li = l.lv_first,
}
local function f(s, _)
-- (listitem_T *) NULL is equal to nil, but yet it is not false.
@@ -222,7 +230,7 @@ lst2tbl = function(l, processed)
if processed[p_key] then
return processed[p_key]
end
- local ret = {[type_key]=list_type}
+ local ret = { [type_key] = list_type }
processed[p_key] = ret
for i, li in list_iter(l) do
ret[i] = typvalt2lua(li.li_tv, processed)
@@ -238,11 +246,13 @@ local hi_key_removed = nil
local function dict_iter(d, return_hi)
hi_key_removed = hi_key_removed or eval._hash_key_removed()
local init_s = {
- todo=d.dv_hashtab.ht_used,
- hi=d.dv_hashtab.ht_array,
+ todo = d.dv_hashtab.ht_used,
+ hi = d.dv_hashtab.ht_array,
}
local function f(s, _)
- if s.todo == 0 then return nil end
+ if s.todo == 0 then
+ return nil
+ end
while s.todo > 0 do
if s.hi.hi_key ~= nil and s.hi.hi_key ~= hi_key_removed then
local key = ffi.string(s.hi.hi_key)
@@ -250,8 +260,7 @@ local function dict_iter(d, return_hi)
if return_hi then
ret = s.hi
else
- ret = ffi.cast('dictitem_T*',
- s.hi.hi_key - ffi.offsetof('dictitem_T', 'di_key'))
+ ret = ffi.cast('dictitem_T*', s.hi.hi_key - ffi.offsetof('dictitem_T', 'di_key'))
end
s.todo = s.todo - 1
s.hi = s.hi + 1
@@ -269,7 +278,7 @@ local function first_di(d)
end
local function dict_items(d)
- local ret = {[0]=0}
+ local ret = { [0] = 0 }
for k, hi in dict_iter(d) do
ret[k] = hi
ret[0] = ret[0] + 1
@@ -301,12 +310,12 @@ local typvalt = function(typ, vval)
elseif type(typ) == 'string' then
typ = eval[typ]
end
- return ffi.gc(ffi.new('typval_T', {v_type=typ, vval=vval}), eval.tv_clear)
+ return ffi.gc(ffi.new('typval_T', { v_type = typ, vval = vval }), eval.tv_clear)
end
local lua2typvalt_type_tab = {
[int_type] = function(l, _)
- return typvalt(eval.VAR_NUMBER, {v_number=l.value})
+ return typvalt(eval.VAR_NUMBER, { v_number = l.value })
end,
[flt_type] = function(l, processed)
return lua2typvalt(l.value, processed)
@@ -314,31 +323,34 @@ local lua2typvalt_type_tab = {
[list_type] = function(l, processed)
if processed[l] then
processed[l].lv_refcount = processed[l].lv_refcount + 1
- return typvalt(eval.VAR_LIST, {v_list=processed[l]})
+ return typvalt(eval.VAR_LIST, { v_list = processed[l] })
end
local lst = populate_list(eval.tv_list_alloc(#l), l, processed)
- return typvalt(eval.VAR_LIST, {v_list=lst})
+ return typvalt(eval.VAR_LIST, { v_list = lst })
end,
[dict_type] = function(l, processed)
if processed[l] then
processed[l].dv_refcount = processed[l].dv_refcount + 1
- return typvalt(eval.VAR_DICT, {v_dict=processed[l]})
+ return typvalt(eval.VAR_DICT, { v_dict = processed[l] })
end
local dct = populate_dict(eval.tv_dict_alloc(), l, processed)
- return typvalt(eval.VAR_DICT, {v_dict=dct})
+ return typvalt(eval.VAR_DICT, { v_dict = dct })
end,
[func_type] = function(l, processed)
if processed[l] then
processed[l].pt_refcount = processed[l].pt_refcount + 1
- return typvalt(eval.VAR_PARTIAL, {v_partial=processed[l]})
+ return typvalt(eval.VAR_PARTIAL, { v_partial = processed[l] })
end
if l.args or l.dict then
- local pt = populate_partial(ffi.gc(ffi.cast('partial_T*',
- eval.xcalloc(1, ffi.sizeof('partial_T'))), nil), l, processed)
- return typvalt(eval.VAR_PARTIAL, {v_partial=pt})
+ local pt = populate_partial(
+ ffi.gc(ffi.cast('partial_T*', eval.xcalloc(1, ffi.sizeof('partial_T'))), nil),
+ l,
+ processed
+ )
+ return typvalt(eval.VAR_PARTIAL, { v_partial = pt })
else
return typvalt(eval.VAR_FUNC, {
- v_string=eval.xmemdupz(to_cstr(l.value), #l.value)
+ v_string = eval.xmemdupz(to_cstr(l.value), #l.value),
})
end
end,
@@ -349,12 +361,12 @@ local special_vals = nil
lua2typvalt = function(l, processed)
if not special_vals then
special_vals = {
- [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}},
- [true] = {'VAR_BOOL', {v_bool=eval.kBoolVarTrue}},
- [false] = {'VAR_BOOL', {v_bool=eval.kBoolVarFalse}},
+ [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 } },
+ [true] = { 'VAR_BOOL', { v_bool = eval.kBoolVarTrue } },
+ [false] = { 'VAR_BOOL', { v_bool = eval.kBoolVarFalse } },
}
for k, v in pairs(special_vals) do
@@ -382,9 +394,9 @@ lua2typvalt = function(l, processed)
end
end
elseif type(l) == 'number' then
- return typvalt(eval.VAR_FLOAT, {v_float=l})
+ return typvalt(eval.VAR_FLOAT, { v_float = l })
elseif type(l) == 'string' then
- return typvalt(eval.VAR_STRING, {v_string=eval.xmemdupz(to_cstr(l), #l)})
+ return typvalt(eval.VAR_STRING, { v_string = eval.xmemdupz(to_cstr(l), #l) })
elseif type(l) == 'cdata' then
local tv = typvalt(eval.VAR_UNKNOWN)
eval.tv_copy(l, tv)
@@ -408,43 +420,64 @@ local function alloc_len(len, get_ptr)
end
local alloc_logging_helpers = {
- list = function(l) return {func='calloc', args={1, ffi.sizeof('list_T')}, ret=void(l)} end,
- li = function(li) return {func='malloc', args={ffi.sizeof('listitem_T')}, ret=void(li)} end,
- dict = function(d) return {func='calloc', args={1, ffi.sizeof('dict_T')}, ret=void(d)} end,
+ list = function(l)
+ return { func = 'calloc', args = { 1, ffi.sizeof('list_T') }, ret = void(l) }
+ end,
+ li = function(li)
+ return { func = 'malloc', args = { ffi.sizeof('listitem_T') }, ret = void(li) }
+ end,
+ dict = function(d)
+ return { func = 'calloc', args = { 1, ffi.sizeof('dict_T') }, ret = void(d) }
+ end,
di = function(di, size)
- size = alloc_len(size, function() return di.di_key end)
- return {func='malloc', args={ffi.offsetof('dictitem_T', 'di_key') + size + 1}, ret=void(di)}
+ size = alloc_len(size, function()
+ return di.di_key
+ end)
+ return {
+ func = 'malloc',
+ args = { ffi.offsetof('dictitem_T', 'di_key') + size + 1 },
+ ret = void(di),
+ }
end,
str = function(s, size)
- size = alloc_len(size, function() return s end)
- return {func='malloc', args={size + 1}, ret=void(s)}
+ size = alloc_len(size, function()
+ return s
+ end)
+ return { func = 'malloc', args = { size + 1 }, ret = void(s) }
end,
- dwatcher = function(w) return {func='malloc', args={ffi.sizeof('DictWatcher')}, ret=void(w)} end,
+ dwatcher = function(w)
+ return { func = 'malloc', args = { ffi.sizeof('DictWatcher') }, ret = void(w) }
+ end,
- freed = function(p) return {func='free', args={type(p) == 'table' and p or void(p)}} end,
+ freed = function(p)
+ return { func = 'free', args = { type(p) == 'table' and p or void(p) } }
+ end,
-- lua_…: allocated by this file, not by some Neovim function
- lua_pt = function(pt) return {func='calloc', args={1, ffi.sizeof('partial_T')}, ret=void(pt)} end,
+ lua_pt = function(pt)
+ return { func = 'calloc', args = { 1, ffi.sizeof('partial_T') }, ret = void(pt) }
+ end,
lua_tvs = function(argv, argc)
argc = alloc_len(argc)
- return {func='malloc', args={ffi.sizeof('typval_T')*argc}, ret=void(argv)}
+ return { func = 'malloc', args = { ffi.sizeof('typval_T') * argc }, ret = void(argv) }
end,
}
local function int(n)
- return {[type_key]=int_type, value=n}
+ return { [type_key] = int_type, value = n }
end
local function list(...)
- return populate_list(ffi.gc(eval.tv_list_alloc(select('#', ...)),
- eval.tv_list_unref),
- {...}, {})
+ return populate_list(
+ ffi.gc(eval.tv_list_alloc(select('#', ...)), eval.tv_list_unref),
+ { ... },
+ {}
+ )
end
local function dict(d)
- return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free),
- d or {}, {})
+ return populate_dict(ffi.gc(eval.tv_dict_alloc(), eval.tv_dict_free), d or {}, {})
end
local callback2tbl_type_tab = nil
@@ -454,14 +487,16 @@ local function init_callback2tbl_type_tab()
return
end
callback2tbl_type_tab = {
- [tonumber(eval.kCallbackNone)] = function(_) return {type='none'} end,
+ [tonumber(eval.kCallbackNone)] = function(_)
+ return { type = 'none' }
+ end,
[tonumber(eval.kCallbackFuncref)] = function(cb)
- return {type='fref', fref=ffi.string(cb.data.funcref)}
+ return { type = 'fref', fref = ffi.string(cb.data.funcref) }
end,
[tonumber(eval.kCallbackPartial)] = function(cb)
local lua_pt = partial2lua(cb.data.partial)
- return {type='pt', fref=ffi.string(lua_pt.value), pt=lua_pt}
- end
+ return { type = 'pt', fref = ffi.string(lua_pt.value), pt = lua_pt }
+ end,
}
end
@@ -473,15 +508,18 @@ end
local function tbl2callback(tbl)
local ret = nil
if tbl.type == 'none' then
- ret = ffi.new('Callback[1]', {{type=eval.kCallbackNone}})
+ ret = ffi.new('Callback[1]', { { type = eval.kCallbackNone } })
elseif tbl.type == 'fref' then
- ret = ffi.new('Callback[1]', {{type=eval.kCallbackFuncref,
- data={funcref=eval.xstrdup(tbl.fref)}}})
+ ret = ffi.new(
+ 'Callback[1]',
+ { { type = eval.kCallbackFuncref, data = { funcref = eval.xstrdup(tbl.fref) } } }
+ )
elseif tbl.type == 'pt' then
- local pt = ffi.gc(ffi.cast('partial_T*',
- eval.xcalloc(1, ffi.sizeof('partial_T'))), nil)
- ret = ffi.new('Callback[1]', {{type=eval.kCallbackPartial,
- data={partial=populate_partial(pt, tbl.pt, {})}}})
+ local pt = ffi.gc(ffi.cast('partial_T*', eval.xcalloc(1, ffi.sizeof('partial_T'))), nil)
+ ret = ffi.new(
+ 'Callback[1]',
+ { { type = eval.kCallbackPartial, data = { partial = populate_partial(pt, tbl.pt, {}) } } }
+ )
else
assert(false)
end
@@ -495,24 +533,23 @@ local function dict_watchers(d)
local qs = {}
local key_patterns = {}
while q ~= h do
- local qitem = ffi.cast('DictWatcher *',
- ffi.cast('char *', q) - ffi.offsetof('DictWatcher', 'node'))
+ local qitem =
+ ffi.cast('DictWatcher *', ffi.cast('char *', q) - ffi.offsetof('DictWatcher', 'node'))
ret[#ret + 1] = {
- cb=callback2tbl(qitem.callback),
- pat=ffi.string(qitem.key_pattern, qitem.key_pattern_len),
- busy=qitem.busy,
+ cb = callback2tbl(qitem.callback),
+ pat = ffi.string(qitem.key_pattern, qitem.key_pattern_len),
+ busy = qitem.busy,
}
qs[#qs + 1] = qitem
- key_patterns[#key_patterns + 1] = {qitem.key_pattern, qitem.key_pattern_len}
+ key_patterns[#key_patterns + 1] = { qitem.key_pattern, qitem.key_pattern_len }
q = q.next
end
return ret, qs, key_patterns
end
local function eval0(expr)
- local tv = ffi.gc(ffi.new('typval_T', {v_type=eval.VAR_UNKNOWN}),
- eval.tv_clear)
- local evalarg = ffi.new('evalarg_T', {eval_flags = eval.EVAL_EVALUATE})
+ local tv = ffi.gc(ffi.new('typval_T', { v_type = eval.VAR_UNKNOWN }), eval.tv_clear)
+ 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
@@ -521,49 +558,49 @@ local function eval0(expr)
end
return {
- int=int,
+ int = int,
- null_string=null_string,
- null_list=null_list,
- null_dict=null_dict,
- list_type=list_type,
- dict_type=dict_type,
- func_type=func_type,
- int_type=int_type,
- flt_type=flt_type,
+ null_string = null_string,
+ null_list = null_list,
+ null_dict = null_dict,
+ list_type = list_type,
+ dict_type = dict_type,
+ func_type = func_type,
+ int_type = int_type,
+ flt_type = flt_type,
- nil_value=nil_value,
+ nil_value = nil_value,
- type_key=type_key,
- locks_key=locks_key,
+ type_key = type_key,
+ locks_key = locks_key,
- list=list,
- dict=dict,
- lst2tbl=lst2tbl,
- dct2tbl=dct2tbl,
+ list = list,
+ dict = dict,
+ lst2tbl = lst2tbl,
+ dct2tbl = dct2tbl,
- lua2typvalt=lua2typvalt,
- typvalt2lua=typvalt2lua,
+ lua2typvalt = lua2typvalt,
+ typvalt2lua = typvalt2lua,
- typvalt=typvalt,
+ typvalt = typvalt,
- li_alloc=li_alloc,
- tv_list_item_free=tv_list_item_free,
+ li_alloc = li_alloc,
+ tv_list_item_free = tv_list_item_free,
- dict_iter=dict_iter,
- list_iter=list_iter,
- first_di=first_di,
+ dict_iter = dict_iter,
+ list_iter = list_iter,
+ first_di = first_di,
- alloc_logging_helpers=alloc_logging_helpers,
+ alloc_logging_helpers = alloc_logging_helpers,
- list_items=list_items,
- dict_items=dict_items,
+ list_items = list_items,
+ dict_items = dict_items,
- dict_watchers=dict_watchers,
- tbl2callback=tbl2callback,
- callback2tbl=callback2tbl,
+ dict_watchers = dict_watchers,
+ tbl2callback = tbl2callback,
+ callback2tbl = callback2tbl,
- eval0=eval0,
+ eval0 = eval0,
- empty_list = {[type_key]=list_type},
+ empty_list = { [type_key] = list_type },
}
diff --git a/test/unit/eval/tricks_spec.lua b/test/unit/eval/tricks_spec.lua
index 7aa0f0f6e6..ed26fd44e4 100644
--- a/test/unit/eval/tricks_spec.lua
+++ b/test/unit/eval/tricks_spec.lua
@@ -8,8 +8,7 @@ local eq = helpers.eq
local eval0 = eval_helpers.eval0
-local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h',
- './src/nvim/memory.h')
+local eval = cimport('./src/nvim/eval.h', './src/nvim/eval/typval.h', './src/nvim/memory.h')
describe('NULL typval_T', function()
itp('is produced by $XXX_UNEXISTENT_VAR_XXX', function()
diff --git a/test/unit/eval/tv_clear_spec.lua b/test/unit/eval/tv_clear_spec.lua
index ca37301b32..a34cf6082a 100644
--- a/test/unit/eval/tv_clear_spec.lua
+++ b/test/unit/eval/tv_clear_spec.lua
@@ -28,8 +28,8 @@ end)
describe('tv_clear()', function()
itp('successfully frees all lists in [&l [1], *l, *l]', function()
- local l_inner = {1}
- local list = {l_inner, l_inner, l_inner}
+ local l_inner = { 1 }
+ local list = { l_inner, l_inner, l_inner }
local list_tv = ffi.gc(lua2typvalt(list), nil)
local list_p = list_tv.vval.v_list
local lis = list_items(list_p)
@@ -55,8 +55,8 @@ describe('tv_clear()', function()
})
end)
itp('successfully frees all lists in [&l [], *l, *l]', function()
- local l_inner = {[type_key]=list_type}
- local list = {l_inner, l_inner, l_inner}
+ local l_inner = { [type_key] = list_type }
+ local list = { l_inner, l_inner, l_inner }
local list_tv = ffi.gc(lua2typvalt(list), nil)
local list_p = list_tv.vval.v_list
local lis = list_items(list_p)
@@ -80,7 +80,7 @@ describe('tv_clear()', function()
end)
itp('successfully frees all dictionaries in [&d {}, *d]', function()
local d_inner = {}
- local list = {d_inner, d_inner}
+ local list = { d_inner, d_inner }
local list_tv = ffi.gc(lua2typvalt(list), nil)
local list_p = list_tv.vval.v_list
local lis = list_items(list_p)
@@ -101,8 +101,8 @@ describe('tv_clear()', function()
})
end)
itp('successfully frees all dictionaries in [&d {a: 1}, *d]', function()
- local d_inner = {a=1}
- local list = {d_inner, d_inner}
+ local d_inner = { a = 1 }
+ local list = { d_inner, d_inner }
local list_tv = ffi.gc(lua2typvalt(list), nil)
local list_p = list_tv.vval.v_list
local lis = list_items(list_p)
diff --git a/test/unit/eval/typval_spec.lua b/test/unit/eval/typval_spec.lua
index 34a1299725..6edd164438 100644
--- a/test/unit/eval/typval_spec.lua
+++ b/test/unit/eval/typval_spec.lua
@@ -14,7 +14,7 @@ local cimport = helpers.cimport
local to_cstr = helpers.to_cstr
local alloc_log_new = helpers.alloc_log_new
local concat_tables = helpers.concat_tables
-local map = helpers.tbl_map
+local map = vim.tbl_map
local a = eval_helpers.alloc_logging_helpers
local int = eval_helpers.int
@@ -41,21 +41,25 @@ local callback2tbl = eval_helpers.callback2tbl
local tbl2callback = eval_helpers.tbl2callback
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_defs.h',
- './src/nvim/globals.h')
+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_defs.h',
+ './src/nvim/globals.h'
+)
local function vimconv_alloc()
- return ffi.gc(
- ffi.cast('vimconv_T*', lib.xcalloc(1, ffi.sizeof('vimconv_T'))), function(vc)
- lib.convert_setup(vc, nil, nil)
- lib.xfree(vc)
- end)
+ return ffi.gc(ffi.cast('vimconv_T*', lib.xcalloc(1, ffi.sizeof('vimconv_T'))), function(vc)
+ lib.convert_setup(vc, nil, nil)
+ lib.xfree(vc)
+ end)
end
local function list_watch_alloc(li)
- return ffi.cast('listwatch_T*', ffi.new('listwatch_T[1]', {{lw_item=li}}))
+ return ffi.cast('listwatch_T*', ffi.new('listwatch_T[1]', { { lw_item = li } }))
end
local function list_watch(l, li)
@@ -66,12 +70,14 @@ end
local function get_alloc_rets(exp_log, res)
setmetatable(res, {
- __index={
- freed=function(r, n) return {func='free', args={r[n]}} end
- }
+ __index = {
+ freed = function(r, n)
+ return { func = 'free', args = { r[n] } }
+ end,
+ },
})
- for i = 1,#exp_log do
- if ({malloc=true, calloc=true})[exp_log[i].func] then
+ for i = 1, #exp_log do
+ if ({ malloc = true, calloc = true })[exp_log[i].func] then
res[#res + 1] = exp_log[i].ret
end
end
@@ -89,8 +95,7 @@ after_each(function()
end)
local function ga_alloc(itemsize, growsize)
- local ga = ffi.gc(ffi.cast('garray_T*', ffi.new('garray_T[1]', {})),
- lib.ga_clear)
+ local ga = ffi.gc(ffi.cast('garray_T*', ffi.new('garray_T[1]', {})), lib.ga_clear)
lib.ga_init(ga, itemsize or 1, growsize or 80)
return ga
end
@@ -100,7 +105,7 @@ local function check_emsg(f, msg)
if saved_last_msg_hist == nil then
saved_last_msg_hist = nil
end
- local ret = {f()}
+ 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, last_msg)
@@ -167,8 +172,9 @@ describe('typval.c', function()
a.str(lis[4].li_tv.vval.v_string, 1),
a.li(lis[4]),
})
- local strings = map(function(li) return li.li_tv.vval.v_string end,
- lis)
+ local strings = map(function(li)
+ return li.li_tv.vval.v_string
+ end, lis)
eq(lis[2], lib.tv_list_item_remove(l, lis[1]))
alloc_log:check({
@@ -213,20 +219,26 @@ describe('typval.c', function()
})
eq(lis[5], lib.tv_list_item_remove(l, lis[4]))
- alloc_log:check({a.freed(lis[4])})
- eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item})
+ alloc_log:check({ a.freed(lis[4]) })
+ eq({ lis[1], lis[5], lis[7] }, { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item })
eq(lis[3], lib.tv_list_item_remove(l, lis[2]))
- alloc_log:check({a.freed(lis[2])})
- eq({lis[1], lis[5], lis[7]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item})
+ alloc_log:check({ a.freed(lis[2]) })
+ eq({ lis[1], lis[5], lis[7] }, { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item })
eq(nil, lib.tv_list_item_remove(l, lis[7]))
- alloc_log:check({a.freed(lis[7])})
- eq({lis[1], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil})
+ alloc_log:check({ a.freed(lis[7]) })
+ eq(
+ { lis[1], lis[5], nil },
+ { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil }
+ )
eq(lis[3], lib.tv_list_item_remove(l, lis[1]))
- alloc_log:check({a.freed(lis[1])})
- eq({lis[3], lis[5], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil})
+ alloc_log:check({ a.freed(lis[1]) })
+ eq(
+ { lis[3], lis[5], nil },
+ { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil }
+ )
lib.tv_list_watch_remove(l, lws[2])
lib.tv_list_watch_remove(l, lws[3])
@@ -285,7 +297,7 @@ describe('typval.c', function()
alloc_log:check(get_alloc_rets({
a.list(l1),
a.li(l1.lv_first),
- a.str(l1.lv_last.li_tv.vval.v_string, #('abc')),
+ a.str(l1.lv_last.li_tv.vval.v_string, #'abc'),
a.li(l1.lv_last),
a.list(l2),
a.dict(l2.lv_first.li_tv.vval.v_dict),
@@ -324,7 +336,7 @@ describe('typval.c', function()
alloc_log:check(get_alloc_rets({
a.list(l1),
a.li(l1.lv_first),
- a.str(l1.lv_last.li_tv.vval.v_string, #('abc')),
+ a.str(l1.lv_last.li_tv.vval.v_string, #'abc'),
a.li(l1.lv_last),
a.list(l2),
a.dict(l2.lv_first.li_tv.vval.v_dict),
@@ -348,8 +360,7 @@ describe('typval.c', function()
end)
end)
describe('free_contents()', function()
- itp('recursively frees list, except for the list structure itself',
- function()
+ itp('recursively frees list, except for the list structure itself', function()
local l1 = ffi.gc(list(1, 'abc'), nil)
local l2 = ffi.gc(list({}), nil)
local l3 = ffi.gc(list(empty_list), nil)
@@ -357,7 +368,7 @@ describe('typval.c', function()
alloc_log:check(get_alloc_rets({
a.list(l1),
a.li(l1.lv_first),
- a.str(l1.lv_last.li_tv.vval.v_string, #('abc')),
+ a.str(l1.lv_last.li_tv.vval.v_string, #'abc'),
a.li(l1.lv_last),
a.list(l2),
a.dict(l2.lv_first.li_tv.vval.v_dict),
@@ -406,7 +417,7 @@ describe('typval.c', function()
end)
describe('drop_items()', function()
itp('works', function()
- local l_tv = lua2typvalt({1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13})
+ local l_tv = lua2typvalt({ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 })
local l = l_tv.vval.v_list
local lis = list_items(l)
-- Three watchers: pointing to first, middle and last elements.
@@ -418,20 +429,29 @@ describe('typval.c', function()
alloc_log:clear()
lib.tv_list_drop_items(l, lis[1], lis[3])
- eq({4, 5, 6, 7, 8, 9, 10, 11, 12, 13}, typvalt2lua(l_tv))
- eq({lis[4], lis[7], lis[13]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item})
+ eq({ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 }, typvalt2lua(l_tv))
+ eq({ lis[4], lis[7], lis[13] }, { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item })
lib.tv_list_drop_items(l, lis[11], lis[13])
- eq({4, 5, 6, 7, 8, 9, 10}, typvalt2lua(l_tv))
- eq({lis[4], lis[7], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil})
+ eq({ 4, 5, 6, 7, 8, 9, 10 }, typvalt2lua(l_tv))
+ eq(
+ { lis[4], lis[7], nil },
+ { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil }
+ )
lib.tv_list_drop_items(l, lis[6], lis[8])
- eq({4, 5, 9, 10}, typvalt2lua(l_tv))
- eq({lis[4], lis[9], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil})
+ eq({ 4, 5, 9, 10 }, typvalt2lua(l_tv))
+ eq(
+ { lis[4], lis[9], nil },
+ { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil }
+ )
lib.tv_list_drop_items(l, lis[4], lis[10])
eq(empty_list, typvalt2lua(l_tv))
- eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil})
+ eq(
+ { true, true, true },
+ { lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil }
+ )
lib.tv_list_watch_remove(l, lws[1])
lib.tv_list_watch_remove(l, lws[2])
@@ -442,10 +462,13 @@ describe('typval.c', function()
end)
describe('remove_items()', function()
itp('works', function()
- local l_tv = lua2typvalt({'1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13'})
+ local l_tv =
+ lua2typvalt({ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13' })
local l = l_tv.vval.v_list
local lis = list_items(l)
- local strings = map(function(li) return li.li_tv.vval.v_string end, lis)
+ local strings = map(function(li)
+ return li.li_tv.vval.v_string
+ end, lis)
-- Three watchers: pointing to first, middle and last elements.
local lws = {
list_watch(l, lis[1]),
@@ -455,8 +478,8 @@ describe('typval.c', function()
alloc_log:clear()
lib.tv_list_remove_items(l, lis[1], lis[3])
- eq({'4', '5', '6', '7', '8', '9', '10', '11', '12', '13'}, typvalt2lua(l_tv))
- eq({lis[4], lis[7], lis[13]}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item})
+ eq({ '4', '5', '6', '7', '8', '9', '10', '11', '12', '13' }, typvalt2lua(l_tv))
+ eq({ lis[4], lis[7], lis[13] }, { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item })
alloc_log:check({
a.freed(strings[1]),
a.freed(lis[1]),
@@ -467,8 +490,11 @@ describe('typval.c', function()
})
lib.tv_list_remove_items(l, lis[11], lis[13])
- eq({'4', '5', '6', '7', '8', '9', '10'}, typvalt2lua(l_tv))
- eq({lis[4], lis[7], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil})
+ eq({ '4', '5', '6', '7', '8', '9', '10' }, typvalt2lua(l_tv))
+ eq(
+ { lis[4], lis[7], nil },
+ { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil }
+ )
alloc_log:check({
a.freed(strings[11]),
a.freed(lis[11]),
@@ -479,8 +505,11 @@ describe('typval.c', function()
})
lib.tv_list_remove_items(l, lis[6], lis[8])
- eq({'4', '5', '9', '10'}, typvalt2lua(l_tv))
- eq({lis[4], lis[9], nil}, {lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil})
+ eq({ '4', '5', '9', '10' }, typvalt2lua(l_tv))
+ eq(
+ { lis[4], lis[9], nil },
+ { lws[1].lw_item, lws[2].lw_item, lws[3].lw_item == nil and nil }
+ )
alloc_log:check({
a.freed(strings[6]),
a.freed(lis[6]),
@@ -492,7 +521,10 @@ describe('typval.c', function()
lib.tv_list_remove_items(l, lis[4], lis[10])
eq(empty_list, typvalt2lua(l_tv))
- eq({true, true, true}, {lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil})
+ eq(
+ { true, true, true },
+ { lws[1].lw_item == nil, lws[2].lw_item == nil, lws[3].lw_item == nil }
+ )
alloc_log:check({
a.freed(strings[4]),
a.freed(lis[4]),
@@ -514,28 +546,28 @@ describe('typval.c', function()
describe('insert', function()
describe('()', function()
itp('works', function()
- local l_tv = lua2typvalt({1, 2, 3, 4, 5, 6, 7})
+ local l_tv = lua2typvalt({ 1, 2, 3, 4, 5, 6, 7 })
local l = l_tv.vval.v_list
local lis = list_items(l)
local li
li = li_alloc(true)
- li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}}
+ li.li_tv = { v_type = lib.VAR_FLOAT, vval = { v_float = 100500 } }
lib.tv_list_insert(l, li, nil)
eq(l.lv_last, li)
- eq({1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv))
+ eq({ 1, 2, 3, 4, 5, 6, 7, 100500 }, typvalt2lua(l_tv))
li = li_alloc(true)
- li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=0}}
+ li.li_tv = { v_type = lib.VAR_FLOAT, vval = { v_float = 0 } }
lib.tv_list_insert(l, li, lis[1])
eq(l.lv_first, li)
- eq({0, 1, 2, 3, 4, 5, 6, 7, 100500}, typvalt2lua(l_tv))
+ eq({ 0, 1, 2, 3, 4, 5, 6, 7, 100500 }, typvalt2lua(l_tv))
li = li_alloc(true)
- li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=4.5}}
+ li.li_tv = { v_type = lib.VAR_FLOAT, vval = { v_float = 4.5 } }
lib.tv_list_insert(l, li, lis[5])
eq(list_items(l)[6], li)
- eq({0, 1, 2, 3, 4, 4.5, 5, 6, 7, 100500}, typvalt2lua(l_tv))
+ eq({ 0, 1, 2, 3, 4, 4.5, 5, 6, 7, 100500 }, typvalt2lua(l_tv))
end)
itp('works with an empty list', function()
local l_tv = lua2typvalt(empty_list)
@@ -545,10 +577,10 @@ describe('typval.c', function()
eq(nil, l.lv_last)
local li = li_alloc(true)
- li.li_tv = {v_type=lib.VAR_FLOAT, vval={v_float=100500}}
+ li.li_tv = { v_type = lib.VAR_FLOAT, vval = { v_float = 100500 } }
lib.tv_list_insert(l, li, nil)
eq(l.lv_last, li)
- eq({100500}, typvalt2lua(l_tv))
+ eq({ 100500 }, typvalt2lua(l_tv))
end)
end)
describe('tv()', function()
@@ -577,7 +609,7 @@ describe('typval.c', function()
a.str(l.lv_first.li_tv.vval.v_string, 'test'),
})
- eq({'test', empty_list}, typvalt2lua(l_tv))
+ eq({ 'test', empty_list }, typvalt2lua(l_tv))
end)
end)
end)
@@ -602,7 +634,7 @@ describe('typval.c', function()
a.li(l.lv_last),
})
- eq({{1}, null_list}, typvalt2lua(l_tv))
+ eq({ { 1 }, null_list }, typvalt2lua(l_tv))
end)
end)
describe('dict()', function()
@@ -610,7 +642,7 @@ describe('typval.c', function()
local l_tv = lua2typvalt(empty_list)
local l = l_tv.vval.v_list
- local l_d_tv = lua2typvalt({test=1})
+ local l_d_tv = lua2typvalt({ test = 1 })
local l_d = l_d_tv.vval.v_dict
alloc_log:clear()
eq(1, l_d.dv_refcount)
@@ -626,7 +658,7 @@ describe('typval.c', function()
a.li(l.lv_last),
})
- eq({{test=1}, null_dict}, typvalt2lua(l_tv))
+ eq({ { test = 1 }, null_dict }, typvalt2lua(l_tv))
end)
end)
describe('string()', function()
@@ -657,7 +689,7 @@ describe('typval.c', function()
a.li(l.lv_last),
})
- eq({'tes', null_string, null_string, 'test'}, typvalt2lua(l_tv))
+ eq({ 'tes', null_string, null_string, 'test' }, typvalt2lua(l_tv))
end)
end)
describe('allocated string()', function()
@@ -682,7 +714,7 @@ describe('typval.c', function()
a.li(l.lv_last),
})
- eq({'test', null_string, null_string}, typvalt2lua(l_tv))
+ eq({ 'test', null_string, null_string }, typvalt2lua(l_tv))
end)
end)
describe('number()', function()
@@ -701,7 +733,7 @@ describe('typval.c', function()
a.li(l.lv_last),
})
- eq({int(-100500), int(100500)}, typvalt2lua(l_tv))
+ eq({ int(-100500), int(100500) }, typvalt2lua(l_tv))
end)
end)
describe('tv()', function()
@@ -730,7 +762,7 @@ describe('typval.c', function()
a.str(l.lv_last.li_tv.vval.v_string, 'test'),
})
- eq({empty_list, 'test'}, typvalt2lua(l_tv))
+ eq({ empty_list, 'test' }, typvalt2lua(l_tv))
end)
end)
describe('owned tv()', function()
@@ -761,7 +793,7 @@ describe('typval.c', function()
a.li(l.lv_last),
})
- eq({empty_list, 'test'}, typvalt2lua(l_tv))
+ eq({ empty_list, 'test' }, typvalt2lua(l_tv))
end)
end)
end)
@@ -777,7 +809,7 @@ describe('typval.c', function()
end)
itp('copies list correctly without converting items', function()
do
- local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict}
+ local v = { { ['«'] = '»' }, { '„' }, 1, '“', null_string, null_list, null_dict }
local l_tv = lua2typvalt(v)
local l = l_tv.vval.v_list
local lis = list_items(l)
@@ -821,7 +853,7 @@ describe('typval.c', function()
a.list(l_deepcopy1),
a.li(lis_deepcopy1[1]),
a.dict(lis_deepcopy1[1].li_tv.vval.v_dict),
- a.di(di_deepcopy1, #('«')),
+ a.di(di_deepcopy1, #'«'),
a.str(di_deepcopy1.di_tv.vval.v_string, #v[1]['«']),
a.li(lis_deepcopy1[2]),
a.list(lis_deepcopy1[2].li_tv.vval.v_list),
@@ -842,7 +874,7 @@ describe('typval.c', function()
-- UTF-8 ↔ latin1 conversions needs no iconv
eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1')))
- local v = {{['«']='»'}, {'„'}, 1, '“', null_string, null_list, null_dict}
+ local v = { { ['«'] = '»' }, { '„' }, 1, '“', null_string, null_list, null_dict }
local l_tv = lua2typvalt(v)
local l = l_tv.vval.v_list
local lis = list_items(l)
@@ -857,8 +889,10 @@ describe('typval.c', function()
local lis_deepcopy1 = list_items(l_deepcopy1)
neq(lis[1].li_tv.vval.v_dict, lis_deepcopy1[1].li_tv.vval.v_dict)
neq(lis[2].li_tv.vval.v_list, lis_deepcopy1[2].li_tv.vval.v_list)
- eq({{['\171']='\187'}, {'\191'}, 1, '\191', null_string, null_list, null_dict},
- lst2tbl(l_deepcopy1))
+ eq(
+ { { ['\171'] = '\187' }, { '\191' }, 1, '\191', null_string, null_list, null_dict },
+ lst2tbl(l_deepcopy1)
+ )
local di_deepcopy1 = first_di(lis_deepcopy1[1].li_tv.vval.v_dict)
alloc_log:clear_tmp_allocs()
alloc_log:check({
@@ -881,18 +915,18 @@ describe('typval.c', function()
end)
itp('returns different/same containers with(out) copyID', function()
local l_inner_tv = lua2typvalt(empty_list)
- local l_tv = lua2typvalt({l_inner_tv, l_inner_tv})
+ local l_tv = lua2typvalt({ l_inner_tv, l_inner_tv })
eq(3, l_inner_tv.vval.v_list.lv_refcount)
local l = l_tv.vval.v_list
eq(l.lv_first.li_tv.vval.v_list, l.lv_last.li_tv.vval.v_list)
local l_copy1 = tv_list_copy(nil, l, true, 0)
neq(l_copy1.lv_first.li_tv.vval.v_list, l_copy1.lv_last.li_tv.vval.v_list)
- eq({empty_list, empty_list}, lst2tbl(l_copy1))
+ eq({ empty_list, empty_list }, lst2tbl(l_copy1))
local l_copy2 = tv_list_copy(nil, l, true, 2)
eq(l_copy2.lv_first.li_tv.vval.v_list, l_copy2.lv_last.li_tv.vval.v_list)
- eq({empty_list, empty_list}, lst2tbl(l_copy2))
+ eq({ empty_list, empty_list }, lst2tbl(l_copy2))
eq(3, l_inner_tv.vval.v_list.lv_refcount)
end)
@@ -934,7 +968,7 @@ describe('typval.c', function()
})
eq(1, l.lv_refcount)
eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount)
- eq({1, {}, 1, {}}, lst2tbl(l))
+ eq({ 1, {}, 1, {} }, lst2tbl(l))
l = list(1, {})
alloc_log:clear()
@@ -946,7 +980,7 @@ describe('typval.c', function()
a.li(l.lv_last.li_prev.li_prev),
a.li(l.lv_last.li_prev),
})
- eq({1, 1, {}, {}}, lst2tbl(l))
+ eq({ 1, 1, {}, {} }, lst2tbl(l))
eq(1, l.lv_refcount)
eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount)
@@ -960,7 +994,7 @@ describe('typval.c', function()
a.li(l.lv_first),
a.li(l.lv_first.li_next),
})
- eq({1, {}, 1, {}}, lst2tbl(l))
+ eq({ 1, {}, 1, {} }, lst2tbl(l))
eq(1, l.lv_refcount)
eq(2, l.lv_last.li_tv.vval.v_dict.dv_refcount)
end)
@@ -973,28 +1007,25 @@ describe('typval.c', function()
eq(1, el.lv_refcount)
lib.tv_list_extend(l, el, nil)
- alloc_log:check({
- })
+ alloc_log:check({})
eq(1, l.lv_refcount)
eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount)
eq(1, el.lv_refcount)
- eq({1, {}}, lst2tbl(l))
+ eq({ 1, {} }, lst2tbl(l))
lib.tv_list_extend(l, el, l.lv_first)
- alloc_log:check({
- })
+ alloc_log:check({})
eq(1, l.lv_refcount)
eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount)
eq(1, el.lv_refcount)
- eq({1, {}}, lst2tbl(l))
+ eq({ 1, {} }, lst2tbl(l))
lib.tv_list_extend(l, el, l.lv_last)
- alloc_log:check({
- })
+ alloc_log:check({})
eq(1, l.lv_refcount)
eq(1, l.lv_last.li_tv.vval.v_dict.dv_refcount)
eq(1, el.lv_refcount)
- eq({1, {}}, lst2tbl(l))
+ eq({ 1, {} }, lst2tbl(l))
end)
itp('can extend list with another non-empty list', function()
local l
@@ -1014,7 +1045,7 @@ describe('typval.c', function()
})
eq(1, l2.lv_refcount)
eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount)
- eq({1, {}, 42, empty_list}, lst2tbl(l))
+ eq({ 1, {}, 42, empty_list }, lst2tbl(l))
lib.tv_list_free(l)
eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount)
@@ -1030,7 +1061,7 @@ describe('typval.c', function()
})
eq(1, l2.lv_refcount)
eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount)
- eq({42, empty_list, 1, {}}, lst2tbl(l))
+ eq({ 42, empty_list, 1, {} }, lst2tbl(l))
lib.tv_list_free(l)
eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount)
@@ -1046,7 +1077,7 @@ describe('typval.c', function()
})
eq(1, l2.lv_refcount)
eq(2, l2.lv_last.li_tv.vval.v_list.lv_refcount)
- eq({1, 42, empty_list, {}}, lst2tbl(l))
+ eq({ 1, 42, empty_list, {} }, lst2tbl(l))
lib.tv_list_free(l)
eq(1, l2.lv_last.li_tv.vval.v_list.lv_refcount)
end)
@@ -1062,7 +1093,7 @@ describe('typval.c', function()
eq(OK, lib.tv_list_concat(nil, l, rettv1))
eq(1, l.lv_refcount)
eq(tonumber(lib.VAR_LIST), tonumber(rettv1.v_type))
- eq({1, {}}, typvalt2lua(rettv1))
+ eq({ 1, {} }, typvalt2lua(rettv1))
eq(1, rettv1.vval.v_list.lv_refcount)
alloc_log:check({
a.list(rettv1.vval.v_list),
@@ -1075,7 +1106,7 @@ describe('typval.c', function()
eq(OK, lib.tv_list_concat(l, nil, rettv2))
eq(1, l.lv_refcount)
eq(tonumber(lib.VAR_LIST), tonumber(rettv2.v_type))
- eq({1, {}}, typvalt2lua(rettv2))
+ eq({ 1, {} }, typvalt2lua(rettv2))
eq(1, rettv2.vval.v_list.lv_refcount)
alloc_log:check({
a.list(rettv2.vval.v_list),
@@ -1112,7 +1143,7 @@ describe('typval.c', function()
a.li(rettv.vval.v_list.lv_last.li_prev),
a.li(rettv.vval.v_list.lv_last),
})
- eq({1, {}, 3, empty_list}, typvalt2lua(rettv))
+ eq({ 1, {}, 3, empty_list }, typvalt2lua(rettv))
end)
itp('can concatenate list with itself', function()
local l = list(1, {})
@@ -1131,7 +1162,7 @@ describe('typval.c', function()
a.li(rettv.vval.v_list.lv_last.li_prev),
a.li(rettv.vval.v_list.lv_last),
})
- eq({1, {}, 1, {}}, typvalt2lua(rettv))
+ eq({ 1, {}, 1, {} }, typvalt2lua(rettv))
end)
itp('can concatenate empty non-NULL lists', function()
local l = list(1, {})
@@ -1154,7 +1185,7 @@ describe('typval.c', function()
a.li(rettv1.vval.v_list.lv_first),
a.li(rettv1.vval.v_list.lv_last),
})
- eq({1, {}}, typvalt2lua(rettv1))
+ eq({ 1, {} }, typvalt2lua(rettv1))
local rettv2 = typvalt()
eq(OK, lib.tv_list_concat(le, l, rettv2))
@@ -1167,7 +1198,7 @@ describe('typval.c', function()
a.li(rettv2.vval.v_list.lv_first),
a.li(rettv2.vval.v_list.lv_last),
})
- eq({1, {}}, typvalt2lua(rettv2))
+ eq({ 1, {} }, typvalt2lua(rettv2))
local rettv3 = typvalt()
eq(OK, lib.tv_list_concat(le, le, rettv3))
@@ -1257,15 +1288,15 @@ describe('typval.c', function()
-- indicates that tv_equal_recurse_limit and recursive_cnt were set which
-- is essential. This argument will be set when comparing inner lists.
itp('compares lists correctly when case is not ignored', function()
- local l1 = list('abc', {1, 2, 'Abc'}, 'def')
- local l2 = list('abc', {1, 2, 'Abc'})
- local l3 = list('abc', {1, 2, 'Abc'}, 'Def')
- local l4 = list('abc', {1, 2, 'Abc', 4}, 'def')
- local l5 = list('Abc', {1, 2, 'Abc'}, 'def')
- local l6 = list('abc', {1, 2, 'Abc'}, 'def')
- local l7 = list('abc', {1, 2, 'abc'}, 'def')
+ local l1 = list('abc', { 1, 2, 'Abc' }, 'def')
+ local l2 = list('abc', { 1, 2, 'Abc' })
+ local l3 = list('abc', { 1, 2, 'Abc' }, 'Def')
+ local l4 = list('abc', { 1, 2, 'Abc', 4 }, 'def')
+ local l5 = list('Abc', { 1, 2, 'Abc' }, 'def')
+ local l6 = list('abc', { 1, 2, 'Abc' }, 'def')
+ local l7 = list('abc', { 1, 2, 'abc' }, 'def')
local l8 = list('abc', nil, 'def')
- local l9 = list('abc', {1, 2, nil}, 'def')
+ local l9 = list('abc', { 1, 2, nil }, 'def')
eq(true, lib.tv_list_equal(l1, l1, false, false))
eq(false, lib.tv_list_equal(l1, l2, false, false))
@@ -1278,15 +1309,15 @@ describe('typval.c', function()
eq(false, lib.tv_list_equal(l1, l9, false, false))
end)
itp('compares lists correctly when case is ignored', function()
- local l1 = list('abc', {1, 2, 'Abc'}, 'def')
- local l2 = list('abc', {1, 2, 'Abc'})
- local l3 = list('abc', {1, 2, 'Abc'}, 'Def')
- local l4 = list('abc', {1, 2, 'Abc', 4}, 'def')
- local l5 = list('Abc', {1, 2, 'Abc'}, 'def')
- local l6 = list('abc', {1, 2, 'Abc'}, 'def')
- local l7 = list('abc', {1, 2, 'abc'}, 'def')
+ local l1 = list('abc', { 1, 2, 'Abc' }, 'def')
+ local l2 = list('abc', { 1, 2, 'Abc' })
+ local l3 = list('abc', { 1, 2, 'Abc' }, 'Def')
+ local l4 = list('abc', { 1, 2, 'Abc', 4 }, 'def')
+ local l5 = list('Abc', { 1, 2, 'Abc' }, 'def')
+ local l6 = list('abc', { 1, 2, 'Abc' }, 'def')
+ local l7 = list('abc', { 1, 2, 'abc' }, 'def')
local l8 = list('abc', nil, 'def')
- local l9 = list('abc', {1, 2, nil}, 'def')
+ local l9 = list('abc', { 1, 2, nil }, 'def')
eq(true, lib.tv_list_equal(l1, l1, true, false))
eq(false, lib.tv_list_equal(l1, l2, true, false))
@@ -1355,7 +1386,7 @@ describe('typval.c', function()
describe('nr()', function()
local function tv_list_find_nr(l, n, msg)
return check_emsg(function()
- local err = ffi.new('bool[1]', {false})
+ local err = ffi.new('bool[1]', { false })
local ret = lib.tv_list_find_nr(l, n, err)
return (err[0] == true), ret
end, msg)
@@ -1364,10 +1395,10 @@ describe('typval.c', function()
local l = list(int(1), int(2), int(3), int(4), int(5))
alloc_log:clear()
- eq({false, 1}, {tv_list_find_nr(l, -5)})
- eq({false, 5}, {tv_list_find_nr(l, 4)})
- eq({false, 3}, {tv_list_find_nr(l, 2)})
- eq({false, 3}, {tv_list_find_nr(l, -3)})
+ eq({ false, 1 }, { tv_list_find_nr(l, -5) })
+ eq({ false, 5 }, { tv_list_find_nr(l, 4) })
+ eq({ false, 3 }, { tv_list_find_nr(l, 2) })
+ eq({ false, 3 }, { tv_list_find_nr(l, -3) })
alloc_log:check({})
end)
@@ -1375,10 +1406,10 @@ describe('typval.c', function()
local l = list('1', '2', '3', '4', '5')
alloc_log:clear()
- eq({false, 1}, {tv_list_find_nr(l, -5)})
- eq({false, 5}, {tv_list_find_nr(l, 4)})
- eq({false, 3}, {tv_list_find_nr(l, 2)})
- eq({false, 3}, {tv_list_find_nr(l, -3)})
+ eq({ false, 1 }, { tv_list_find_nr(l, -5) })
+ eq({ false, 5 }, { tv_list_find_nr(l, 4) })
+ eq({ false, 3 }, { tv_list_find_nr(l, 2) })
+ eq({ false, 3 }, { tv_list_find_nr(l, -3) })
alloc_log:check({})
end)
@@ -1386,15 +1417,15 @@ describe('typval.c', function()
local l = list(null_string)
alloc_log:clear()
- eq({false, 0}, {tv_list_find_nr(l, 0)})
+ eq({ false, 0 }, { tv_list_find_nr(l, 0) })
alloc_log:check({})
end)
itp('errors out on NULL lists', function()
- eq({true, -1}, {tv_list_find_nr(nil, -5)})
- eq({true, -1}, {tv_list_find_nr(nil, 4)})
- eq({true, -1}, {tv_list_find_nr(nil, 2)})
- eq({true, -1}, {tv_list_find_nr(nil, -3)})
+ eq({ true, -1 }, { tv_list_find_nr(nil, -5) })
+ eq({ true, -1 }, { tv_list_find_nr(nil, 4) })
+ eq({ true, -1 }, { tv_list_find_nr(nil, 2) })
+ eq({ true, -1 }, { tv_list_find_nr(nil, -3) })
alloc_log:check({})
end)
@@ -1402,20 +1433,20 @@ describe('typval.c', function()
local l = list(int(1), int(2), int(3), int(4), int(5))
alloc_log:clear()
- eq({true, -1}, {tv_list_find_nr(l, -6)})
- eq({true, -1}, {tv_list_find_nr(l, 5)})
+ eq({ true, -1 }, { tv_list_find_nr(l, -6) })
+ eq({ true, -1 }, { tv_list_find_nr(l, 5) })
alloc_log:check({})
end)
itp('errors out on invalid types', function()
local l = list(1, empty_list, {})
- eq({true, 0}, {tv_list_find_nr(l, 0, 'E805: Using a Float as a Number')})
- eq({true, 0}, {tv_list_find_nr(l, 1, 'E745: Using a List as a Number')})
- eq({true, 0}, {tv_list_find_nr(l, 2, 'E728: Using a Dictionary as a Number')})
- eq({true, 0}, {tv_list_find_nr(l, -1, 'E728: Using a Dictionary as a Number')})
- eq({true, 0}, {tv_list_find_nr(l, -2, 'E745: Using a List as a Number')})
- eq({true, 0}, {tv_list_find_nr(l, -3, 'E805: Using a Float as a Number')})
+ eq({ true, 0 }, { tv_list_find_nr(l, 0, 'E805: Using a Float as a Number') })
+ eq({ true, 0 }, { tv_list_find_nr(l, 1, 'E745: Using a List as a Number') })
+ eq({ true, 0 }, { tv_list_find_nr(l, 2, 'E728: Using a Dictionary as a Number') })
+ eq({ true, 0 }, { tv_list_find_nr(l, -1, 'E728: Using a Dictionary as a Number') })
+ eq({ true, 0 }, { tv_list_find_nr(l, -2, 'E745: Using a List as a Number') })
+ eq({ true, 0 }, { tv_list_find_nr(l, -3, 'E805: Using a Float as a Number') })
end)
end)
local function tv_list_find_str(l, n, msg)
@@ -1439,7 +1470,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), 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')
@@ -1499,7 +1530,7 @@ describe('typval.c', function()
itp('works with an empty key', function()
local d = dict({})
eq({}, dict_watchers(d))
- local cb = ffi.gc(tbl2callback({type='none'}), nil)
+ local cb = ffi.gc(tbl2callback({ type = 'none' }), nil)
alloc_log:clear()
lib.tv_dict_watcher_add(d, '*', 0, cb[0])
local ws, qs = dict_watchers(d)
@@ -1508,7 +1539,7 @@ describe('typval.c', function()
a.dwatcher(qs[1]),
a.str(key_p, 0),
})
- eq({{busy=false, cb={type='none'}, pat=''}}, ws)
+ eq({ { busy = false, cb = { type = 'none' }, pat = '' } }, ws)
eq(true, lib.tv_dict_watcher_remove(d, 'x', 0, cb[0]))
alloc_log:check({
a.freed(key_p),
@@ -1519,19 +1550,29 @@ describe('typval.c', function()
itp('works with multiple callbacks', function()
local d = dict({})
eq({}, dict_watchers(d))
- alloc_log:check({a.dict(d)})
+ alloc_log:check({ a.dict(d) })
local cbs = {}
- cbs[1] = {'te', ffi.gc(tbl2callback({type='none'}), nil)}
+ cbs[1] = { 'te', ffi.gc(tbl2callback({ type = 'none' }), nil) }
alloc_log:check({})
- cbs[2] = {'foo', ffi.gc(tbl2callback({type='fref', fref='tr'}), nil)}
+ cbs[2] = { 'foo', ffi.gc(tbl2callback({ type = 'fref', fref = 'tr' }), nil) }
alloc_log:check({
- a.str(cbs[2][2].data.funcref, #('tr')),
+ a.str(cbs[2][2].data.funcref, #'tr'),
})
- cbs[3] = {'te', ffi.gc(tbl2callback({type='pt', fref='tr', pt={
- value='tr',
- args={'test'},
- dict={},
- }}), nil)}
+ cbs[3] = {
+ 'te',
+ ffi.gc(
+ tbl2callback({
+ type = 'pt',
+ fref = 'tr',
+ pt = {
+ value = 'tr',
+ args = { 'test' },
+ dict = {},
+ },
+ }),
+ nil
+ ),
+ }
local pt3 = cbs[3][2].data.partial
local pt3_argv = pt3.pt_argv
local pt3_dict = pt3.pt_dict
@@ -1540,22 +1581,32 @@ describe('typval.c', function()
alloc_log:check({
a.lua_pt(pt3),
a.lua_tvs(pt3_argv, pt3.pt_argc),
- a.str(pt3_str_arg, #('test')),
+ a.str(pt3_str_arg, #'test'),
a.dict(pt3_dict),
- a.str(pt3_name, #('tr')),
+ a.str(pt3_name, #'tr'),
})
for _, v in ipairs(cbs) do
- lib.tv_dict_watcher_add(d, v[1], #(v[1]), v[2][0])
+ lib.tv_dict_watcher_add(d, v[1], #v[1], v[2][0])
end
local ws, qs, kps = dict_watchers(d)
- eq({{busy=false, pat=cbs[1][1], cb={type='none'}},
- {busy=false, pat=cbs[2][1], cb={type='fref', fref='tr'}},
- {busy=false, pat=cbs[3][1], cb={type='pt', fref='tr', pt={
- [type_key]=func_type,
- value='tr',
- args={'test'},
- dict={},
- }}}}, ws)
+ eq({
+ { busy = false, pat = cbs[1][1], cb = { type = 'none' } },
+ { busy = false, pat = cbs[2][1], cb = { type = 'fref', fref = 'tr' } },
+ {
+ busy = false,
+ pat = cbs[3][1],
+ cb = {
+ type = 'pt',
+ fref = 'tr',
+ pt = {
+ [type_key] = func_type,
+ value = 'tr',
+ args = { 'test' },
+ dict = {},
+ },
+ },
+ },
+ }, ws)
alloc_log:check({
a.dwatcher(qs[1]),
a.str(kps[1][1], kps[1][2]),
@@ -1571,13 +1622,23 @@ describe('typval.c', function()
a.freed(qs[2]),
})
eq(false, lib.tv_dict_watcher_remove(d, cbs[2][1], #cbs[2][1], cbs[2][2][0]))
- eq({{busy=false, pat=cbs[1][1], cb={type='none'}},
- {busy=false, pat=cbs[3][1], cb={type='pt', fref='tr', pt={
- [type_key]=func_type,
- value='tr',
- args={'test'},
- dict={},
- }}}}, dict_watchers(d))
+ eq({
+ { busy = false, pat = cbs[1][1], cb = { type = 'none' } },
+ {
+ busy = false,
+ pat = cbs[3][1],
+ cb = {
+ type = 'pt',
+ fref = 'tr',
+ pt = {
+ [type_key] = func_type,
+ value = 'tr',
+ args = { 'test' },
+ dict = {},
+ },
+ },
+ },
+ }, dict_watchers(d))
eq(true, lib.tv_dict_watcher_remove(d, cbs[3][1], #cbs[3][1], cbs[3][2][0]))
alloc_log:check({
a.freed(pt3_str_arg),
@@ -1589,7 +1650,7 @@ describe('typval.c', function()
a.freed(qs[3]),
})
eq(false, lib.tv_dict_watcher_remove(d, cbs[3][1], #cbs[3][1], cbs[3][2][0]))
- eq({{busy=false, pat=cbs[1][1], cb={type='none'}}}, dict_watchers(d))
+ eq({ { busy = false, pat = cbs[1][1], cb = { type = 'none' } } }, dict_watchers(d))
eq(true, lib.tv_dict_watcher_remove(d, cbs[1][1], #cbs[1][1], cbs[1][2][0]))
alloc_log:check({
a.freed(kps[1][1]),
@@ -1615,14 +1676,14 @@ describe('typval.c', function()
di = ffi.gc(lib.tv_dict_item_alloc_len(s, len or #s), nil)
end
eq(s:sub(1, len), ffi.string(di.di_key))
- alloc_log:check({a.di(di, len)})
+ alloc_log:check({ a.di(di, len) })
if tv then
di.di_tv = ffi.gc(tv, nil)
else
di.di_tv.v_type = lib.VAR_UNKNOWN
end
lib.tv_dict_item_free(di)
- alloc_log:check(concat_tables(more_frees, {a.freed(di)}))
+ alloc_log:check(concat_tables(more_frees, { a.freed(di) }))
end
local function check_tv_dict_item_alloc(s, tv, more_frees)
return check_tv_dict_item_alloc_len(s, nil, tv, more_frees)
@@ -1634,26 +1695,30 @@ describe('typval.c', function()
check_tv_dict_item_alloc_len('', 0)
check_tv_dict_item_alloc_len('TEST', 2)
local tv = lua2typvalt('test')
- alloc_log:check({a.str(tv.vval.v_string, #('test'))})
- check_tv_dict_item_alloc('', tv, {a.freed(tv.vval.v_string)})
+ alloc_log:check({ a.str(tv.vval.v_string, #'test') })
+ check_tv_dict_item_alloc('', tv, { a.freed(tv.vval.v_string) })
tv = lua2typvalt('test')
- alloc_log:check({a.str(tv.vval.v_string, #('test'))})
- check_tv_dict_item_alloc_len('', 0, tv, {a.freed(tv.vval.v_string)})
+ alloc_log:check({ a.str(tv.vval.v_string, #'test') })
+ check_tv_dict_item_alloc_len('', 0, tv, { a.freed(tv.vval.v_string) })
end)
end)
describe('add()/remove()', function()
itp('works', function()
local d = dict()
eq({}, dct2tbl(d))
- alloc_log:check({a.dict(d)})
+ alloc_log:check({ a.dict(d) })
local di = ffi.gc(lib.tv_dict_item_alloc(''), nil)
local tv = lua2typvalt('test')
di.di_tv = ffi.gc(tv, nil)
- alloc_log:check({a.di(di, ''), a.str(tv.vval.v_string, 'test')})
+ alloc_log:check({ a.di(di, ''), a.str(tv.vval.v_string, 'test') })
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(): duplicate key ""'))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add(d, di)
+ end, 'E685: Internal error: hash_add(): duplicate key ""')
+ )
alloc_log:clear()
lib.tv_dict_item_remove(d, di)
alloc_log:check({
@@ -1679,28 +1744,28 @@ describe('typval.c', function()
end)
itp('works with empty key', function()
local lua_d = {
- ['']=0,
- t=1,
- te=2,
- tes=3,
- test=4,
- testt=5,
+ [''] = 0,
+ t = 1,
+ te = 2,
+ tes = 3,
+ test = 4,
+ testt = 5,
}
local d = dict(lua_d)
alloc_log:clear()
eq(lua_d, dct2tbl(d))
alloc_log:check({})
local dis = dict_items(d)
- eq({0, '', dis['']}, {tv_dict_find(d, '', 0)})
+ eq({ 0, '', dis[''] }, { tv_dict_find(d, '', 0) })
end)
itp('works with len properly', function()
local lua_d = {
- ['']=0,
- t=1,
- te=2,
- tes=3,
- test=4,
- testt=5,
+ [''] = 0,
+ t = 1,
+ te = 2,
+ tes = 3,
+ test = 4,
+ testt = 5,
}
local d = dict(lua_d)
alloc_log:clear()
@@ -1708,80 +1773,125 @@ describe('typval.c', function()
alloc_log:check({})
for i = 0, 5 do
local v, k = tv_dict_find(d, 'testt', i)
- eq({i, ('testt'):sub(1, i)}, {v, k})
+ eq({ i, ('testt'):sub(1, i) }, { v, k })
end
- eq(nil, tv_dict_find(d, 'testt', 6)) -- Should take NUL byte
+ eq(nil, tv_dict_find(d, 'testt', 6)) -- Should take NUL byte
eq(5, tv_dict_find(d, 'testt', -1))
alloc_log:check({})
end)
end)
describe('get_number()', function()
itp('works with NULL dict', function()
- eq(0, check_emsg(function() return lib.tv_dict_get_number(nil, 'test') end,
- nil))
+ eq(
+ 0,
+ check_emsg(function()
+ return lib.tv_dict_get_number(nil, 'test')
+ end, nil)
+ )
end)
itp('works', function()
- local d = ffi.gc(dict({test={}}), nil)
- eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 'test') end,
- 'E728: Using a Dictionary as a Number'))
- d = ffi.gc(dict({tes=int(42), t=44, te='43'}), nil)
+ local d = ffi.gc(dict({ test = {} }), nil)
+ eq(
+ 0,
+ check_emsg(function()
+ return lib.tv_dict_get_number(d, 'test')
+ end, 'E728: Using a Dictionary as a Number')
+ )
+ d = ffi.gc(dict({ tes = int(42), t = 44, te = '43' }), nil)
alloc_log:clear()
- eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 'test') end,
- nil))
- eq(42, check_emsg(function() return lib.tv_dict_get_number(d, 'tes') end,
- nil))
- eq(43, check_emsg(function() return lib.tv_dict_get_number(d, 'te') end,
- nil))
+ eq(
+ 0,
+ check_emsg(function()
+ return lib.tv_dict_get_number(d, 'test')
+ end, nil)
+ )
+ eq(
+ 42,
+ check_emsg(function()
+ return lib.tv_dict_get_number(d, 'tes')
+ end, nil)
+ )
+ eq(
+ 43,
+ check_emsg(function()
+ return lib.tv_dict_get_number(d, 'te')
+ end, nil)
+ )
alloc_log:check({})
- eq(0, check_emsg(function() return lib.tv_dict_get_number(d, 't') end,
- 'E805: Using a Float as a Number'))
+ eq(
+ 0,
+ check_emsg(function()
+ return lib.tv_dict_get_number(d, 't')
+ end, 'E805: Using a Float as a Number')
+ )
end)
end)
describe('get_string()', function()
itp('works with NULL dict', function()
- eq(nil, check_emsg(function() return lib.tv_dict_get_string(nil, 'test', false) end,
- nil))
+ eq(
+ nil,
+ check_emsg(function()
+ return lib.tv_dict_get_string(nil, 'test', false)
+ end, nil)
+ )
end)
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 a Dictionary as a String')))
- d = ffi.gc(dict({tes=int(42), t=44, te='43', xx=int(45)}), nil)
+ 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 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)
- eq(nil, check_emsg(function() return lib.tv_dict_get_string(d, 'test', false) end,
- nil))
- local s42 = check_emsg(function() return lib.tv_dict_get_string(d, 'tes', false) end,
- nil)
+ eq(
+ nil,
+ check_emsg(function()
+ return lib.tv_dict_get_string(d, 'test', false)
+ end, nil)
+ )
+ local s42 = check_emsg(function()
+ return lib.tv_dict_get_string(d, 'tes', false)
+ end, nil)
eq('42', ffi.string(s42))
- local s45 = check_emsg(function() return lib.tv_dict_get_string(d, 'xx', false) end,
- nil)
+ local s45 = check_emsg(function()
+ return lib.tv_dict_get_string(d, 'xx', false)
+ end, nil)
eq(s42, s45)
eq('45', ffi.string(s45))
eq('45', ffi.string(s42))
- local s43 = check_emsg(function() return lib.tv_dict_get_string(d, 'te', false) end,
- nil)
+ local s43 = check_emsg(function()
+ return lib.tv_dict_get_string(d, 'te', false)
+ end, nil)
eq('43', ffi.string(s43))
neq(s42, s43)
eq(s43, dis.te.di_tv.vval.v_string)
alloc_log:check({})
- local s44 = check_emsg(function() return lib.tv_dict_get_string(d, 't', false) end,
- nil)
+ 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), 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)
alloc_log:clear()
- local ret = check_emsg(function() return lib.tv_dict_get_string(d, key, true) end,
- emsg)
+ 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
if is_float then
- alloc_log:check({a.freed(alloc_log.null), 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)})
+ alloc_log:check({ a.str(ret, s_ret) })
end
else
alloc_log:check({})
@@ -1790,9 +1900,9 @@ describe('typval.c', function()
lib.xfree(ret)
return s_ret
end
- local d = ffi.gc(dict({test={}}), nil)
+ local d = ffi.gc(dict({ test = {} }), nil)
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)
+ 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'))
eq('42', tv_dict_get_string_alloc(d, 'tes'))
@@ -1805,12 +1915,13 @@ describe('typval.c', function()
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 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
if is_float then
- alloc_log:check({a.freed(alloc_log.null), a.freed(alloc_log.null)})
+ alloc_log:check({ a.freed(alloc_log.null), a.freed(alloc_log.null) })
else
alloc_log:check({})
end
@@ -1822,12 +1933,12 @@ describe('typval.c', function()
end)
itp('works', function()
local lua_d = {
- ['']={},
- t=1,
- te=int(2),
- tes=empty_list,
- test='tset',
- testt=5,
+ [''] = {},
+ t = 1,
+ te = int(2),
+ tes = empty_list,
+ test = 'tset',
+ testt = 5,
}
local d = dict(lua_d)
alloc_log:clear()
@@ -1851,12 +1962,13 @@ describe('typval.c', function()
def = def or ffi.gc(lib.xstrdup('DEFAULT'), lib.xfree)
len = len or #key
alloc_log:clear()
- local ret = check_emsg(function() return lib.tv_dict_get_string_buf_chk(d, key, len, buf, def) end,
- emsg)
+ local ret = check_emsg(function()
+ return lib.tv_dict_get_string_buf_chk(d, key, len, buf, def)
+ end, emsg)
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), a.freed(alloc_log.null)})
+ alloc_log:check({ a.freed(alloc_log.null), a.freed(alloc_log.null) })
else
alloc_log:check({})
end
@@ -1868,12 +1980,12 @@ describe('typval.c', function()
end)
itp('works', function()
local lua_d = {
- ['']={},
- t=1,
- te=int(2),
- tes=empty_list,
- test='tset',
- testt=5,
+ [''] = {},
+ t = 1,
+ te = int(2),
+ tes = empty_list,
+ test = 'tset',
+ testt = 5,
}
local d = dict(lua_d)
alloc_log:clear()
@@ -1901,7 +2013,8 @@ describe('typval.c', function()
describe('get_callback()', function()
local function tv_dict_get_callback(d, key, key_len, emsg)
key_len = key_len or #key
- local cb = ffi.gc(ffi.cast('Callback*', lib.xmalloc(ffi.sizeof('Callback'))), lib.callback_free)
+ local cb =
+ ffi.gc(ffi.cast('Callback*', lib.xmalloc(ffi.sizeof('Callback'))), lib.callback_free)
alloc_log:clear()
local ret = check_emsg(function()
return lib.tv_dict_get_callback(d, key, key_len, cb)
@@ -1910,35 +2023,59 @@ describe('typval.c', function()
return cb_lua, ret
end
itp('works with NULL dict', function()
- eq({{type='none'}, true}, {tv_dict_get_callback(nil, '')})
+ eq({ { type = 'none' }, true }, { tv_dict_get_callback(nil, '') })
end)
itp('works', function()
local lua_d = {
- ['']='tr',
- t=int(1),
- te={[type_key]=func_type, value='tr'},
- tes={[type_key]=func_type, value='tr', args={'a', 'b'}},
- test={[type_key]=func_type, value='Test', dict={test=1}, args={}},
- testt={[type_key]=func_type, value='Test', dict={test=1}, args={1}},
+ [''] = 'tr',
+ t = int(1),
+ te = { [type_key] = func_type, value = 'tr' },
+ tes = { [type_key] = func_type, value = 'tr', args = { 'a', 'b' } },
+ test = { [type_key] = func_type, value = 'Test', dict = { test = 1 }, args = {} },
+ testt = { [type_key] = func_type, value = 'Test', dict = { test = 1 }, args = { 1 } },
}
local d = dict(lua_d)
eq(lua_d, dct2tbl(d))
- eq({{type='fref', fref='tr'}, true},
- {tv_dict_get_callback(d, '', -1)})
- eq({{type='none'}, true},
- {tv_dict_get_callback(d, 'x', -1)})
- eq({{type='fref', fref='tr'}, true},
- {tv_dict_get_callback(d, 'testt', 0)})
- eq({{type='none'}, false},
- {tv_dict_get_callback(d, 'test', 1, 'E6000: Argument is not a function or function name')})
- eq({{type='fref', fref='tr'}, true},
- {tv_dict_get_callback(d, 'testt', 2)})
- eq({{ type='pt', fref='tr', pt={ [type_key]=func_type, value='tr', args={ 'a', 'b' } } }, true},
- {tv_dict_get_callback(d, 'testt', 3)})
- eq({{ type='pt', fref='Test', pt={ [type_key]=func_type, value='Test', dict={ test=1 }, args={} } }, true},
- {tv_dict_get_callback(d, 'testt', 4)})
- eq({{ type='pt', fref='Test', pt={ [type_key]=func_type, value='Test', dict={ test=1 }, args={1} } }, true},
- {tv_dict_get_callback(d, 'testt', 5)})
+ eq({ { type = 'fref', fref = 'tr' }, true }, { tv_dict_get_callback(d, '', -1) })
+ eq({ { type = 'none' }, true }, { tv_dict_get_callback(d, 'x', -1) })
+ eq({ { type = 'fref', fref = 'tr' }, true }, { tv_dict_get_callback(d, 'testt', 0) })
+ eq({ { type = 'none' }, false }, {
+ tv_dict_get_callback(
+ d,
+ 'test',
+ 1,
+ 'E6000: Argument is not a function or function name'
+ ),
+ })
+ eq({ { type = 'fref', fref = 'tr' }, true }, { tv_dict_get_callback(d, 'testt', 2) })
+ eq({
+ {
+ type = 'pt',
+ fref = 'tr',
+ pt = {
+ [type_key] = func_type,
+ value = 'tr',
+ args = { 'a', 'b' },
+ },
+ },
+ true,
+ }, { tv_dict_get_callback(d, 'testt', 3) })
+ eq({
+ {
+ type = 'pt',
+ fref = 'Test',
+ pt = { [type_key] = func_type, value = 'Test', dict = { test = 1 }, args = {} },
+ },
+ true,
+ }, { tv_dict_get_callback(d, 'testt', 4) })
+ eq({
+ {
+ type = 'pt',
+ fref = 'Test',
+ pt = { [type_key] = func_type, value = 'Test', dict = { test = 1 }, args = { 1 } },
+ },
+ true,
+ }, { tv_dict_get_callback(d, 'testt', 5) })
end)
end)
end)
@@ -1946,22 +2083,26 @@ describe('typval.c', function()
describe('()', function()
itp('works', function()
local di = lib.tv_dict_item_alloc_len('t-est', 5)
- alloc_log:check({a.di(di, 't-est')})
+ alloc_log:check({ a.di(di, 't-est') })
di.di_tv.v_type = lib.VAR_NUMBER
di.di_tv.vval.v_number = 42
- local d = dict({test=10})
+ local d = dict({ test = 10 })
local dis = dict_items(d)
alloc_log:check({
a.dict(d),
- a.di(dis.test, 'test')
+ a.di(dis.test, 'test'),
})
- eq({test=10}, dct2tbl(d))
+ eq({ test = 10 }, dct2tbl(d))
alloc_log:clear()
eq(OK, lib.tv_dict_add(d, di))
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(): duplicate key "t-est"'))
+ 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(): duplicate key "t-est"')
+ )
end)
end)
describe('list()', function()
@@ -1969,21 +2110,29 @@ describe('typval.c', function()
local l = list(1, 2, 3)
alloc_log:clear()
eq(1, l.lv_refcount)
- local d = dict({test=10})
+ local d = dict({ test = 10 })
alloc_log:clear()
- eq({test=10}, dct2tbl(d))
+ eq({ test = 10 }, dct2tbl(d))
eq(OK, lib.tv_dict_add_list(d, 'testt', 3, l))
local dis = dict_items(d)
- alloc_log:check({a.di(dis.tes, 'tes')})
- eq({test=10, tes={1, 2, 3}}, dct2tbl(d))
+ alloc_log:check({ a.di(dis.tes, 'tes') })
+ 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(): duplicate key "tes"'))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add_list(d, 'testt', 3, l)
+ end, 'E685: Internal error: hash_add(): duplicate key "tes"')
+ )
eq(2, l.lv_refcount)
alloc_log:clear()
lib.emsg_skip = lib.emsg_skip + 1
- eq(FAIL, check_emsg(function() return lib.tv_dict_add_list(d, 'testt', 3, l) end,
- nil))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add_list(d, 'testt', 3, l)
+ end, nil)
+ )
eq(2, l.lv_refcount)
lib.emsg_skip = lib.emsg_skip - 1
alloc_log:clear_tmp_allocs()
@@ -1992,24 +2141,32 @@ describe('typval.c', function()
end)
describe('dict()', function()
itp('works', function()
- local d2 = dict({foo=42})
+ local d2 = dict({ foo = 42 })
alloc_log:clear()
eq(1, d2.dv_refcount)
- local d = dict({test=10})
+ local d = dict({ test = 10 })
alloc_log:clear()
- eq({test=10}, dct2tbl(d))
+ eq({ test = 10 }, dct2tbl(d))
eq(OK, lib.tv_dict_add_dict(d, 'testt', 3, d2))
local dis = dict_items(d)
- alloc_log:check({a.di(dis.tes, 'tes')})
- eq({test=10, tes={foo=42}}, dct2tbl(d))
+ alloc_log:check({ a.di(dis.tes, 'tes') })
+ 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(): duplicate key "tes"'))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add_dict(d, 'testt', 3, d2)
+ end, 'E685: Internal error: hash_add(): duplicate key "tes"')
+ )
eq(2, d2.dv_refcount)
alloc_log:clear()
lib.emsg_skip = lib.emsg_skip + 1
- eq(FAIL, check_emsg(function() return lib.tv_dict_add_dict(d, 'testt', 3, d2) end,
- nil))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add_dict(d, 'testt', 3, d2)
+ end, nil)
+ )
eq(2, d2.dv_refcount)
lib.emsg_skip = lib.emsg_skip - 1
alloc_log:clear_tmp_allocs()
@@ -2018,19 +2175,27 @@ describe('typval.c', function()
end)
describe('nr()', function()
itp('works', function()
- local d = dict({test=10})
+ local d = dict({ test = 10 })
alloc_log:clear()
- eq({test=10}, dct2tbl(d))
+ eq({ test = 10 }, dct2tbl(d))
eq(OK, lib.tv_dict_add_nr(d, 'testt', 3, 2))
local dis = dict_items(d)
- 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(): duplicate key "tes"'))
+ 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(): 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,
- nil))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add_nr(d, 'testt', 3, 2)
+ end, nil)
+ )
lib.emsg_skip = lib.emsg_skip - 1
alloc_log:clear_tmp_allocs()
alloc_log:check({})
@@ -2038,19 +2203,27 @@ describe('typval.c', function()
end)
describe('float()', function()
itp('works', function()
- local d = dict({test=10})
+ local d = dict({ test = 10 })
alloc_log:clear()
- eq({test=10}, dct2tbl(d))
+ eq({ test = 10 }, dct2tbl(d))
eq(OK, lib.tv_dict_add_float(d, 'testt', 3, 1.5))
local dis = dict_items(d)
- 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(): duplicate key "tes"'))
+ 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(): 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,
- nil))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add_float(d, 'testt', 3, 1.5)
+ end, nil)
+ )
lib.emsg_skip = lib.emsg_skip - 1
alloc_log:clear_tmp_allocs()
alloc_log:check({})
@@ -2058,22 +2231,30 @@ describe('typval.c', function()
end)
describe('str()', function()
itp('works', function()
- local d = dict({test=10})
+ local d = dict({ test = 10 })
alloc_log:clear()
- eq({test=10}, dct2tbl(d))
+ eq({ test = 10 }, dct2tbl(d))
eq(OK, lib.tv_dict_add_str(d, 'testt', 3, 'TEST'))
local dis = dict_items(d)
alloc_log:check({
a.str(dis.tes.di_tv.vval.v_string, 'TEST'),
a.di(dis.tes, 'tes'),
})
- 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(): duplicate key "tes"'))
+ 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(): 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,
- nil))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add_str(d, 'testt', 3, 'TEST')
+ end, nil)
+ )
lib.emsg_skip = lib.emsg_skip - 1
alloc_log:clear_tmp_allocs()
alloc_log:check({})
@@ -2081,8 +2262,8 @@ describe('typval.c', function()
end)
describe('allocated_str()', function()
itp('works', function()
- local d = dict({test=10})
- eq({test=10}, dct2tbl(d))
+ local d = dict({ test = 10 })
+ eq({ test = 10 }, dct2tbl(d))
alloc_log:clear()
local s1 = lib.xstrdup('TEST')
local s2 = lib.xstrdup('TEST')
@@ -2097,13 +2278,21 @@ describe('typval.c', function()
alloc_log:check({
a.di(dis.tes, 'tes'),
})
- 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(): duplicate key "tes"'))
+ 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(): 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,
- nil))
+ eq(
+ FAIL,
+ check_emsg(function()
+ return lib.tv_dict_add_allocated_str(d, 'testt', 3, s3)
+ end, nil)
+ )
lib.emsg_skip = lib.emsg_skip - 1
alloc_log:clear_tmp_allocs()
alloc_log:check({
@@ -2115,7 +2304,7 @@ describe('typval.c', function()
describe('clear()', function()
itp('works', function()
local d = dict()
- alloc_log:check({a.dict(d)})
+ alloc_log:check({ a.dict(d) })
eq({}, dct2tbl(d))
lib.tv_dict_clear(d)
eq({}, dct2tbl(d))
@@ -2123,32 +2312,34 @@ describe('typval.c', function()
local dis = dict_items(d)
local di = dis.TES
local di_s = di.di_tv.vval.v_string
- alloc_log:check({a.str(di_s), a.di(di)})
- eq({TES='tEsT'}, dct2tbl(d))
+ alloc_log:check({ a.str(di_s), a.di(di) })
+ eq({ TES = 'tEsT' }, dct2tbl(d))
lib.tv_dict_clear(d)
- alloc_log:check({a.freed(di_s), a.freed(di)})
+ alloc_log:check({ a.freed(di_s), a.freed(di) })
eq({}, dct2tbl(d))
end)
end)
describe('extend()', function()
local function tv_dict_extend(d1, d2, action, emsg)
- action = action or "force"
- check_emsg(function() return lib.tv_dict_extend(d1, d2, action) end, emsg)
+ action = action or 'force'
+ check_emsg(function()
+ return lib.tv_dict_extend(d1, d2, action)
+ end, emsg)
end
itp('works', function()
local d1 = dict()
- alloc_log:check({a.dict(d1)})
+ alloc_log:check({ a.dict(d1) })
eq({}, dct2tbl(d1))
local d2 = dict()
- alloc_log:check({a.dict(d2)})
+ alloc_log:check({ a.dict(d2) })
eq({}, dct2tbl(d2))
tv_dict_extend(d1, d2, 'error')
tv_dict_extend(d1, d2, 'keep')
tv_dict_extend(d1, d2, 'force')
alloc_log:check({})
- d1 = dict({a='TEST'})
- eq({a='TEST'}, dct2tbl(d1))
+ d1 = dict({ a = 'TEST' })
+ eq({ a = 'TEST' }, dct2tbl(d1))
local dis1 = dict_items(d1)
local a1_s = dis1.a.di_tv.vval.v_string
alloc_log:clear_tmp_allocs()
@@ -2157,8 +2348,8 @@ describe('typval.c', function()
a.di(dis1.a),
a.str(a1_s),
})
- d2 = dict({a='TSET'})
- eq({a='TSET'}, dct2tbl(d2))
+ d2 = dict({ a = 'TSET' })
+ eq({ a = 'TSET' }, dct2tbl(d2))
local dis2 = dict_items(d2)
local a2_s = dis2.a.di_tv.vval.v_string
alloc_log:clear_tmp_allocs()
@@ -2169,72 +2360,66 @@ describe('typval.c', function()
})
tv_dict_extend(d1, d2, 'error', 'E737: Key already exists: a')
- eq({a='TEST'}, dct2tbl(d1))
- eq({a='TSET'}, dct2tbl(d2))
+ eq({ a = 'TEST' }, dct2tbl(d1))
+ eq({ a = 'TSET' }, dct2tbl(d2))
alloc_log:clear()
tv_dict_extend(d1, d2, 'keep')
alloc_log:check({})
- eq({a='TEST'}, dct2tbl(d1))
- eq({a='TSET'}, dct2tbl(d2))
+ eq({ a = 'TEST' }, dct2tbl(d1))
+ eq({ a = 'TSET' }, dct2tbl(d2))
tv_dict_extend(d1, d2, 'force')
alloc_log:check({
a.freed(a1_s),
a.str(dis1.a.di_tv.vval.v_string),
})
- eq({a='TSET'}, dct2tbl(d1))
- eq({a='TSET'}, dct2tbl(d2))
+ eq({ a = 'TSET' }, dct2tbl(d1))
+ eq({ a = 'TSET' }, dct2tbl(d2))
end)
pending('disallows overriding builtin or user functions: here be the dragons', function()
-- pending: see TODO below
local d = dict()
d.dv_scope = lib.VAR_DEF_SCOPE
local f_lua = {
- [type_key]=func_type,
- value='tr',
+ [type_key] = func_type,
+ value = 'tr',
}
local f_tv = lua2typvalt(f_lua)
local p_lua = {
- [type_key]=func_type,
- value='tr',
- args={1},
+ [type_key] = func_type,
+ value = 'tr',
+ args = { 1 },
}
local p_tv = lua2typvalt(p_lua)
eq(lib.VAR_PARTIAL, p_tv.v_type)
- local d2 = dict({tr=f_tv})
- local d3 = dict({tr=p_tv})
- local d4 = dict({['TEST:THIS']=p_tv})
- local d5 = dict({Test=f_tv})
- local d6 = dict({Test=p_tv})
+ local d2 = dict({ tr = f_tv })
+ local d3 = dict({ tr = p_tv })
+ local d4 = dict({ ['TEST:THIS'] = p_tv })
+ local d5 = dict({ Test = f_tv })
+ local d6 = dict({ Test = p_tv })
eval0([[execute("function Test()\nendfunction")]])
-- TODO: test breaks at this point
- tv_dict_extend(d, d2, 'force',
- 'E704: Funcref variable name must start with a capital: tr')
- tv_dict_extend(d, d3, 'force',
- 'E704: Funcref variable name must start with a capital: tr')
- tv_dict_extend(d, d4, 'force',
- 'E461: Illegal variable name: TEST:THIS')
- tv_dict_extend(d, d5, 'force',
- 'E705: Variable name conflicts with existing function: Test')
- tv_dict_extend(d, d6, 'force',
- 'E705: Variable name conflicts with existing function: Test')
+ tv_dict_extend(d, d2, 'force', 'E704: Funcref variable name must start with a capital: tr')
+ tv_dict_extend(d, d3, 'force', 'E704: Funcref variable name must start with a capital: tr')
+ tv_dict_extend(d, d4, 'force', 'E461: Illegal variable name: TEST:THIS')
+ tv_dict_extend(d, d5, 'force', 'E705: Variable name conflicts with existing function: Test')
+ tv_dict_extend(d, d6, 'force', 'E705: Variable name conflicts with existing function: Test')
eq({}, dct2tbl(d))
d.dv_scope = lib.VAR_SCOPE
- tv_dict_extend(d, d4, 'force',
- 'E461: Illegal variable name: TEST:THIS')
+ tv_dict_extend(d, d4, 'force', 'E461: Illegal variable name: TEST:THIS')
eq({}, dct2tbl(d))
tv_dict_extend(d, d2, 'force')
- eq({tr=f_lua}, dct2tbl(d))
+ eq({ tr = f_lua }, dct2tbl(d))
tv_dict_extend(d, d3, 'force')
- eq({tr=p_lua}, dct2tbl(d))
+ eq({ tr = p_lua }, dct2tbl(d))
tv_dict_extend(d, d5, 'force')
- eq({tr=p_lua, Test=f_lua}, dct2tbl(d))
+ eq({ tr = p_lua, Test = f_lua }, dct2tbl(d))
tv_dict_extend(d, d6, 'force')
- eq({tr=p_lua, Test=p_lua}, dct2tbl(d))
+ eq({ tr = p_lua, Test = p_lua }, dct2tbl(d))
end)
itp('cares about locks and read-only items', function()
- local d_lua = {tv_locked=1, tv_fixed=2, di_ro=3, di_ro_sbx=4}
+ local d_lua = { tv_locked = 1, tv_fixed = 2, di_ro = 3, di_ro_sbx = 4 }
local d = dict(d_lua)
local dis = dict_items(d)
dis.tv_locked.di_tv.v_lock = lib.VAR_LOCKED
@@ -2242,14 +2427,19 @@ describe('typval.c', function()
dis.di_ro.di_flags = bit.bor(dis.di_ro.di_flags, lib.DI_FLAGS_RO)
dis.di_ro_sbx.di_flags = bit.bor(dis.di_ro_sbx.di_flags, lib.DI_FLAGS_RO_SBX)
lib.sandbox = true
- local d1 = dict({tv_locked=41})
- local d2 = dict({tv_fixed=42})
- local d3 = dict({di_ro=43})
- local d4 = dict({di_ro_sbx=44})
+ local d1 = dict({ tv_locked = 41 })
+ local d2 = dict({ tv_fixed = 42 })
+ local d3 = dict({ di_ro = 43 })
+ local d4 = dict({ di_ro_sbx = 44 })
tv_dict_extend(d, d1, 'force', 'E741: Value is locked: extend() argument')
tv_dict_extend(d, d2, 'force', 'E742: Cannot change value of extend() argument')
tv_dict_extend(d, d3, 'force', 'E46: Cannot change read-only variable "extend() argument"')
- tv_dict_extend(d, d4, 'force', 'E794: Cannot set variable in the sandbox: "extend() argument"')
+ tv_dict_extend(
+ d,
+ d4,
+ 'force',
+ 'E794: Cannot set variable in the sandbox: "extend() argument"'
+ )
eq(d_lua, dct2tbl(d))
lib.sandbox = false
tv_dict_extend(d, d4, 'force')
@@ -2264,20 +2454,20 @@ describe('typval.c', function()
itp('works', function()
eq(true, tv_dict_equal(nil, nil))
local d1 = dict()
- alloc_log:check({a.dict(d1)})
+ alloc_log:check({ a.dict(d1) })
eq(1, d1.dv_refcount)
eq(true, tv_dict_equal(nil, d1))
eq(true, tv_dict_equal(d1, nil))
eq(true, tv_dict_equal(d1, d1))
eq(1, d1.dv_refcount)
alloc_log:check({})
- local d_upper = dict({a='TEST'})
+ local d_upper = dict({ a = 'TEST' })
local dis_upper = dict_items(d_upper)
- local d_lower = dict({a='test'})
+ local d_lower = dict({ a = 'test' })
local dis_lower = dict_items(d_lower)
- local d_kupper_upper = dict({A='TEST'})
+ local d_kupper_upper = dict({ A = 'TEST' })
local dis_kupper_upper = dict_items(d_kupper_upper)
- local d_kupper_lower = dict({A='test'})
+ local d_kupper_lower = dict({ A = 'test' })
local dis_kupper_lower = dict_items(d_kupper_lower)
alloc_log:clear_tmp_allocs()
alloc_log:check({
@@ -2320,7 +2510,15 @@ describe('typval.c', function()
end)
itp('copies dict correctly without converting items', function()
do
- local v = {a={['«']='»'}, b={'„'}, ['1']=1, ['«»']='“', ns=null_string, nl=null_list, nd=null_dict}
+ local v = {
+ a = { ['«'] = '»' },
+ b = { '„' },
+ ['1'] = 1,
+ ['«»'] = '“',
+ ns = null_string,
+ nl = null_list,
+ nd = null_dict,
+ }
local d_tv = lua2typvalt(v)
local d = d_tv.vval.v_dict
local dis = dict_items(d)
@@ -2358,7 +2556,15 @@ describe('typval.c', function()
-- UTF-8 ↔ latin1 conversions need no iconv
eq(OK, lib.convert_setup(vc, to_cstr('utf-8'), to_cstr('latin1')))
- local v = {a={['«']='»'}, b={'„'}, ['1']=1, ['«»']='“', ns=null_string, nl=null_list, nd=null_dict}
+ local v = {
+ a = { ['«'] = '»' },
+ b = { '„' },
+ ['1'] = 1,
+ ['«»'] = '“',
+ ns = null_string,
+ nl = null_list,
+ nd = null_dict,
+ }
local d_tv = lua2typvalt(v)
local d = d_tv.vval.v_dict
local dis = dict_items(d)
@@ -2373,14 +2579,21 @@ describe('typval.c', function()
local dis_deepcopy1 = dict_items(d_deepcopy1)
neq(dis.a.di_tv.vval.v_dict, dis_deepcopy1.a.di_tv.vval.v_dict)
neq(dis.b.di_tv.vval.v_list, dis_deepcopy1.b.di_tv.vval.v_list)
- eq({a={['\171']='\187'}, b={'\191'}, ['1']=1, ['\171\187']='\191', ns=null_string, nl=null_list, nd=null_dict},
- dct2tbl(d_deepcopy1))
+ eq({
+ a = { ['\171'] = '\187' },
+ b = { '\191' },
+ ['1'] = 1,
+ ['\171\187'] = '\191',
+ ns = null_string,
+ nl = null_list,
+ nd = null_dict,
+ }, dct2tbl(d_deepcopy1))
alloc_log:clear_tmp_allocs()
alloc_log:clear()
end)
itp('returns different/same containers with(out) copyID', function()
local d_inner_tv = lua2typvalt({})
- local d_tv = lua2typvalt({a=d_inner_tv, b=d_inner_tv})
+ local d_tv = lua2typvalt({ a = d_inner_tv, b = d_inner_tv })
eq(3, d_inner_tv.vval.v_dict.dv_refcount)
local d = d_tv.vval.v_dict
local dis = dict_items(d)
@@ -2389,12 +2602,12 @@ describe('typval.c', function()
local d_copy1 = tv_dict_copy(nil, d, true, 0)
local dis_copy1 = dict_items(d_copy1)
neq(dis_copy1.a.di_tv.vval.v_dict, dis_copy1.b.di_tv.vval.v_dict)
- eq({a={}, b={}}, dct2tbl(d_copy1))
+ eq({ a = {}, b = {} }, dct2tbl(d_copy1))
local d_copy2 = tv_dict_copy(nil, d, true, 2)
local dis_copy2 = dict_items(d_copy2)
eq(dis_copy2.a.di_tv.vval.v_dict, dis_copy2.b.di_tv.vval.v_dict)
- eq({a={}, b={}}, dct2tbl(d_copy2))
+ eq({ a = {}, b = {} }, dct2tbl(d_copy2))
eq(3, d_inner_tv.vval.v_dict.dv_refcount)
end)
@@ -2420,9 +2633,9 @@ describe('typval.c', function()
end)
describe('set_keys_readonly()', function()
itp('works', function()
- local d = dict({a=true})
+ local d = dict({ a = true })
local dis = dict_items(d)
- alloc_log:check({a.dict(d), a.di(dis.a)})
+ alloc_log:check({ a.dict(d), a.di(dis.a) })
eq(0, bit.band(dis.a.di_flags, lib.DI_FLAGS_RO))
eq(0, bit.band(dis.a.di_flags, lib.DI_FLAGS_FIX))
lib.tv_dict_set_keys_readonly(d)
@@ -2472,23 +2685,52 @@ describe('typval.c', function()
local dd_d = nil
dd.dd = dd
for _, v in ipairs({
- {nil_value},
- {null_string, nil, function() return {a.freed(alloc_log.null)} end},
- {0},
- {int(0)},
- {true},
- {false},
- {'true', function(tv) return {a.str(tv.vval.v_string)} end},
- {{}, function(tv) return {a.dict(tv.vval.v_dict)} end},
- {empty_list, function(tv) return {a.list(tv.vval.v_list)} end},
- {ll, function(tv)
- ll_l = tv.vval.v_list
- return {a.list(tv.vval.v_list), a.li(tv.vval.v_list.lv_first)}
- end, defalloc},
- {dd, function(tv)
- dd_d = tv.vval.v_dict
- return {a.dict(tv.vval.v_dict), a.di(first_di(tv.vval.v_dict))}
- end, defalloc},
+ { nil_value },
+ {
+ null_string,
+ nil,
+ function()
+ return { a.freed(alloc_log.null) }
+ end,
+ },
+ { 0 },
+ { int(0) },
+ { true },
+ { false },
+ {
+ 'true',
+ function(tv)
+ return { a.str(tv.vval.v_string) }
+ end,
+ },
+ {
+ {},
+ function(tv)
+ return { a.dict(tv.vval.v_dict) }
+ end,
+ },
+ {
+ empty_list,
+ function(tv)
+ return { a.list(tv.vval.v_list) }
+ end,
+ },
+ {
+ ll,
+ function(tv)
+ ll_l = tv.vval.v_list
+ return { a.list(tv.vval.v_list), a.li(tv.vval.v_list.lv_first) }
+ end,
+ defalloc,
+ },
+ {
+ dd,
+ function(tv)
+ dd_d = tv.vval.v_dict
+ return { a.dict(tv.vval.v_dict), a.di(first_di(tv.vval.v_dict)) }
+ end,
+ defalloc,
+ },
}) do
local tv = lua2typvalt(v[1])
local alloc_rets = {}
@@ -2503,26 +2745,45 @@ describe('typval.c', function()
describe('copy()', function()
itp('works', function()
local function strallocs(tv)
- return {a.str(tv.vval.v_string)}
+ return { a.str(tv.vval.v_string) }
end
for _, v in ipairs({
- {nil_value},
- {null_string},
- {0},
- {int(0)},
- {true},
- {false},
- {{}, function(tv) return {a.dict(tv.vval.v_dict)} end, nil, function(from, to)
- eq(2, to.vval.v_dict.dv_refcount)
- eq(to.vval.v_dict, from.vval.v_dict)
- end},
- {empty_list, function(tv) return {a.list(tv.vval.v_list)} end, nil, function(from, to)
- eq(2, to.vval.v_list.lv_refcount)
- eq(to.vval.v_list, from.vval.v_list)
- end},
- {'test', strallocs, strallocs, function(from, to)
- neq(to.vval.v_string, from.vval.v_string)
- end},
+ { nil_value },
+ { null_string },
+ { 0 },
+ { int(0) },
+ { true },
+ { false },
+ {
+ {},
+ function(tv)
+ return { a.dict(tv.vval.v_dict) }
+ end,
+ nil,
+ function(from, to)
+ eq(2, to.vval.v_dict.dv_refcount)
+ eq(to.vval.v_dict, from.vval.v_dict)
+ end,
+ },
+ {
+ empty_list,
+ function(tv)
+ return { a.list(tv.vval.v_list) }
+ end,
+ nil,
+ function(from, to)
+ eq(2, to.vval.v_list.lv_refcount)
+ eq(to.vval.v_list, from.vval.v_list)
+ end,
+ },
+ {
+ 'test',
+ strallocs,
+ strallocs,
+ function(from, to)
+ neq(to.vval.v_string, from.vval.v_string)
+ end,
+ },
}) do
local from = lua2typvalt(v[1])
alloc_log:check((v[2] or defalloc)(from))
@@ -2540,9 +2801,9 @@ describe('typval.c', function()
describe('item_lock()', function()
itp('does not alter VAR_PARTIAL', function()
local p_tv = lua2typvalt({
- [type_key]=func_type,
- value='tr',
- dict={},
+ [type_key] = func_type,
+ value = 'tr',
+ dict = {},
})
lib.tv_item_lock(p_tv, -1, true, false)
eq(lib.VAR_UNLOCKED, p_tv.vval.v_partial.pt_dict.dv_lock)
@@ -2641,18 +2902,18 @@ describe('typval.c', function()
end
itp('works', function()
eq(false, tv_check_lock(lib.VAR_UNLOCKED, 'test', 3))
- eq(true, tv_check_lock(lib.VAR_LOCKED, 'test', 3,
- 'E741: Value is locked: tes'))
- eq(true, tv_check_lock(lib.VAR_FIXED, 'test', 3,
- 'E742: Cannot change value of tes'))
- eq(true, tv_check_lock(lib.VAR_LOCKED, nil, 0,
- 'E741: Value is locked: Unknown'))
- eq(true, tv_check_lock(lib.VAR_FIXED, nil, 0,
- 'E742: Cannot change value of Unknown'))
- eq(true, tv_check_lock(lib.VAR_LOCKED, nil, lib.kTVCstring,
- 'E741: Value is locked: Unknown'))
- eq(true, tv_check_lock(lib.VAR_FIXED, 'test', lib.kTVCstring,
- 'E742: Cannot change value of test'))
+ eq(true, tv_check_lock(lib.VAR_LOCKED, 'test', 3, 'E741: Value is locked: tes'))
+ eq(true, tv_check_lock(lib.VAR_FIXED, 'test', 3, 'E742: Cannot change value of tes'))
+ eq(true, tv_check_lock(lib.VAR_LOCKED, nil, 0, 'E741: Value is locked: Unknown'))
+ eq(true, tv_check_lock(lib.VAR_FIXED, nil, 0, 'E742: Cannot change value of Unknown'))
+ eq(
+ true,
+ tv_check_lock(lib.VAR_LOCKED, nil, lib.kTVCstring, 'E741: Value is locked: Unknown')
+ )
+ eq(
+ true,
+ tv_check_lock(lib.VAR_FIXED, 'test', lib.kTVCstring, 'E742: Cannot change value of test')
+ )
end)
end)
describe('equal()', function()
@@ -2683,15 +2944,15 @@ describe('typval.c', function()
-- indicates that tv_equal_recurse_limit and recursive_cnt were set which
-- is essential. This argument will be set when comparing inner lists.
itp('compares lists correctly when case is not ignored', function()
- local l1 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'})
- local l2 = lua2typvalt({'abc', {1, 2, 'Abc'}})
- local l3 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'Def'})
- local l4 = lua2typvalt({'abc', {1, 2, 'Abc', 4}, 'def'})
- local l5 = lua2typvalt({'Abc', {1, 2, 'Abc'}, 'def'})
- local l6 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'})
- local l7 = lua2typvalt({'abc', {1, 2, 'abc'}, 'def'})
- local l8 = lua2typvalt({'abc', nil, 'def'})
- local l9 = lua2typvalt({'abc', {1, 2, nil}, 'def'})
+ local l1 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'def' })
+ local l2 = lua2typvalt({ 'abc', { 1, 2, 'Abc' } })
+ local l3 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'Def' })
+ local l4 = lua2typvalt({ 'abc', { 1, 2, 'Abc', 4 }, 'def' })
+ local l5 = lua2typvalt({ 'Abc', { 1, 2, 'Abc' }, 'def' })
+ local l6 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'def' })
+ local l7 = lua2typvalt({ 'abc', { 1, 2, 'abc' }, 'def' })
+ local l8 = lua2typvalt({ 'abc', nil, 'def' })
+ local l9 = lua2typvalt({ 'abc', { 1, 2, nil }, 'def' })
eq(true, lib.tv_equal(l1, l1, false, false))
eq(false, lib.tv_equal(l1, l2, false, false))
@@ -2704,15 +2965,15 @@ describe('typval.c', function()
eq(false, lib.tv_equal(l1, l9, false, false))
end)
itp('compares lists correctly when case is ignored', function()
- local l1 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'})
- local l2 = lua2typvalt({'abc', {1, 2, 'Abc'}})
- local l3 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'Def'})
- local l4 = lua2typvalt({'abc', {1, 2, 'Abc', 4}, 'def'})
- local l5 = lua2typvalt({'Abc', {1, 2, 'Abc'}, 'def'})
- local l6 = lua2typvalt({'abc', {1, 2, 'Abc'}, 'def'})
- local l7 = lua2typvalt({'abc', {1, 2, 'abc'}, 'def'})
- local l8 = lua2typvalt({'abc', nil, 'def'})
- local l9 = lua2typvalt({'abc', {1, 2, nil}, 'def'})
+ local l1 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'def' })
+ local l2 = lua2typvalt({ 'abc', { 1, 2, 'Abc' } })
+ local l3 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'Def' })
+ local l4 = lua2typvalt({ 'abc', { 1, 2, 'Abc', 4 }, 'def' })
+ local l5 = lua2typvalt({ 'Abc', { 1, 2, 'Abc' }, 'def' })
+ local l6 = lua2typvalt({ 'abc', { 1, 2, 'Abc' }, 'def' })
+ local l7 = lua2typvalt({ 'abc', { 1, 2, 'abc' }, 'def' })
+ local l8 = lua2typvalt({ 'abc', nil, 'def' })
+ local l9 = lua2typvalt({ 'abc', { 1, 2, nil }, 'def' })
eq(true, lib.tv_equal(l1, l1, true, false))
eq(false, lib.tv_equal(l1, l2, true, false))
@@ -2732,20 +2993,20 @@ describe('typval.c', function()
eq(true, tv_equal(nd, nd))
alloc_log:check({})
local d1 = lua2typvalt({})
- alloc_log:check({a.dict(d1.vval.v_dict)})
+ alloc_log:check({ a.dict(d1.vval.v_dict) })
eq(1, d1.vval.v_dict.dv_refcount)
eq(true, tv_equal(nd, d1))
eq(true, tv_equal(d1, nd))
eq(true, tv_equal(d1, d1))
eq(1, d1.vval.v_dict.dv_refcount)
alloc_log:check({})
- local d_upper = lua2typvalt({a='TEST'})
+ local d_upper = lua2typvalt({ a = 'TEST' })
local dis_upper = dict_items(d_upper.vval.v_dict)
- local d_lower = lua2typvalt({a='test'})
+ local d_lower = lua2typvalt({ a = 'test' })
local dis_lower = dict_items(d_lower.vval.v_dict)
- local d_kupper_upper = lua2typvalt({A='TEST'})
+ local d_kupper_upper = lua2typvalt({ A = 'TEST' })
local dis_kupper_upper = dict_items(d_kupper_upper.vval.v_dict)
- local d_kupper_lower = lua2typvalt({A='test'})
+ local d_kupper_lower = lua2typvalt({ A = 'test' })
local dis_kupper_lower = dict_items(d_kupper_lower.vval.v_dict)
alloc_log:clear_tmp_allocs()
alloc_log:check({
@@ -2781,24 +3042,31 @@ describe('typval.c', function()
itp('works', function()
local tv = typvalt()
local mem = lib.xmalloc(1)
- tv.vval.v_list = mem -- Should crash when actually accessed
+ tv.vval.v_list = mem -- Should crash when actually accessed
alloc_log:clear()
for _, v in ipairs({
- {lib.VAR_NUMBER, nil},
- {lib.VAR_FLOAT, 'E805: Expected a Number or a String, Float found'},
- {lib.VAR_PARTIAL, 'E703: Expected a Number or a String, Funcref found'},
- {lib.VAR_FUNC, 'E703: Expected a Number or a String, Funcref found'},
- {lib.VAR_LIST, 'E745: Expected a Number or a String, List found'},
- {lib.VAR_DICT, 'E728: Expected a Number or a String, Dictionary found'},
- {lib.VAR_SPECIAL, 'E5300: Expected a Number or a String'},
- {lib.VAR_UNKNOWN, 'E685: Internal error: tv_check_str_or_nr(UNKNOWN)'},
+ { lib.VAR_NUMBER, nil },
+ { lib.VAR_FLOAT, 'E805: Expected a Number or a String, Float found' },
+ { lib.VAR_PARTIAL, 'E703: Expected a Number or a String, Funcref found' },
+ { lib.VAR_FUNC, 'E703: Expected a Number or a String, Funcref found' },
+ { lib.VAR_LIST, 'E745: Expected a Number or a String, List found' },
+ { lib.VAR_DICT, 'E728: Expected a Number or a String, Dictionary found' },
+ { lib.VAR_SPECIAL, 'E5300: Expected a Number or a String' },
+ { lib.VAR_UNKNOWN, 'E685: Internal error: tv_check_str_or_nr(UNKNOWN)' },
}) do
local typ = v[1]
local emsg = v[2]
local ret = true
- if emsg then ret = false end
+ if emsg then
+ ret = false
+ end
tv.v_type = typ
- eq(ret, check_emsg(function() return lib.tv_check_str_or_nr(tv) end, emsg))
+ eq(
+ ret,
+ check_emsg(function()
+ return lib.tv_check_str_or_nr(tv)
+ end, emsg)
+ )
if emsg then
alloc_log:clear()
else
@@ -2811,24 +3079,31 @@ describe('typval.c', function()
itp('works', function()
local tv = typvalt()
local mem = lib.xmalloc(1)
- tv.vval.v_list = mem -- Should crash when actually accessed
+ tv.vval.v_list = mem -- Should crash when actually accessed
alloc_log:clear()
for _, v in ipairs({
- {lib.VAR_NUMBER, nil},
- {lib.VAR_FLOAT, 'E805: Using a Float as a Number'},
- {lib.VAR_PARTIAL, 'E703: Using a Funcref as a Number'},
- {lib.VAR_FUNC, 'E703: Using a Funcref as a Number'},
- {lib.VAR_LIST, 'E745: Using a List as a Number'},
- {lib.VAR_DICT, 'E728: Using a Dictionary as a Number'},
- {lib.VAR_SPECIAL, nil},
- {lib.VAR_UNKNOWN, 'E685: using an invalid value as a Number'},
+ { lib.VAR_NUMBER, nil },
+ { lib.VAR_FLOAT, 'E805: Using a Float as a Number' },
+ { lib.VAR_PARTIAL, 'E703: Using a Funcref as a Number' },
+ { lib.VAR_FUNC, 'E703: Using a Funcref as a Number' },
+ { lib.VAR_LIST, 'E745: Using a List as a Number' },
+ { lib.VAR_DICT, 'E728: Using a Dictionary as a Number' },
+ { lib.VAR_SPECIAL, nil },
+ { lib.VAR_UNKNOWN, 'E685: using an invalid value as a Number' },
}) do
local typ = v[1]
local emsg = v[2]
local ret = true
- if emsg then ret = false end
+ if emsg then
+ ret = false
+ end
tv.v_type = typ
- eq(ret, check_emsg(function() return lib.tv_check_num(tv) end, emsg))
+ eq(
+ ret,
+ check_emsg(function()
+ return lib.tv_check_num(tv)
+ end, emsg)
+ )
if emsg then
alloc_log:clear()
else
@@ -2841,25 +3116,32 @@ describe('typval.c', function()
itp('works', function()
local tv = typvalt()
local mem = lib.xmalloc(1)
- tv.vval.v_list = mem -- Should crash when actually accessed
+ tv.vval.v_list = mem -- Should crash when actually accessed
alloc_log:clear()
for _, v in ipairs({
- {lib.VAR_NUMBER, nil},
- {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'},
- {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_NUMBER, nil },
+ { 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' },
+ { 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' },
}) do
local typ = v[1]
local emsg = v[2]
local ret = true
- if emsg then ret = false end
+ if emsg then
+ ret = false
+ end
tv.v_type = typ
- eq(ret, check_emsg(function() return lib.tv_check_str(tv) end, emsg))
+ eq(
+ ret,
+ check_emsg(function()
+ return lib.tv_check_str(tv)
+ end, emsg)
+ )
if emsg then
alloc_log:clear()
else
@@ -2873,24 +3155,29 @@ describe('typval.c', function()
describe('number()', function()
itp('works', 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}, 'E805: Using a Float as a Number', 0},
- {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', 0},
- {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', 0},
- {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', 0},
- {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', 0},
- {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0},
- {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 1},
- {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 0},
- {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0},
+ { 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 }, 'E805: Using a Float as a Number', 0 },
+ { lib.VAR_PARTIAL, { v_partial = NULL }, 'E703: Using a Funcref as a Number', 0 },
+ { lib.VAR_FUNC, { v_string = NULL }, 'E703: Using a Funcref as a Number', 0 },
+ { lib.VAR_LIST, { v_list = NULL }, 'E745: Using a List as a Number', 0 },
+ { lib.VAR_DICT, { v_dict = NULL }, 'E728: Using a Dictionary as a Number', 0 },
+ { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 0 },
+ { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 1 },
+ { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 0 },
+ { lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0 },
}) 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() return lib.tv_get_number(tv) end, emsg))
+ eq(
+ ret,
+ check_emsg(function()
+ return lib.tv_get_number(tv)
+ end, emsg)
+ )
if emsg then
alloc_log:clear()
else
@@ -2902,28 +3189,31 @@ describe('typval.c', function()
describe('number_chk()', function()
itp('works', 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}, 'E805: Using a Float as a Number', 0},
- {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', 0},
- {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', 0},
- {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', 0},
- {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', 0},
- {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0},
- {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 1},
- {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 0},
- {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0},
+ { 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 }, 'E805: Using a Float as a Number', 0 },
+ { lib.VAR_PARTIAL, { v_partial = NULL }, 'E703: Using a Funcref as a Number', 0 },
+ { lib.VAR_FUNC, { v_string = NULL }, 'E703: Using a Funcref as a Number', 0 },
+ { lib.VAR_LIST, { v_list = NULL }, 'E745: Using a List as a Number', 0 },
+ { lib.VAR_DICT, { v_dict = NULL }, 'E728: Using a Dictionary as a Number', 0 },
+ { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 0 },
+ { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 1 },
+ { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 0 },
+ { lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', 0 },
}) 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], not not emsg}
- eq(ret, check_emsg(function()
- local err = ffi.new('bool[1]', {false})
- local res = lib.tv_get_number_chk(tv, err)
- return {res, err[0]}
- end, emsg))
+ local ret = { v[4], not not emsg }
+ eq(
+ ret,
+ check_emsg(function()
+ local err = ffi.new('bool[1]', { false })
+ local res = lib.tv_get_number_chk(tv, err)
+ return { res, err[0] }
+ end, emsg)
+ )
if emsg then
alloc_log:clear()
else
@@ -2935,18 +3225,18 @@ describe('typval.c', function()
describe('lnum()', function()
itp('works', 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_STRING, {v_string=to_cstr('.')}, nil, 46},
- {lib.VAR_FLOAT, {v_float=42.53}, 'E805: Using a Float as a Number', -1},
- {lib.VAR_PARTIAL, {v_partial=NULL}, 'E703: Using a Funcref as a Number', -1},
- {lib.VAR_FUNC, {v_string=NULL}, 'E703: Using a Funcref as a Number', -1},
- {lib.VAR_LIST, {v_list=NULL}, 'E745: Using a List as a Number', -1},
- {lib.VAR_DICT, {v_dict=NULL}, 'E728: Using a Dictionary as a Number', -1},
- {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, nil, 0},
- {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, nil, 1},
- {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, nil, 0},
- {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', -1},
+ { lib.VAR_NUMBER, { v_number = 42 }, nil, 42 },
+ { lib.VAR_STRING, { v_string = to_cstr('100500') }, nil, 100500 },
+ { lib.VAR_STRING, { v_string = to_cstr('.') }, nil, 46 },
+ { lib.VAR_FLOAT, { v_float = 42.53 }, 'E805: Using a Float as a Number', -1 },
+ { lib.VAR_PARTIAL, { v_partial = NULL }, 'E703: Using a Funcref as a Number', -1 },
+ { lib.VAR_FUNC, { v_string = NULL }, 'E703: Using a Funcref as a Number', -1 },
+ { lib.VAR_LIST, { v_list = NULL }, 'E745: Using a List as a Number', -1 },
+ { lib.VAR_DICT, { v_dict = NULL }, 'E728: Using a Dictionary as a Number', -1 },
+ { lib.VAR_SPECIAL, { v_special = lib.kSpecialVarNull }, nil, 0 },
+ { lib.VAR_BOOL, { v_bool = lib.kBoolVarTrue }, nil, 1 },
+ { lib.VAR_BOOL, { v_bool = lib.kBoolVarFalse }, nil, 0 },
+ { lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_number(UNKNOWN)', -1 },
}) do
lib.curwin.w_cursor.lnum = 46
-- Using to_cstr, cannot free with tv_clear
@@ -2954,7 +3244,12 @@ describe('typval.c', function()
alloc_log:check({})
local emsg = v[3]
local ret = v[4]
- eq(ret, check_emsg(function() return lib.tv_get_lnum(tv) end, emsg))
+ eq(
+ ret,
+ check_emsg(function()
+ return lib.tv_get_lnum(tv)
+ end, emsg)
+ )
if emsg then
alloc_log:clear()
else
@@ -2966,24 +3261,49 @@ describe('typval.c', function()
describe('float()', function()
itp('works', function()
for _, v in ipairs({
- {lib.VAR_NUMBER, {v_number=42}, nil, 42},
- {lib.VAR_STRING, {v_string=to_cstr('100500')}, 'E892: Using a String as a Float', 0},
- {lib.VAR_FLOAT, {v_float=42.53}, nil, 42.53},
- {lib.VAR_PARTIAL, {v_partial=NULL}, 'E891: Using a Funcref as a Float', 0},
- {lib.VAR_FUNC, {v_string=NULL}, 'E891: Using a Funcref as a Float', 0},
- {lib.VAR_LIST, {v_list=NULL}, 'E893: Using a List as a Float', 0},
- {lib.VAR_DICT, {v_dict=NULL}, 'E894: Using a Dictionary as a Float', 0},
- {lib.VAR_SPECIAL, {v_special=lib.kSpecialVarNull}, 'E907: Using a special value as a Float', 0},
- {lib.VAR_BOOL, {v_bool=lib.kBoolVarTrue}, 'E362: Using a boolean value as a Float', 0},
- {lib.VAR_BOOL, {v_bool=lib.kBoolVarFalse}, 'E362: Using a boolean value as a Float', 0},
- {lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_float(UNKNOWN)', 0},
+ { lib.VAR_NUMBER, { v_number = 42 }, nil, 42 },
+ {
+ lib.VAR_STRING,
+ { v_string = to_cstr('100500') },
+ 'E892: Using a String as a Float',
+ 0,
+ },
+ { lib.VAR_FLOAT, { v_float = 42.53 }, nil, 42.53 },
+ { lib.VAR_PARTIAL, { v_partial = NULL }, 'E891: Using a Funcref as a Float', 0 },
+ { lib.VAR_FUNC, { v_string = NULL }, 'E891: Using a Funcref as a Float', 0 },
+ { lib.VAR_LIST, { v_list = NULL }, 'E893: Using a List as a Float', 0 },
+ { lib.VAR_DICT, { v_dict = NULL }, 'E894: Using a Dictionary as a Float', 0 },
+ {
+ lib.VAR_SPECIAL,
+ { v_special = lib.kSpecialVarNull },
+ 'E907: Using a special value as a Float',
+ 0,
+ },
+ {
+ lib.VAR_BOOL,
+ { v_bool = lib.kBoolVarTrue },
+ 'E362: Using a boolean value as a Float',
+ 0,
+ },
+ {
+ lib.VAR_BOOL,
+ { v_bool = lib.kBoolVarFalse },
+ 'E362: Using a boolean value as a Float',
+ 0,
+ },
+ { lib.VAR_UNKNOWN, nil, 'E685: Internal error: tv_get_float(UNKNOWN)', 0 },
}) 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() return lib.tv_get_float(tv) end, emsg))
+ eq(
+ ret,
+ check_emsg(function()
+ return lib.tv_get_float(tv)
+ end, emsg)
+ )
if emsg then
alloc_log:clear()
else
@@ -3001,24 +3321,31 @@ describe('typval.c', function()
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))
+ 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), a.freed(alloc_log.null)})
+ alloc_log:check({ a.freed(alloc_log.null), a.freed(alloc_log.null) })
else
alloc_log:check({})
end
@@ -3030,17 +3357,17 @@ describe('typval.c', function()
local buf_chk = lib.tv_get_string_chk(lua2typvalt(int(1)))
neq(buf, buf_chk)
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}, 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', ''},
- {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'},
- {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''},
+ { 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 }, 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', '' },
+ { 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' },
+ { lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', '' },
}, function(tv)
return lib.tv_get_string(tv), buf
end)
@@ -3050,17 +3377,17 @@ describe('typval.c', function()
itp('works', function()
local buf = lib.tv_get_string_chk(lua2typvalt(int(1)))
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}, 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},
- {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'},
- {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil},
+ { 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 }, 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 },
+ { 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' },
+ { lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil },
}, function(tv)
return lib.tv_get_string_chk(tv), buf
end)
@@ -3069,19 +3396,19 @@ describe('typval.c', function()
describe('string_buf()', function()
itp('works', function()
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}, 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', ''},
- {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'},
- {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', ''},
+ { 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 }, 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', '' },
+ { 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' },
+ { lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', '' },
}, function(tv)
- local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0})
+ local buf = ffi.new('char[?]', lib.NUMBUFLEN, { 0 })
return lib.tv_get_string_buf(tv, buf), buf
end)
end)
@@ -3089,19 +3416,19 @@ describe('typval.c', function()
describe('string_buf_chk()', function()
itp('works', function()
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}, 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},
- {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'},
- {lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil},
+ { 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 }, 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 },
+ { 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' },
+ { lib.VAR_UNKNOWN, nil, 'E908: Using an invalid value as a String', nil },
}, function(tv)
- local buf = ffi.new('char[?]', lib.NUMBUFLEN, {0})
+ local buf = ffi.new('char[?]', lib.NUMBUFLEN, { 0 })
return lib.tv_get_string_buf_chk(tv, buf), buf
end)
end)
diff --git a/test/unit/fileio_spec.lua b/test/unit/fileio_spec.lua
index 066d013b19..1284f84222 100644
--- a/test/unit/fileio_spec.lua
+++ b/test/unit/fileio_spec.lua
@@ -1,24 +1,23 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
--{:cimport, :internalize, :eq, :neq, :ffi, :lib, :cstr, :to_cstr} = require 'test.unit.helpers'
-local eq = helpers.eq
-local ffi = helpers.ffi
+local eq = helpers.eq
+local ffi = helpers.ffi
local to_cstr = helpers.to_cstr
-local NULL = helpers.NULL
+local NULL = helpers.NULL
-local fileio = helpers.cimport("./src/nvim/fileio.h")
+local fileio = helpers.cimport('./src/nvim/fileio.h')
describe('file_pat functions', function()
describe('file_pat_to_reg_pat', function()
-
local file_pat_to_reg_pat = function(pat)
local res = fileio.file_pat_to_reg_pat(to_cstr(pat), NULL, NULL, 0)
return ffi.string(res)
end
itp('returns ^path$ regex for literal path input', function()
- eq( '^path$', file_pat_to_reg_pat('path'))
+ eq('^path$', file_pat_to_reg_pat('path'))
end)
itp('does not prepend ^ when there is a starting glob (*)', function()
@@ -34,13 +33,15 @@ describe('file_pat functions', function()
end)
itp('replaces the bash any character (?) with the regex any character (.)', function()
- eq('^foo.bar$', file_pat_to_reg_pat('foo?bar'))
+ eq('^foo.bar$', file_pat_to_reg_pat('foo?bar'))
end)
- itp('replaces a glob (*) in the middle of a path with regex multiple any character (.*)',
- function()
- eq('^foo.*bar$', file_pat_to_reg_pat('foo*bar'))
- end)
+ itp(
+ 'replaces a glob (*) in the middle of a path with regex multiple any character (.*)',
+ function()
+ eq('^foo.*bar$', file_pat_to_reg_pat('foo*bar'))
+ end
+ )
itp([[unescapes \? to ?]], function()
eq('^foo?bar$', file_pat_to_reg_pat([[foo\?bar]]))
diff --git a/test/unit/fixtures/multiqueue.c b/test/unit/fixtures/multiqueue.c
index 3a5ddab4b8..149daca893 100644
--- a/test/unit/fixtures/multiqueue.c
+++ b/test/unit/fixtures/multiqueue.c
@@ -6,7 +6,7 @@
void ut_multiqueue_put(MultiQueue *self, const char *str)
{
- multiqueue_put(self, NULL, 1, str);
+ multiqueue_put(self, NULL, (void *)str);
}
const char *ut_multiqueue_get(MultiQueue *self)
diff --git a/test/unit/formatc.lua b/test/unit/formatc.lua
index c94f0d88f7..ce9cb81f4a 100644
--- a/test/unit/formatc.lua
+++ b/test/unit/formatc.lua
@@ -24,103 +24,145 @@ SOFTWARE. --]]
-- work.
-- see: http://lua-users.org/wiki/LpegRecipes
-local lpeg = require "lpeg"
+local lpeg = require 'lpeg'
local C, P, R, S, V = lpeg.C, lpeg.P, lpeg.R, lpeg.S, lpeg.V
local Carg, Cc, Cp, Ct = lpeg.Carg, lpeg.Cc, lpeg.Cp, lpeg.Ct
-local tokens = P { "tokens";
+local tokens = P {
+ 'tokens',
-- Comment of form /* ... */
- comment = Ct(P"/*" * C((V"newline" + (1 - P"*/"))^0) * P"*/" * Cc"comment"),
+ comment = Ct(P '/*' * C((V 'newline' + (1 - P '*/')) ^ 0) * P '*/' * Cc 'comment'),
-- Single line comment
- line_comment = Ct(P"//" * C((1 - V"newline")^0) * Cc"comment_line"),
+ line_comment = Ct(P '//' * C((1 - V 'newline') ^ 0) * Cc 'comment_line'),
-- Single platform independent line break which increments line number
- newline = (P"\r\n" + P"\n\r" + S"\r\n") * (Cp() * Carg(1)) / function(pos, state)
+ newline = (P '\r\n' + P '\n\r' + S '\r\n') * (Cp() * Carg(1)) / function(pos, state)
state.line = state.line + 1
state.line_start = pos
end,
-- Line continuation
- line_extend = Ct(C(P[[\]] * V"newline") * Cc"line_extend"),
+ line_extend = Ct(C(P [[\]] * V 'newline') * Cc 'line_extend'),
-- Whitespace of any length (includes newlines)
- whitespace = Ct(C((S" \t" + V"newline")^1) * Cc"whitespace"),
+ whitespace = Ct(C((S ' \t' + V 'newline') ^ 1) * Cc 'whitespace'),
-- Special form of #include with filename followed in angled brackets (matches 3 tokens)
- include = Ct(C(P"#include") * Cc"preprocessor") *
- Ct(C(S" \t"^1) * Cc"whitespace") *
- Ct(C(P"<" * (1 - P">")^1 * P">") * Cc"string"),
+ include = Ct(C(P '#include') * Cc 'preprocessor') * Ct(C(S ' \t' ^ 1) * Cc 'whitespace') * Ct(
+ C(P '<' * (1 - P '>') ^ 1 * P '>') * Cc 'string'
+ ),
-- Preprocessor instruction
- preprocessor = V"include" +
- Ct(C(P"#" * P" "^0 * ( P"define" + P"elif" + P"else" + P"endif" + P"#" +
- P"error" + P"ifdef" + P"ifndef" + P"if" + P"import" +
- P"include" + P"line" + P"pragma" + P"undef" + P"using" +
- P"pragma"
- ) * #S" \r\n\t") * Cc"preprocessor"),
+ preprocessor = V 'include'
+ + Ct(
+ C(
+ P '#'
+ * P ' ' ^ 0
+ * (P 'define' + P 'elif' + P 'else' + P 'endif' + P '#' + P 'error' + P 'ifdef' + P 'ifndef' + P 'if' + P 'import' + P 'include' + P 'line' + P 'pragma' + P 'undef' + P 'using' + P 'pragma')
+ * #S ' \r\n\t'
+ ) * Cc 'preprocessor'
+ ),
-- Identifier of form [a-zA-Z_][a-zA-Z0-9_]*
- identifier = Ct(C(R("az","AZ","__") * R("09","az","AZ","__")^0) * Cc"identifier"),
+ identifier = Ct(C(R('az', 'AZ', '__') * R('09', 'az', 'AZ', '__') ^ 0) * Cc 'identifier'),
-- Single character in a string
- sstring_char = R("\001&","([","]\255") + (P"\\" * S[[ntvbrfa\?'"0x]]),
- dstring_char = R("\001!","#[","]\255") + (P"\\" * S[[ntvbrfa\?'"0x]]),
+ sstring_char = R('\001&', '([', ']\255') + (P '\\' * S [[ntvbrfa\?'"0x]]),
+ dstring_char = R('\001!', '#[', ']\255') + (P '\\' * S [[ntvbrfa\?'"0x]]),
-- String literal
- string = Ct(C(P"'" * (V"sstring_char" + P'"')^0 * P"'" +
- P'"' * (V"dstring_char" + P"'")^0 * P'"') * Cc"string"),
+ string = Ct(
+ C(
+ P "'" * (V 'sstring_char' + P '"') ^ 0 * P "'"
+ + P '"' * (V 'dstring_char' + P "'") ^ 0 * P '"'
+ ) * Cc 'string'
+ ),
-- Operator
- operator = Ct(C(P">>=" + P"<<=" + P"..." +
- P"::" + P"<<" + P">>" + P"<=" + P">=" + P"==" + P"!=" +
- P"||" + P"&&" + P"++" + P"--" + P"->" + P"+=" + P"-=" +
- P"*=" + P"/=" + P"|=" + P"&=" + P"^=" + S"+-*/=<>%^|&.?:!~,") * Cc"operator"),
+ operator = Ct(
+ C(
+ P '>>='
+ + P '<<='
+ + P '...'
+ + P '::'
+ + P '<<'
+ + P '>>'
+ + P '<='
+ + P '>='
+ + P '=='
+ + P '!='
+ + P '||'
+ + P '&&'
+ + P '++'
+ + P '--'
+ + P '->'
+ + P '+='
+ + P '-='
+ + P '*='
+ + P '/='
+ + P '|='
+ + P '&='
+ + P '^='
+ + S '+-*/=<>%^|&.?:!~,'
+ ) * Cc 'operator'
+ ),
-- Misc. char (token type is the character itself)
- char = Ct(C(S"[]{}();") / function(x) return x, x end),
+ char = Ct(C(S '[]{}();') / function(x)
+ return x, x
+ end),
-- Hex, octal or decimal number
- int = Ct(C((P"0x" * R("09","af","AF")^1) + (P"0" * R"07"^0) + R"09"^1) * Cc"integer"),
+ int = Ct(
+ C((P '0x' * R('09', 'af', 'AF') ^ 1) + (P '0' * R '07' ^ 0) + R '09' ^ 1) * Cc 'integer'
+ ),
-- Floating point number
- f_exponent = S"eE" + S"+-"^-1 * R"09"^1,
- f_terminator = S"fFlL",
- float = Ct(C(
- R"09"^1 * V"f_exponent" * V"f_terminator"^-1 +
- R"09"^0 * P"." * R"09"^1 * V"f_exponent"^-1 * V"f_terminator"^-1 +
- R"09"^1 * P"." * R"09"^0 * V"f_exponent"^-1 * V"f_terminator"^-1
- ) * Cc"float"),
+ f_exponent = S 'eE' + S '+-' ^ -1 * R '09' ^ 1,
+ f_terminator = S 'fFlL',
+ float = Ct(
+ C(
+ R '09' ^ 1 * V 'f_exponent' * V 'f_terminator' ^ -1
+ + R '09' ^ 0 * P '.' * R '09' ^ 1 * V 'f_exponent' ^ -1 * V 'f_terminator' ^ -1
+ + R '09' ^ 1 * P '.' * R '09' ^ 0 * V 'f_exponent' ^ -1 * V 'f_terminator' ^ -1
+ ) * Cc 'float'
+ ),
-- Any token
- token = V"comment" +
- V"line_comment" +
- V"identifier" +
- V"whitespace" +
- V"line_extend" +
- V"preprocessor" +
- V"string" +
- V"char" +
- V"operator" +
- V"float" +
- V"int",
+ token = V 'comment'
+ + V 'line_comment'
+ + V 'identifier'
+ + V 'whitespace'
+ + V 'line_extend'
+ + V 'preprocessor'
+ + V 'string'
+ + V 'char'
+ + V 'operator'
+ + V 'float'
+ + V 'int',
-- Error for when nothing else matches
error = (Cp() * C(P(1) ^ -8) * Carg(1)) / function(pos, where, state)
- error(("Tokenising error on line %i, position %i, near '%s'")
- :format(state.line, pos - state.line_start + 1, where))
+ error(
+ ("Tokenising error on line %i, position %i, near '%s'"):format(
+ state.line,
+ pos - state.line_start + 1,
+ where
+ )
+ )
end,
-- Match end of input or throw error
- finish = -P(1) + V"error",
+ finish = -P(1) + V 'error',
-- Match stream of tokens into a table
- tokens = Ct(V"token" ^ 0) * V"finish",
+ tokens = Ct(V 'token' ^ 0) * V 'finish',
}
local function TokeniseC(str)
- return tokens:match(str, 1, {line = 1, line_start = 1})
+ return tokens:match(str, 1, { line = 1, line_start = 1 })
end
local function set(t)
@@ -131,16 +173,43 @@ local function set(t)
return s
end
-local C_keywords = set { -- luacheck: ignore
- "break", "case", "char", "const", "continue", "default", "do", "double",
- "else", "enum", "extern", "float", "for", "goto", "if", "int", "long",
- "register", "return", "short", "signed", "sizeof", "static", "struct",
- "switch", "typedef", "union", "unsigned", "void", "volatile", "while",
+local C_keywords = set { -- luacheck: ignore
+ 'break',
+ 'case',
+ 'char',
+ 'const',
+ 'continue',
+ 'default',
+ 'do',
+ 'double',
+ 'else',
+ 'enum',
+ 'extern',
+ 'float',
+ 'for',
+ 'goto',
+ 'if',
+ 'int',
+ 'long',
+ 'register',
+ 'return',
+ 'short',
+ 'signed',
+ 'sizeof',
+ 'static',
+ 'struct',
+ 'switch',
+ 'typedef',
+ 'union',
+ 'unsigned',
+ 'void',
+ 'volatile',
+ 'while',
}
-- Very primitive C formatter that tries to put "things" inside braces on one
-- line. This is a step done after preprocessing the C source to ensure that
--- the duplicate line detecter can more reliably pick out identical declarations.
+-- the duplicate line detector can more reliably pick out identical declarations.
--
-- an example:
-- struct mystruct
@@ -174,7 +243,7 @@ local function formatc(str)
-- if we're not inside a block, we're at the basic statement level,
-- and ';' indicates we're at the end of a statement, so we put end
-- it with a newline.
- token[1] = token[1] .. "\n"
+ token[1] = token[1] .. '\n'
end_at_brace = false
end
elseif typ == 'identifier' then
@@ -194,20 +263,20 @@ local function formatc(str)
-- if we're not inside a block, we're at the basic statement level,
-- and ';' indicates we're at the end of a statement, so we put end
-- it with a newline.
- token[1] = ";\n"
+ token[1] = ';\n'
end
elseif typ == 'whitespace' then
-- replace all whitespace by one space
- local repl = " "
+ local repl = ' '
-- except when allow_on_nl is true and there's a newline in the whitespace
- if string.find(token[1], "[\r\n]+") and allow_one_nl == true then
+ if string.find(token[1], '[\r\n]+') and allow_one_nl == true then
-- in that case we replace all whitespace by one newline
- repl = "\n"
+ repl = '\n'
allow_one_nl = false
end
- token[1] = string.gsub(token[1], "%s+", repl)
+ token[1] = string.gsub(token[1], '%s+', repl)
end
result[#result + 1] = token[1]
end
@@ -216,8 +285,8 @@ local function formatc(str)
end
-- standalone operation (very handy for debugging)
-local function standalone(...) -- luacheck: ignore
- local Preprocess = require("preprocess")
+local function standalone(...) -- luacheck: ignore
+ local Preprocess = require('preprocess')
Preprocess.add_to_include_path('./../../src')
Preprocess.add_to_include_path('./../../build/include')
Preprocess.add_to_include_path('./../../.deps/usr/include')
@@ -226,9 +295,9 @@ local function standalone(...) -- luacheck: ignore
local formatted
if #arg == 2 and arg[2] == 'no' then
- formatted = raw
+ formatted = raw
else
- formatted = formatc(raw)
+ formatted = formatc(raw)
end
print(formatted)
diff --git a/test/unit/garray_spec.lua b/test/unit/garray_spec.lua
index 5d41dd39ec..0f947c42b8 100644
--- a/test/unit/garray_spec.lua
+++ b/test/unit/garray_spec.lua
@@ -1,4 +1,4 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local cimport = helpers.cimport
@@ -47,7 +47,7 @@ local ga_size = function(garr)
return ga_len(garr) * ga_itemsize(garr)
end
-local ga_maxsize = function(garr) -- luacheck: ignore
+local ga_maxsize = function(garr) -- luacheck: ignore
return ga_maxlen(garr) * ga_itemsize(garr)
end
@@ -157,7 +157,9 @@ local ga_append_ints = function(garr, ...)
end
-- enhanced constructors
-local garray_ctype = function(...) return ffi.typeof('garray_T[1]')(...) end
+local garray_ctype = function(...)
+ return ffi.typeof('garray_T[1]')(...)
+end
local new_garray = function()
local garr = garray_ctype()
return ffi.gc(garr, ga_clear)
@@ -165,7 +167,7 @@ end
local new_string_garray = function()
local garr = garray_ctype()
- ga_init(garr, ffi.sizeof("unsigned char *"), 1)
+ ga_init(garr, ffi.sizeof('unsigned char *'), 1)
return ffi.gc(garr, ga_clear_strings)
end
@@ -182,7 +184,6 @@ local ga_scramble = function(garr)
end
describe('garray', function()
-
describe('ga_init', function()
itp('initializes the values of the garray', function()
local garr = new_garray()
@@ -199,9 +200,9 @@ describe('garray', function()
local function new_and_grow(itemsize_, growsize_, req)
local garr = new_garray()
ga_init(garr, itemsize_, growsize_)
- eq(0, ga_size(garr)) -- should be 0 at first
- eq(NULL, ga_data(garr)) -- should be NULL
- ga_grow(garr, req) -- add space for `req` items
+ eq(0, ga_size(garr)) -- should be 0 at first
+ eq(NULL, ga_data(garr)) -- should be NULL
+ ga_grow(garr, req) -- add space for `req` items
return garr
end
@@ -210,8 +211,8 @@ describe('garray', function()
growsize = 4
local grow_by = growsize - 1
local garr = new_and_grow(itemsize, growsize, grow_by)
- neq(NULL, ga_data(garr)) -- data should be a ptr to memory
- eq(growsize, ga_maxlen(garr)) -- we requested LESS than growsize, so...
+ neq(NULL, ga_data(garr)) -- data should be a ptr to memory
+ eq(growsize, ga_maxlen(garr)) -- we requested LESS than growsize, so...
end)
itp('grows by num items if num > growsize', function()
@@ -219,8 +220,8 @@ describe('garray', function()
growsize = 4
local grow_by = growsize + 1
local garr = new_and_grow(itemsize, growsize, grow_by)
- neq(NULL, ga_data(garr)) -- data should be a ptr to memory
- eq(grow_by, ga_maxlen(garr)) -- we requested MORE than growsize, so...
+ neq(NULL, ga_data(garr)) -- data should be a ptr to memory
+ eq(grow_by, ga_maxlen(garr)) -- we requested MORE than growsize, so...
end)
itp('does not grow when nothing is requested', function()
@@ -252,7 +253,7 @@ describe('garray', function()
-- this is the actual ga_append, the others are just emulated lua
-- versions
local garr = new_garray()
- ga_init(garr, ffi.sizeof("uint8_t"), 1)
+ ga_init(garr, ffi.sizeof('uint8_t'), 1)
ga_append(garr, 'h')
ga_append(garr, 'e')
ga_append(garr, 'l')
@@ -265,13 +266,13 @@ describe('garray', function()
itp('can append integers', function()
local garr = new_garray()
- ga_init(garr, ffi.sizeof("int"), 1)
+ ga_init(garr, ffi.sizeof('int'), 1)
local input = {
-20,
94,
867615,
90927,
- 86
+ 86,
}
ga_append_ints(garr, unpack(input))
local ints = ga_data_as_ints(garr)
@@ -283,11 +284,11 @@ describe('garray', function()
itp('can append strings to a growing array of strings', function()
local garr = new_string_garray()
local input = {
- "some",
- "str",
- "\r\n\r●●●●●●,,,",
- "hmm",
- "got it"
+ 'some',
+ 'str',
+ '\r\n\r●●●●●●,,,',
+ 'hmm',
+ 'got it',
}
ga_append_strings(garr, unpack(input))
-- check that we can get the same strings out of the array
@@ -301,8 +302,8 @@ describe('garray', function()
describe('ga_concat', function()
itp('concatenates the parameter to the growing byte array', function()
local garr = new_garray()
- ga_init(garr, ffi.sizeof("char"), 1)
- local str = "ohwell●●"
+ ga_init(garr, ffi.sizeof('char'), 1)
+ local str = 'ohwell●●'
local loop = 5
for _ = 1, loop do
ga_concat(garr, str)
@@ -331,21 +332,21 @@ describe('garray', function()
describe('ga_concat_strings', function()
itp('returns an empty string when concatenating an empty array', function()
- test_concat_fn({ }, ga_concat_strings)
+ test_concat_fn({}, ga_concat_strings)
end)
itp('can concatenate a non-empty array', function()
test_concat_fn({
'oh',
'my',
- 'neovim'
+ 'neovim',
}, ga_concat_strings)
end)
end)
describe('ga_concat_strings_sep', function()
itp('returns an empty string when concatenating an empty array', function()
- test_concat_fn({ }, ga_concat_strings_sep, '---')
+ test_concat_fn({}, ga_concat_strings_sep, '---')
end)
itp('can concatenate a non-empty array', function()
@@ -353,7 +354,7 @@ describe('garray', function()
test_concat_fn({
'oh',
'my',
- 'neovim'
+ 'neovim',
}, ga_concat_strings_sep, sep)
end)
end)
@@ -370,13 +371,13 @@ describe('garray', function()
'bbb',
'ccc',
'ccc',
- 'ddd●●'
+ 'ddd●●',
}
local sorted_dedup_input = {
'aaa',
'bbb',
'ccc',
- 'ddd●●'
+ 'ddd●●',
}
ga_append_strings(garr, unpack(input))
ga_remove_duplicate_strings(garr)
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua
index 8d581dac49..ab4a59cfdb 100644
--- a/test/unit/helpers.lua
+++ b/test/unit/helpers.lua
@@ -2,24 +2,24 @@ 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.cmakeconfig.paths')
local global_helpers = require('test.helpers')
+local paths = global_helpers.paths
local assert = require('luassert')
local say = require('say')
local check_cores = global_helpers.check_cores
local dedent = global_helpers.dedent
local neq = global_helpers.neq
-local map = global_helpers.tbl_map
+local map = vim.tbl_map
local eq = global_helpers.eq
-local trim = global_helpers.trim
+local trim = vim.trim
-- add some standard header locations
-for _, p in ipairs(Paths.include_paths) do
+for _, p in ipairs(paths.include_paths) do
Preprocess.add_to_include_path(p)
end
-local child_pid = nil --- @type integer
+local child_pid = nil --- @type integer?
--- @generic F: function
--- @param func F
--- @return F
@@ -49,7 +49,7 @@ local function child_call(func, ret)
return function(...)
local child_calls = child_calls_mod or child_calls_init
if child_pid ~= 0 then
- child_calls[#child_calls + 1] = {func=func, args={...}}
+ child_calls[#child_calls + 1] = { func = func, args = { ... } }
return ret
else
return func(...)
@@ -62,7 +62,7 @@ end
--- @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
@@ -75,7 +75,7 @@ local child_cleanups_mod_once = nil --- @type ChildCall[]?
local function child_cleanup_once(func, ...)
local child_cleanups = child_cleanups_mod_once
if child_pid ~= 0 then
- child_cleanups[#child_cleanups + 1] = {func=func, args={...}}
+ child_cleanups[#child_cleanups + 1] = { func = func, args = { ... } }
else
func(...)
end
@@ -133,25 +133,28 @@ local pragma_pack_id = 1
local function filter_complex_blocks(body)
local result = {} --- @type string[]
- for line in body:gmatch("[^\r\n]+") do
- 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_")
- or string.find(line, "UUID_NULL") -- static const uuid_t UUID_NULL = {...}
- or string.find(line, "inline _Bool")) then
+ for line in body:gmatch('[^\r\n]+') do
+ 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_')
+ or string.find(line, 'UUID_NULL') -- static const uuid_t UUID_NULL = {...}
+ or string.find(line, 'inline _Bool')
+ )
+ then
result[#result + 1] = line
end
end
- return table.concat(result, "\n")
+ return table.concat(result, '\n')
end
-
local cdef = ffi.cdef
local cimportstr
@@ -184,9 +187,8 @@ local function cimport(...)
previous_defines = previous_defines_init
cdefs = cdefs_init
end
- for _, path in ipairs({...}) do
- if not (path:sub(1, 1) == '/' or path:sub(1, 1) == '.'
- or path:sub(2, 2) == ':') then
+ for _, path in ipairs({ ... }) do
+ if not (path:sub(1, 1) == '/' or path:sub(1, 1) == '.' or path:sub(2, 2) == ':') then
path = './' .. path
end
if not preprocess_cache[path] then
@@ -205,15 +207,15 @@ local function cimport(...)
body = filter_complex_blocks(body)
-- add the formatted lines to a set
local new_cdefs = Set:new()
- for line in body:gmatch("[^\r\n]+") do
+ for line in body:gmatch('[^\r\n]+') do
line = trim(line)
-- give each #pragma pack an unique id, so that they don't get removed
-- if they are inserted into the set
-- (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
+ -- otherwise luajit has wrong memory layouts for the structs)
+ if line:match('#pragma%s+pack') then
--- @type string
- line = line .. " // " .. pragma_pack_id
+ line = line .. ' // ' .. pragma_pack_id
pragma_pack_id = pragma_pack_id + 1
end
new_cdefs:add(line)
@@ -277,13 +279,13 @@ end
local function alloc_log_new()
local log = {
- log={}, --- @type ChildCallLog[]
- lib=cimport('./src/nvim/memory.h'), --- @type table<string,function>
- original_functions={}, --- @type table<string,function>
- null={['\0:is_null']=true},
+ log = {}, --- @type ChildCallLog[]
+ lib = cimport('./src/nvim/memory.h'), --- @type table<string,function>
+ original_functions = {}, --- @type table<string,function>
+ null = { ['\0:is_null'] = true },
}
- local allocator_functions = {'malloc', 'free', 'calloc', 'realloc'}
+ local allocator_functions = { 'malloc', 'free', 'calloc', 'realloc' }
function log:save_original_functions()
for _, funcname in ipairs(allocator_functions) do
@@ -301,7 +303,7 @@ local function alloc_log_new()
local kk = k
self.lib['mem_' .. k] = function(...)
--- @type ChildCallLog
- local log_entry = { func = kk, args = {...} }
+ local log_entry = { func = kk, args = { ... } }
self.log[#self.log + 1] = log_entry
if kk == 'free' then
self.original_functions[kk](...)
@@ -314,7 +316,9 @@ local function alloc_log_new()
log_entry.args[i] = self.null
end
end
- if self.hook then self:hook(log_entry) end
+ if self.hook then
+ self:hook(log_entry)
+ end
if log_entry.ret then
return log_entry.ret
end
@@ -355,7 +359,7 @@ local function alloc_log_new()
end
end
table.sort(toremove)
- for i = #toremove,1,-1 do
+ for i = #toremove, 1, -1 do
table.remove(self.log, toremove[i])
end
end
@@ -365,11 +369,9 @@ local function alloc_log_new()
log:set_mocks()
end
- function log:before_each()
- end
+ function log:before_each() end
- function log:after_each()
- end
+ function log:after_each() end
log:setup()
@@ -397,13 +399,12 @@ function sc.fork()
end
function sc.pipe()
- local ret = ffi.new('int[2]', {-1, -1})
+ local ret = ffi.new('int[2]', { -1, -1 })
ffi.errno(0)
local res = ffi.C.pipe(ret)
- if (res ~= 0) then
+ if res ~= 0 then
local err = ffi.errno(0)
- assert(res == 0, ("pipe() error: %u: %s"):format(
- err, ffi.string(ffi.C.strerror(err))))
+ 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]
@@ -411,19 +412,16 @@ end
--- @return string
function sc.read(rd, len)
- local ret = ffi.new('char[?]', len, {0})
+ 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))
+ 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))))
+ assert(false, ('read() error: %u: %s'):format(err, ffi.string(ffi.C.strerror(err))))
end
elseif bytes_read == 0 then
break
@@ -439,15 +437,16 @@ function sc.write(wr, 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))
+ 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))
+ assert(
+ false,
+ ("write() error: %u: %s ('%s')"):format(err, ffi.string(ffi.C.strerror(err)), s)
+ )
end
elseif bytes_written == 0 then
break
@@ -464,7 +463,7 @@ sc.close = ffi.C.close
--- @return integer
function sc.wait(pid)
ffi.errno(0)
- local stat_loc = ffi.new('int[1]', {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
@@ -472,8 +471,7 @@ function sc.wait(pid)
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))))
+ assert(false, ('waitpid() error: %u: %s'):format(err, ffi.string(ffi.C.strerror(err))))
end
else
assert(r == pid)
@@ -489,7 +487,7 @@ sc.exit = ffi.C._exit
local function format_list(lst)
local ret = {} --- @type string[]
for _, v in ipairs(lst) do
- ret[#ret+1] = assert:format({v, n=1})[1]
+ ret[#ret + 1] = assert:format({ v, n = 1 })[1]
end
return table.concat(ret, ', ')
end
@@ -498,9 +496,8 @@ if os.getenv('NVIM_TEST_PRINT_SYSCALLS') == '1' then
for k_, v_ in pairs(sc) do
(function(k, v)
sc[k] = function(...)
- local rets = {v(...)}
- io.stderr:write(('%s(%s) = %s\n'):format(k, format_list({...}),
- format_list(rets)))
+ local rets = { v(...) }
+ io.stderr:write(('%s(%s) = %s\n'):format(k, format_list({ ... }), format_list(rets)))
return unpack(rets)
end
end)(k_, v_)
@@ -512,9 +509,13 @@ local function just_fail(_)
end
say:set('assertion.just_fail.positive', '%s')
say:set('assertion.just_fail.negative', '%s')
-assert:register('assertion', 'just_fail', just_fail,
- 'assertion.just_fail.positive',
- 'assertion.just_fail.negative')
+assert:register(
+ 'assertion',
+ 'just_fail',
+ just_fail,
+ 'assertion.just_fail.positive',
+ 'assertion.just_fail.negative'
+)
local hook_fnamelen = 30
local hook_sfnamelen = 30
@@ -561,7 +562,7 @@ local function child_sethook(wr)
local info = nil --- @type debuginfo?
if use_prev then
info = prev_info
- elseif reason ~= 'tail return' then -- tail return
+ elseif reason ~= 'tail return' then -- tail return
info = debug.getinfo(2, 'nSl')
end
@@ -609,17 +610,20 @@ local function child_sethook(wr)
-- assert(-1 <= lnum and lnum <= 99999)
local lnum_s = lnum == -1 and 'nknwn' or ('%u'):format(lnum)
--- @type string
- local msg = ( -- lua does not support %*
+ local msg = ( -- lua does not support %*
''
.. msgchar
.. whatchar
.. namewhatchar
.. ' '
- .. source .. (' '):rep(hook_sfnamelen - #source)
+ .. source
+ .. (' '):rep(hook_sfnamelen - #source)
.. ':'
- .. funcname .. (' '):rep(hook_fnamelen - #funcname)
+ .. funcname
+ .. (' '):rep(hook_fnamelen - #funcname)
.. ':'
- .. ('0'):rep(hook_numlen - #lnum_s) .. lnum_s
+ .. ('0'):rep(hook_numlen - #lnum_s)
+ .. lnum_s
.. '\n'
)
-- eq(hook_msglen, #msg)
@@ -724,7 +728,7 @@ local function check_child_err(rd)
--- @type string
err = err .. '\nNo end of trace occurred'
end
- local cc_err, cc_emsg = pcall(check_cores, Paths.test_luajit_prg, true)
+ 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
@@ -742,16 +746,16 @@ local function itp_parent(rd, pid, allow_failure, location)
sc.close(rd)
if not ok then
if allow_failure then
- io.stderr:write('Errorred out ('..status..'):\n' .. tostring(emsg) .. '\n')
+ io.stderr:write('Errorred out (' .. status .. '):\n' .. tostring(emsg) .. '\n')
os.execute([[
sh -c "source ci/common/test.sh
- check_core_dumps --delete \"]] .. Paths.test_luajit_prg .. [[\""]])
+ check_core_dumps --delete \"]] .. paths.test_luajit_prg .. [[\""]])
else
- error(tostring(emsg)..'\nexit code: '..status)
+ error(tostring(emsg) .. '\nexit code: ' .. status)
end
elseif status ~= 0 then
if not allow_failure then
- error("child process errored out with status "..status.."!\n\n"..location)
+ error('child process errored out with status ' .. status .. '!\n\n' .. location)
end
end
end
@@ -760,7 +764,9 @@ local function gen_itp(it)
child_calls_mod = {}
child_calls_mod_once = {}
child_cleanups_mod_once = {}
- preprocess_cache_mod = map(function(v) return v end, preprocess_cache_init)
+ preprocess_cache_mod = map(function(v)
+ return v
+ end, preprocess_cache_init)
previous_defines_mod = previous_defines_init
cdefs_mod = cdefs_init:copy()
local function itp(name, func, allow_failure)
@@ -791,11 +797,15 @@ local function gen_itp(it)
end
local function cppimport(path)
- return cimport(Paths.test_source_path .. '/test/includes/pre/' .. 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',
- './src/nvim/os/fs.h')
+cimport(
+ './src/nvim/types_defs.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)
@@ -844,7 +854,7 @@ local function ptr2addr(ptr)
return tonumber(ffi.cast('intptr_t', ffi.cast('void *', ptr)))
end
-local s = ffi.new('char[64]', {0})
+local s = ffi.new('char[64]', { 0 })
local function ptr2key(ptr)
ffi.C.snprintf(s, ffi.sizeof(s), '%p', ffi.cast('void *', ptr))
@@ -853,7 +863,9 @@ end
local function is_asan()
cimport('./src/nvim/version.h')
- local status, res = pcall(function() return lib.version_cflags end)
+ local status, res = pcall(function()
+ return lib.version_cflags
+ end)
if status then
return ffi.string(res):match('-fsanitize=[a-z,]*address')
else
@@ -892,7 +904,7 @@ local module = {
is_asan = is_asan,
}
--- @class test.unit.helpers: test.unit.helpers.module, test.helpers
-module = global_helpers.tbl_extend('error', module, global_helpers)
+module = vim.tbl_extend('error', module, global_helpers)
return function()
return module
diff --git a/test/unit/indent_spec.lua b/test/unit/indent_spec.lua
index ec86822b55..7902918c54 100644
--- a/test/unit/indent_spec.lua
+++ b/test/unit/indent_spec.lua
@@ -1,10 +1,12 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
-local eq = helpers.eq
+local to_cstr = helpers.to_cstr
+local ffi = helpers.ffi
+local eq = helpers.eq
-local indent = helpers.cimport("./src/nvim/indent.h")
-local globals = helpers.cimport("./src/nvim/globals.h")
+local indent = helpers.cimport('./src/nvim/indent.h')
+local globals = helpers.cimport('./src/nvim/globals.h')
describe('get_sts_value', function()
itp([[returns 'softtabstop' when it is non-negative]], function()
@@ -28,3 +30,31 @@ describe('get_sts_value', function()
eq(tabstop, indent.get_sts_value())
end)
end)
+
+describe('indent_size_ts()', function()
+ itp('works for spaces', function()
+ local line = to_cstr((' '):rep(7) .. 'a ')
+ eq(7, indent.indent_size_ts(line, 100, nil))
+ end)
+
+ itp('works for tabs and spaces', function()
+ local line = to_cstr(' \t \t \t\t a ')
+ eq(19, indent.indent_size_ts(line, 4, nil))
+ end)
+
+ itp('works for tabs and spaces with empty vts', function()
+ local vts = ffi.new('int[1]') -- zero initialized => first element (size) == 0
+ local line = to_cstr(' \t \t \t\t a ')
+ eq(23, indent.indent_size_ts(line, 4, vts))
+ end)
+
+ itp('works for tabs and spaces with vts', function()
+ local vts = ffi.new('int[3]')
+ vts[0] = 2 -- zero indexed
+ vts[1] = 7
+ vts[2] = 2
+
+ local line = to_cstr(' \t \t \t\t a ')
+ eq(18, indent.indent_size_ts(line, 4, vts))
+ end)
+end)
diff --git a/test/unit/keycodes_spec.lua b/test/unit/keycodes_spec.lua
index 4da3d37aaa..4a81c62ac1 100644
--- a/test/unit/keycodes_spec.lua
+++ b/test/unit/keycodes_spec.lua
@@ -1,15 +1,14 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
-local ffi = helpers.ffi
-local eq = helpers.eq
-local neq = helpers.neq
+local ffi = helpers.ffi
+local eq = helpers.eq
+local neq = helpers.neq
local keycodes = helpers.cimport('./src/nvim/keycodes.h')
local NULL = helpers.NULL
describe('keycodes.c', function()
-
describe('find_special_key()', function()
local srcp = ffi.new('const unsigned char *[1]')
local modp = ffi.new('int[1]')
@@ -28,31 +27,26 @@ describe('keycodes.c', function()
itp('case-insensitive', function()
-- Compare other capitalizations to this.
srcp[0] = '<C-A>'
- local all_caps_key =
- keycodes.find_special_key(srcp, 5, modp, 0, NULL)
+ local all_caps_key = keycodes.find_special_key(srcp, 5, modp, 0, NULL)
local all_caps_mod = modp[0]
srcp[0] = '<C-a>'
- eq(all_caps_key,
- keycodes.find_special_key(srcp, 5, modp, 0, NULL))
+ eq(all_caps_key, keycodes.find_special_key(srcp, 5, modp, 0, NULL))
eq(all_caps_mod, modp[0])
srcp[0] = '<c-A>'
- eq(all_caps_key,
- keycodes.find_special_key(srcp, 5, modp, 0, NULL))
+ eq(all_caps_key, keycodes.find_special_key(srcp, 5, modp, 0, NULL))
eq(all_caps_mod, modp[0])
srcp[0] = '<c-a>'
- eq(all_caps_key,
- keycodes.find_special_key(srcp, 5, modp, 0, NULL))
+ eq(all_caps_key, keycodes.find_special_key(srcp, 5, modp, 0, NULL))
eq(all_caps_mod, modp[0])
end)
itp('double-quote in keycode #7411', function()
-- Unescaped with in_string=false
srcp[0] = '<C-">'
- eq(string.byte('"'),
- keycodes.find_special_key(srcp, 5, modp, 0, NULL))
+ eq(string.byte('"'), keycodes.find_special_key(srcp, 5, modp, 0, NULL))
-- Unescaped with in_string=true
eq(0, keycodes.find_special_key(srcp, 5, modp, keycodes.FSK_IN_STRING, NULL))
@@ -64,9 +58,7 @@ describe('keycodes.c', function()
eq(0, keycodes.find_special_key(srcp, 6, modp, 0, NULL))
-- Escaped with in_string=true
- eq(string.byte('"'),
- keycodes.find_special_key(srcp, 6, modp, keycodes.FSK_IN_STRING, NULL))
+ eq(string.byte('"'), keycodes.find_special_key(srcp, 6, modp, keycodes.FSK_IN_STRING, NULL))
end)
end)
-
end)
diff --git a/test/unit/marktree_spec.lua b/test/unit/marktree_spec.lua
index 3f9dd4df12..b0a861727d 100644
--- a/test/unit/marktree_spec.lua
+++ b/test/unit/marktree_spec.lua
@@ -1,15 +1,17 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
-local ffi = helpers.ffi
-local eq = helpers.eq
-local ok = helpers.ok
+local ffi = helpers.ffi
+local eq = helpers.eq
+local ok = helpers.ok
-local lib = helpers.cimport("./src/nvim/marktree.h")
+local lib = helpers.cimport('./src/nvim/marktree.h')
local function tablelength(t)
local count = 0
- for _ in pairs(t) do count = count + 1 end
+ for _ in pairs(t) do
+ count = count + 1
+ end
return count
end
@@ -32,15 +34,14 @@ 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.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
+ eq(mark.pos.row, spos[1], mark.id)
+ eq(mark.pos.col, spos[2], mark.id)
if lib.mt_right_test(mark) ~= spos[3] then
- error("invalid gravity for "..id..":("..mark.pos.row..", "..mark.pos.col..")")
+ error('invalid gravity for ' .. id .. ':(' .. mark.pos.row .. ', ' .. mark.pos.col .. ')')
end
if count > 0 then
if not pos_leq(last, spos) then
- error("DISORDER")
+ error('DISORDER')
end
end
count = count + 1
@@ -52,17 +53,21 @@ local function shadoworder(tree, shadow, iter, giveorder)
until not lib.marktree_itr_next(tree, iter)
local shadowlen = tablelength(shadow)
if shadowlen ~= count then
- error("missed some keys? (shadow "..shadowlen..", tree "..count..")")
+ error('missed some keys? (shadow ' .. shadowlen .. ', tree ' .. count .. ')')
end
return id2pos, pos2id
end
local function shadowsplice(shadow, start, old_extent, new_extent)
- local old_end = {start[1] + old_extent[1],
- (old_extent[1] == 0 and start[2] or 0) + old_extent[2]}
- local new_end = {start[1] + new_extent[1],
- (new_extent[1] == 0 and start[2] or 0) + new_extent[2]}
- local delta = {new_end[1] - old_end[1], new_end[2] - old_end[2]}
+ local old_end = {
+ start[1] + old_extent[1],
+ (old_extent[1] == 0 and start[2] or 0) + old_extent[2],
+ }
+ local new_end = {
+ start[1] + new_extent[1],
+ (new_extent[1] == 0 and start[2] or 0) + new_extent[2],
+ }
+ local delta = { new_end[1] - old_end[1], new_end[2] - old_end[2] }
for _, pos in pairs(shadow) do
if pos_leq(start, pos) then
if pos_leq(pos, old_end) then
@@ -82,23 +87,31 @@ local function shadowsplice(shadow, start, old_extent, new_extent)
end
end
-local function dosplice(tree, shadow, start, old_extent, new_extent)
- lib.marktree_splice(tree, start[1], start[2], old_extent[1], old_extent[2], new_extent[1], new_extent[2])
- shadowsplice(shadow, start, old_extent, new_extent)
+local function dosplice(tree, shadow, start, old, new)
+ lib.marktree_splice(tree, start[1], start[2], old[1], old[2], new[1], new[2])
+ shadowsplice(shadow, start, old, new)
end
local ns = 10
local last_id = nil
-local function put(tree, row, col, gravitate, end_row, end_col, end_gravitate)
+local function put(tree, row, col, gravity, end_row, end_col, end_gravity)
last_id = last_id + 1
local my_id = last_id
end_row = end_row or -1
end_col = end_col or -1
- end_gravitate = end_gravitate or false
+ end_gravity = end_gravity or false
+
+ lib.marktree_put_test(tree, ns, my_id, row, col, gravity, end_row, end_col, end_gravity, false)
+ return my_id
+end
- lib.marktree_put_test(tree, ns, my_id, row, col, gravitate, end_row, end_col, end_gravitate);
+local function put_meta(tree, row, col, gravitate, meta)
+ last_id = last_id + 1
+ local my_id = last_id
+
+ lib.marktree_put_test(tree, ns, my_id, row, col, gravitate, -1, -1, false, meta)
return my_id
end
@@ -108,18 +121,18 @@ describe('marktree', function()
end)
itp('works', function()
- local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit
+ local tree = ffi.new('MarkTree[1]') -- zero initialized by luajit
local shadow = {}
- local iter = ffi.new("MarkTreeIter[1]")
- local iter2 = ffi.new("MarkTreeIter[1]")
+ local iter = ffi.new('MarkTreeIter[1]')
+ local iter2 = ffi.new('MarkTreeIter[1]')
- for i = 1,100 do
- for j = 1,100 do
- local gravitate = (i%2) > 0
+ for i = 1, 100 do
+ for j = 1, 100 do
+ local gravitate = (i % 2) > 0
local id = put(tree, j, i, gravitate)
ok(id > 0)
eq(nil, shadow[id])
- shadow[id] = {j,i,gravitate}
+ shadow[id] = { j, i, gravitate }
end
-- checking every insert is too slow, but this is ok
lib.marktree_check(tree)
@@ -133,7 +146,7 @@ describe('marktree', function()
eq({}, pos2id) -- not set if not requested
eq({}, id2pos)
- for i,ipos in pairs(shadow) do
+ for i, ipos in pairs(shadow) do
local p = lib.marktree_lookup_ns(tree, ns, i, false, iter)
eq(ipos[1], p.pos.row)
eq(ipos[2], p.pos.col)
@@ -145,7 +158,7 @@ describe('marktree', function()
-- local k2 = lib.marktree_itr_current(iter)
end
- for i,ipos in pairs(shadow) do
+ for i, ipos in pairs(shadow) do
lib.marktree_itr_get(tree, ipos[1], ipos[2], iter)
local k = lib.marktree_itr_current(iter)
eq(i, tonumber(k.id))
@@ -160,9 +173,9 @@ describe('marktree', function()
shadow[tonumber(del.id)] = nil
shadoworder(tree, shadow, iter)
- for _, ci in ipairs({0,-1,1,-2,2,-10,10}) do
- for i = 1,100 do
- lib.marktree_itr_get(tree, i, 50+ci, iter)
+ for _, ci in ipairs({ 0, -1, 1, -2, 2, -10, 10 }) do
+ for i = 1, 100 do
+ 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.pos.row)
@@ -177,14 +190,14 @@ describe('marktree', function()
-- NB: this is quite rudimentary. We rely on
-- functional tests exercising splicing quite a bit
lib.marktree_check(tree)
- dosplice(tree, shadow, {2,2}, {0,5}, {1, 2})
+ dosplice(tree, shadow, { 2, 2 }, { 0, 5 }, { 1, 2 })
lib.marktree_check(tree)
shadoworder(tree, shadow, iter)
- dosplice(tree, shadow, {30,2}, {30,5}, {1, 2})
+ dosplice(tree, shadow, { 30, 2 }, { 30, 5 }, { 1, 2 })
lib.marktree_check(tree)
shadoworder(tree, shadow, iter)
- dosplice(tree, shadow, {5,3}, {0,2}, {0, 5})
+ dosplice(tree, shadow, { 5, 3 }, { 0, 2 }, { 0, 5 })
shadoworder(tree, shadow, iter)
lib.marktree_check(tree)
@@ -209,7 +222,7 @@ describe('marktree', function()
-- Check iterator validity for 2 specific edge cases:
-- https://github.com/neovim/neovim/pull/14719
lib.marktree_clear(tree)
- for i = 1,20 do
+ for i = 1, 20 do
put(tree, i, i, false)
end
@@ -224,45 +237,59 @@ describe('marktree', function()
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 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]")
+ 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]")
+ 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
+ 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)
+ 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)
@@ -279,13 +306,13 @@ describe('marktree', function()
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);
+ 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")
+ local afil = io.open('Xafile.dot', 'wb')
afil:write(dot1)
afil:close()
- local efil = io.open("Xefile.dot", "wb")
+ local efil = io.open('Xefile.dot', 'wb')
efil:write(dot2)
efil:close()
ok(false)
@@ -295,28 +322,28 @@ describe('marktree', function()
end
itp('works with intersections', function()
- local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit
+ 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))
+ 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
+ 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))
+ 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
+ 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
@@ -324,12 +351,12 @@ describe('marktree', function()
end)
itp('works with intersections with a big tree', function()
- local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit
+ 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))
+ 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
@@ -339,13 +366,13 @@ describe('marktree', function()
eq(2000, tree[0].n_keys)
ok(tree[0].root.level >= 2)
- local iter = ffi.new("MarkTreeIter[1]")
+ local iter = ffi.new('MarkTreeIter[1]')
local k = 0
- for i = 1,20 do
- for j = 1,50 do
+ for i = 1, 20 do
+ for j = 1, 50 do
k = k + 1
- local ival = (j-1)*20+i
+ 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)
@@ -367,10 +394,10 @@ describe('marktree', function()
end)
itp('works with intersections and marktree_splice', function()
- local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit
+ local tree = ffi.new('MarkTree[1]') -- zero initialized by luajit
- for i = 1,1000 do
- put(tree, 1, i, false, 2, 1000-i, false)
+ for i = 1, 1000 do
+ put(tree, 1, i, false, 2, 1000 - i, false)
if i % 10 == 1 then
check_intersections(tree)
end
@@ -380,15 +407,15 @@ describe('marktree', function()
eq(2000, tree[0].n_keys)
ok(tree[0].root.level >= 2)
- for _ = 1,10 do
+ 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 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 because
@@ -405,31 +432,30 @@ describe('marktree', function()
end)
itp('works with intersections and marktree_move', function()
- local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit
+ 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))
+ 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
+ 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)
+ 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
+ local tree = ffi.new('MarkTree[1]') -- zero initialized by luajit
local ids = {}
@@ -441,21 +467,21 @@ describe('marktree', function()
at_row[i] = {}
end
- local size = 1000*size_factor
+ 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
+ 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)
+ local id = put(tree, row1, k, false, row2, size - k, false)
table.insert(ids, id)
- for i = row1+1, row2 do
+ 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
+ if k % 100 * size_factor == 1 or (k < 2000 and k % 100 == 1) then
check_intersections(tree)
end
k = k + 1
@@ -463,13 +489,13 @@ describe('marktree', function()
end
end
- eq(2*size, tree[0].n_keys)
+ 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
+ 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))
@@ -482,14 +508,14 @@ describe('marktree', function()
end
k = 0
- for i = 1,100 do
- for j = 1,(10*size_factor) do
+ for i = 1, 100 do
+ for j = 1, (10 * size_factor) do
k = k + 1
- local ival = (j-1)*100+i
+ 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
+ if k % 100 * size_factor == 0 or (k > 3000 and k % 200 == 0) then
check_intersections(tree)
end
end
@@ -499,7 +525,7 @@ describe('marktree', function()
end)
itp('works with intersections with a even bigger tree and splice', function()
- local tree = ffi.new("MarkTree[1]") -- zero initialized by luajit
+ 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
@@ -509,20 +535,20 @@ describe('marktree', function()
at_row[i] = {}
end
- local size = 1000*size_factor
+ 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
+ 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
+ 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
+ if k % 100 * size_factor == 1 or (k < 2000 and k % 100 == 1) then
check_intersections(tree)
end
k = k + 1
@@ -530,15 +556,93 @@ describe('marktree', function()
end
end
- eq(2*size, tree[0].n_keys)
+ eq(2 * size, tree[0].n_keys)
ok(tree[0].root.level >= 3)
check_intersections(tree)
- for _ = 1,10 do
+ 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)
+
+ itp('works with meta counts', function()
+ local tree = ffi.new('MarkTree[1]') -- zero initialized by luajit
+
+ -- add
+ local shadow = {}
+ for i = 1, 100 do
+ for j = 1, 100 do
+ local gravitate = (i % 2) > 0
+ local inline = (j == 3 or j == 50 or j == 51 or j == 55) and i % 11 == 1
+ inline = inline or ((j >= 80 and j < 85) and i % 3 == 1)
+ local id = put_meta(tree, j, i, gravitate, inline)
+ if inline then
+ shadow[id] = { j, i, gravitate }
+ end
+ end
+ -- checking every insert is too slow, but this is ok
+ lib.marktree_check(tree)
+ end
+
+ lib.marktree_check(tree)
+ local iter = ffi.new('MarkTreeIter[1]')
+ local filter = ffi.new('uint32_t[4]')
+ filter[0] = -1
+ ok(lib.marktree_itr_get_filter(tree, 0, 0, 101, 0, filter, iter))
+ local seen = {}
+ repeat
+ local mark = lib.marktree_itr_current(iter)
+ eq(nil, seen[mark.id])
+ seen[mark.id] = true
+ eq(mark.pos.row, shadow[mark.id][1])
+ eq(mark.pos.col, shadow[mark.id][2])
+ until not lib.marktree_itr_next_filter(tree, iter, 101, 0, filter)
+ eq(tablelength(seen), tablelength(shadow))
+
+ -- test skipping subtrees to find the filtered mark at line 50
+ for i = 4, 50 do
+ ok(lib.marktree_itr_get_filter(tree, i, 0, 60, 0, filter, iter))
+ local mark = lib.marktree_itr_current(iter)
+ eq({ 50, 50, 1 }, { mark.id, mark.pos.row, mark.pos.col })
+ end
+
+ -- delete
+ for id = 1, 10000, 2 do
+ lib.marktree_lookup_ns(tree, ns, id, false, iter)
+ if shadow[id] then
+ local mark = lib.marktree_itr_current(iter)
+ eq(mark.pos.row, shadow[id][1])
+ eq(mark.pos.col, shadow[id][2])
+ shadow[id] = nil
+ end
+ lib.marktree_del_itr(tree, iter, false)
+ if id % 100 == 1 then
+ lib.marktree_check(tree)
+ end
+ end
+
+ -- Splice!
+ dosplice(tree, shadow, { 82, 0 }, { 0, 50 }, { 0, 0 })
+ lib.marktree_check(tree)
+
+ dosplice(tree, shadow, { 81, 50 }, { 2, 50 }, { 1, 0 })
+ lib.marktree_check(tree)
+
+ dosplice(tree, shadow, { 2, 50 }, { 1, 50 }, { 0, 10 })
+ lib.marktree_check(tree)
+
+ ok(lib.marktree_itr_get_filter(tree, 0, 0, 101, 0, filter, iter))
+ seen = {}
+ repeat
+ local mark = lib.marktree_itr_current(iter)
+ eq(nil, seen[mark.id])
+ seen[mark.id] = true
+ eq(mark.pos.row, shadow[mark.id][1])
+ eq(mark.pos.col, shadow[mark.id][2])
+ until not lib.marktree_itr_next_filter(tree, iter, 101, 0, filter)
+ eq(tablelength(seen), tablelength(shadow))
+ end)
end)
diff --git a/test/unit/mbyte_spec.lua b/test/unit/mbyte_spec.lua
index cd94624570..00a8c06ceb 100644
--- a/test/unit/mbyte_spec.lua
+++ b/test/unit/mbyte_spec.lua
@@ -1,8 +1,8 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
-local ffi = helpers.ffi
-local eq = helpers.eq
+local ffi = helpers.ffi
+local eq = helpers.eq
local lib = helpers.cimport('./src/nvim/mbyte.h', './src/nvim/charset.h', './src/nvim/grid.h')
@@ -16,13 +16,12 @@ describe('mbyte', function()
return table.concat(s)
end
- before_each(function()
- end)
+ before_each(function() end)
itp('utf_ptr2char', function()
-- For strings with length 1 the first byte is returned.
for c = 0, 255 do
- eq(c, lib.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
@@ -48,126 +47,230 @@ describe('mbyte', function()
describe('utfc_ptr2schar_len', function()
local function test_seq(seq)
- local firstc = ffi.new("int[1]")
- local buf = ffi.new("char[32]")
+ 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]}
+ return { ffi.string(buf), firstc[0] }
end
local function byte(val)
- return {string.char(val), val}
+ return { string.char(val), val }
end
itp('1-byte sequences', function()
- eq({'', 0}, test_seq{0})
+ eq({ '', 0 }, test_seq { 0 })
for c = 1, 127 do
- eq(byte(c), test_seq{c})
+ eq(byte(c), test_seq { c })
end
for c = 128, 255 do
- eq({'', c}, test_seq{c})
+ eq({ '', c }, test_seq { c })
end
end)
itp('2-byte sequences', function()
-- No combining characters
- eq(byte(0x7f), test_seq{0x7f, 0x7f})
+ eq(byte(0x7f), test_seq { 0x7f, 0x7f })
-- No combining characters
- eq(byte(0x7f), test_seq{0x7f, 0x80})
+ eq(byte(0x7f), test_seq { 0x7f, 0x80 })
-- No UTF-8 sequence
- eq({'', 0xc2}, test_seq{0xc2, 0x7f})
+ eq({ '', 0xc2 }, test_seq { 0xc2, 0x7f })
-- One UTF-8 character
- eq({'\xc2\x80', 0x80}, test_seq{0xc2, 0x80})
+ eq({ '\xc2\x80', 0x80 }, test_seq { 0xc2, 0x80 })
-- No UTF-8 sequence
- eq({'', 0xc2}, test_seq{0xc2, 0xc0})
+ eq({ '', 0xc2 }, test_seq { 0xc2, 0xc0 })
end)
itp('3-byte sequences', function()
-- No second UTF-8 character
- eq(byte(0x7f), test_seq{0x7f, 0x80, 0x80})
+ eq(byte(0x7f), test_seq { 0x7f, 0x80, 0x80 })
-- No combining character
- eq(byte(0x7f), test_seq{0x7f, 0xc2, 0x80})
+ eq(byte(0x7f), test_seq { 0x7f, 0xc2, 0x80 })
-- Combining character is U+0300
- eq({"\x7f\xcc\x80", 0x7f}, test_seq{0x7f, 0xcc, 0x80})
+ eq({ '\x7f\xcc\x80', 0x7f }, test_seq { 0x7f, 0xcc, 0x80 })
-- No UTF-8 sequence
- eq({'', 0xc2}, test_seq{0xc2, 0x7f, 0xcc})
+ eq({ '', 0xc2 }, test_seq { 0xc2, 0x7f, 0xcc })
-- Incomplete combining character
- eq({"\xc2\x80", 0x80}, test_seq{0xc2, 0x80, 0xcc})
+ eq({ '\xc2\x80', 0x80 }, test_seq { 0xc2, 0x80, 0xcc })
-- One UTF-8 character (composing only)
- eq({" \xe2\x83\x90", 0x20d0}, test_seq{0xe2, 0x83, 0x90})
+ eq({ ' \xe2\x83\x90', 0x20d0 }, test_seq { 0xe2, 0x83, 0x90 })
end)
itp('4-byte sequences', function()
-
-- No following combining character
- eq(byte(0x7f), test_seq{0x7f, 0x7f, 0xcc, 0x80})
+ eq(byte(0x7f), test_seq { 0x7f, 0x7f, 0xcc, 0x80 })
-- No second UTF-8 character
- eq(byte(0x7f), test_seq{0x7f, 0xc2, 0xcc, 0x80})
+ eq(byte(0x7f), test_seq { 0x7f, 0xc2, 0xcc, 0x80 })
-- Combining character U+0300
- eq({"\x7f\xcc\x80", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc})
+ eq({ '\x7f\xcc\x80', 0x7f }, test_seq { 0x7f, 0xcc, 0x80, 0xcc })
-- No UTF-8 sequence
- eq({'', 0xc2}, test_seq{0xc2, 0x7f, 0xcc, 0x80})
+ eq({ '', 0xc2 }, test_seq { 0xc2, 0x7f, 0xcc, 0x80 })
-- No following UTF-8 character
- eq({"\xc2\x80", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0xcc})
+ eq({ '\xc2\x80', 0x80 }, test_seq { 0xc2, 0x80, 0xcc, 0xcc })
-- Combining character U+0301
- eq({"\xc2\x80\xcc\x81", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0x81})
+ eq({ '\xc2\x80\xcc\x81', 0x80 }, test_seq { 0xc2, 0x80, 0xcc, 0x81 })
-- One UTF-8 character
- eq({"\xf4\x80\x80\x80", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80})
+ eq({ '\xf4\x80\x80\x80', 0x100000 }, test_seq { 0xf4, 0x80, 0x80, 0x80 })
end)
itp('5+-byte sequences', function()
-- No following combining character
- eq(byte(0x7f), test_seq{0x7f, 0x7f, 0xcc, 0x80, 0x80})
+ eq(byte(0x7f), test_seq { 0x7f, 0x7f, 0xcc, 0x80, 0x80 })
-- No second UTF-8 character
- eq(byte(0x7f), test_seq{0x7f, 0xc2, 0xcc, 0x80, 0x80})
+ eq(byte(0x7f), test_seq { 0x7f, 0xc2, 0xcc, 0x80, 0x80 })
-- Combining character U+0300
- eq({"\x7f\xcc\x80", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x00})
+ eq({ '\x7f\xcc\x80', 0x7f }, test_seq { 0x7f, 0xcc, 0x80, 0xcc, 0x00 })
-- Combining characters U+0300 and U+0301
- eq({"\x7f\xcc\x80\xcc\x81", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81})
+ eq({ '\x7f\xcc\x80\xcc\x81', 0x7f }, test_seq { 0x7f, 0xcc, 0x80, 0xcc, 0x81 })
-- 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})
+ 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
- eq({"\x7f\xcc\x80\xcc\x81\xcc\x82\xcc\x83", 0x7f}, test_seq{0x7f, 0xcc, 0x80, 0xcc, 0x81, 0xcc, 0x82, 0xcc, 0x83})
+ 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
- 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})
+ 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})
+ 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 }
+ )
-- 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})
+ 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})
+ 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
- eq({'', 0xc2}, test_seq{0xc2, 0x7f, 0xcc, 0x80, 0x80})
+ eq({ '', 0xc2 }, test_seq { 0xc2, 0x7f, 0xcc, 0x80, 0x80 })
-- No following UTF-8 character
- eq({"\xc2\x80", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0xcc, 0x80})
+ eq({ '\xc2\x80', 0x80 }, test_seq { 0xc2, 0x80, 0xcc, 0xcc, 0x80 })
-- Combining character U+0301
- eq({"\xc2\x80\xcc\x81", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0x81, 0x7f})
+ eq({ '\xc2\x80\xcc\x81', 0x80 }, test_seq { 0xc2, 0x80, 0xcc, 0x81, 0x7f })
-- Combining character U+0301
- eq({"\xc2\x80\xcc\x81", 0x80}, test_seq{0xc2, 0x80, 0xcc, 0x81, 0xcc})
+ eq({ '\xc2\x80\xcc\x81', 0x80 }, test_seq { 0xc2, 0x80, 0xcc, 0x81, 0xcc })
-- One UTF-8 character
- eq({"\xf4\x80\x80\x80", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80, 0x7f})
+ eq({ '\xf4\x80\x80\x80', 0x100000 }, test_seq { 0xf4, 0x80, 0x80, 0x80, 0x7f })
-- One UTF-8 character
- eq({"\xf4\x80\x80\x80", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80, 0x80})
+ eq({ '\xf4\x80\x80\x80', 0x100000 }, test_seq { 0xf4, 0x80, 0x80, 0x80, 0x80 })
-- One UTF-8 character
- eq({"\xf4\x80\x80\x80", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80, 0xcc})
+ eq({ '\xf4\x80\x80\x80', 0x100000 }, test_seq { 0xf4, 0x80, 0x80, 0x80, 0xcc })
-- Combining characters U+1AB0 and U+0301
- eq({"\xf4\x80\x80\x80\xe1\xaa\xb0\xcc\x81", 0x100000}, test_seq{0xf4, 0x80, 0x80, 0x80, 0xe1, 0xaa, 0xb0, 0xcc, 0x81})
+ eq(
+ { '\xf4\x80\x80\x80\xe1\xaa\xb0\xcc\x81', 0x100000 },
+ test_seq { 0xf4, 0x80, 0x80, 0x80, 0xe1, 0xaa, 0xb0, 0xcc, 0x81 }
+ )
end)
-
end)
+ describe('utf_cp_bounds_len', function()
+ local to_cstr = helpers.to_cstr
+
+ local tests = {
+ {
+ name = 'for valid string',
+ str = 'iÀiiⱠiⱠⱠ𐀀i',
+ offsets = {
+ b = { 0, 0, 1, 0, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 0, 1, 2, 3, 0 },
+ e = { 1, 2, 1, 1, 1, 3, 2, 1, 1, 3, 2, 1, 3, 2, 1, 4, 3, 2, 1, 1 },
+ },
+ },
+ {
+ name = 'for string with incomplete sequence',
+ str = 'i\xC3iÀⱠiÀ\xE2\xB1Ⱡ\xF0\x90\x80',
+ offsets = {
+ b = { 0, 0, 0, 0, 1, 0, 1, 2, 0, 0, 1, 0, 0, 0, 1, 2, 0, 0, 0 },
+ e = { 1, 1, 1, 2, 1, 3, 2, 1, 1, 2, 1, 1, 1, 3, 2, 1, 1, 1, 1 },
+ },
+ },
+ {
+ name = 'for string with trailing bytes after multibyte',
+ str = 'iÀ\xA0Ⱡ\xA0Ⱡ𐀀\xA0i',
+ offsets = {
+ b = { 0, 0, 1, 0, 0, 1, 2, 0, 0, 1, 2, 0, 1, 2, 3, 0, 0 },
+ e = { 1, 2, 1, 1, 3, 2, 1, 1, 3, 2, 1, 4, 3, 2, 1, 1, 1 },
+ },
+ },
+ }
+
+ for _, test in ipairs(tests) do
+ itp(test.name, function()
+ local cstr = to_cstr(test.str)
+ local b_offsets, e_offsets = {}, {}
+ for i = 1, #test.str do
+ local result = lib.utf_cp_bounds_len(cstr, cstr + i - 1, #test.str - (i - 1))
+ table.insert(b_offsets, result.begin_off)
+ table.insert(e_offsets, result.end_off)
+ end
+ eq(test.offsets, { b = b_offsets, e = e_offsets })
+ end)
+ end
+
+ itp('does not read before start', function()
+ local str = '𐀀'
+ local expected_offsets = { b = { 0, 0, 0 }, e = { 1, 1, 1 } }
+ local cstr = to_cstr(str) + 1
+ local b_offsets, e_offsets = {}, {}
+ for i = 1, 3 do
+ local result = lib.utf_cp_bounds_len(cstr, cstr + i - 1, 3 - (i - 1))
+ table.insert(b_offsets, result.begin_off)
+ table.insert(e_offsets, result.end_off)
+ end
+ eq(expected_offsets, { b = b_offsets, e = e_offsets })
+ end)
+
+ itp('does not read past the end', function()
+ local str = '𐀀'
+ local expected_offsets = { b = { 0, 0, 0 }, e = { 1, 1, 1 } }
+ local cstr = to_cstr(str)
+ local b_offsets, e_offsets = {}, {}
+ for i = 1, 3 do
+ local result = lib.utf_cp_bounds_len(cstr, cstr + i - 1, 3 - (i - 1))
+ table.insert(b_offsets, result.begin_off)
+ table.insert(e_offsets, result.end_off)
+ end
+ eq(expected_offsets, { b = b_offsets, e = e_offsets })
+ end)
+ end)
end)
diff --git a/test/unit/memory_spec.lua b/test/unit/memory_spec.lua
index bd72c8bf47..8be55fdbf3 100644
--- a/test/unit/memory_spec.lua
+++ b/test/unit/memory_spec.lua
@@ -1,4 +1,4 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local cimport = helpers.cimport
@@ -11,7 +11,7 @@ local cimp = cimport('stdlib.h', './src/nvim/memory.h')
describe('xstrlcat()', function()
local function test_xstrlcat(dst, src, dsize)
- assert.is_true(dsize >= 1 + string.len(dst)) -- sanity check for tests
+ assert.is_true(dsize >= 1 + string.len(dst)) -- sanity check for tests
local dst_cstr = cstr(dsize, dst)
local src_cstr = to_cstr(src)
eq(string.len(dst .. src), cimp.xstrlcat(dst_cstr, src_cstr, dsize))
@@ -19,34 +19,32 @@ describe('xstrlcat()', function()
end
local function test_xstrlcat_overlap(dst, src_idx, dsize)
- assert.is_true(dsize >= 1 + string.len(dst)) -- sanity check for tests
+ assert.is_true(dsize >= 1 + string.len(dst)) -- sanity check for tests
local dst_cstr = cstr(dsize, dst)
- local src_cstr = dst_cstr + src_idx -- pointer into `dst` (overlaps)
- eq(string.len(dst) + string.len(dst) - src_idx,
- cimp.xstrlcat(dst_cstr, src_cstr, dsize))
+ local src_cstr = dst_cstr + src_idx -- pointer into `dst` (overlaps)
+ eq(string.len(dst) + string.len(dst) - src_idx, cimp.xstrlcat(dst_cstr, src_cstr, dsize))
return ffi.string(dst_cstr)
end
itp('concatenates strings', function()
eq('ab', test_xstrlcat('a', 'b', 3))
eq('ab', test_xstrlcat('a', 'b', 4096))
- eq('ABCיהZdefgiיהZ', test_xstrlcat('ABCיהZ', 'defgiיהZ', 4096))
- eq('b', test_xstrlcat('', 'b', 4096))
- eq('a', test_xstrlcat('a', '', 4096))
+ eq('ABCיהZdefgiיהZ', test_xstrlcat('ABCיהZ', 'defgiיהZ', 4096))
+ eq('b', test_xstrlcat('', 'b', 4096))
+ eq('a', test_xstrlcat('a', '', 4096))
end)
itp('concatenates overlapping strings', function()
- eq('abcabc', test_xstrlcat_overlap('abc', 0, 7))
- eq('abca', test_xstrlcat_overlap('abc', 0, 5))
- eq('abcb', test_xstrlcat_overlap('abc', 1, 5))
- eq('abcc', test_xstrlcat_overlap('abc', 2, 10))
- eq('abcabc', test_xstrlcat_overlap('abc', 0, 2343))
+ eq('abcabc', test_xstrlcat_overlap('abc', 0, 7))
+ eq('abca', test_xstrlcat_overlap('abc', 0, 5))
+ eq('abcb', test_xstrlcat_overlap('abc', 1, 5))
+ eq('abcc', test_xstrlcat_overlap('abc', 2, 10))
+ eq('abcabc', test_xstrlcat_overlap('abc', 0, 2343))
end)
itp('truncates if `dsize` is too small', function()
eq('a', test_xstrlcat('a', 'b', 2))
eq('', test_xstrlcat('', 'b', 1))
- eq('ABCיהZd', test_xstrlcat('ABCיהZ', 'defgiיהZ', 10))
+ eq('ABCיהZd', test_xstrlcat('ABCיהZ', 'defgiיהZ', 10))
end)
-
end)
diff --git a/test/unit/message_spec.lua b/test/unit/message_spec.lua
index 0d5268d199..71aa74d90d 100644
--- a/test/unit/message_spec.lua
+++ b/test/unit/message_spec.lua
@@ -1,12 +1,11 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local ffi = helpers.ffi
local eq = helpers.eq
local to_cstr = helpers.to_cstr
-local cimp = helpers.cimport('./src/nvim/message.h', './src/nvim/memory.h',
- './src/nvim/strings.h')
+local cimp = helpers.cimport('./src/nvim/message.h', './src/nvim/memory.h', './src/nvim/strings.h')
describe('trunc_string', function()
local buflen = 40
@@ -34,8 +33,8 @@ describe('trunc_string', function()
{ ['desc'] = 'by copy', ['func'] = test_copy },
}
- for _,t in ipairs(permutations) do
- describe('populates buf '..t.desc, function()
+ for _, t in ipairs(permutations) do
+ describe('populates buf ' .. t.desc, function()
itp('with a small string', function()
t.func('text', 'text')
end)
diff --git a/test/unit/msgpack_spec.lua b/test/unit/msgpack_spec.lua
index c573714714..bd663a3c75 100644
--- a/test/unit/msgpack_spec.lua
+++ b/test/unit/msgpack_spec.lua
@@ -35,32 +35,36 @@ 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'
+ 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)
+ local unpacker = make_unpacker()
+ lib.unpacker_init(unpacker)
- unpacker_goto(unpacker, payload, payload:len() - 1)
- local finished = unpacker_advance(unpacker)
- eq(finished, false)
+ 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)
+ 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,
+ unpacker_goto(
+ unpacker,
-- [kMessageTypeNotification, "redraw", [
-- ["grid_line",
-- [2, 0, 0, [], false]
diff --git a/test/unit/multiqueue_spec.lua b/test/unit/multiqueue_spec.lua
index bb08a8386f..f6d11ebed0 100644
--- a/test/unit/multiqueue_spec.lua
+++ b/test/unit/multiqueue_spec.lua
@@ -1,4 +1,4 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local child_call_once = helpers.child_call_once
@@ -6,9 +6,9 @@ local cimport = helpers.cimport
local ffi = helpers.ffi
local eq = helpers.eq
-local multiqueue = cimport("./test/unit/fixtures/multiqueue.h")
+local multiqueue = cimport('./test/unit/fixtures/multiqueue.h')
-describe("multiqueue (multi-level event-queue)", function()
+describe('multiqueue (multi-level event-queue)', function()
local parent, child1, child2, child3
local function put(q, str)
diff --git a/test/unit/optionstr_spec.lua b/test/unit/optionstr_spec.lua
index 2e7198a63a..7666db910e 100644
--- a/test/unit/optionstr_spec.lua
+++ b/test/unit/optionstr_spec.lua
@@ -1,28 +1,27 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local to_cstr = helpers.to_cstr
-local eq = helpers.eq
+local eq = helpers.eq
-local optionstr = helpers.cimport("./src/nvim/optionstr.h")
+local optionstr = helpers.cimport('./src/nvim/optionstr.h')
local check_ff_value = function(ff)
return optionstr.check_ff_value(to_cstr(ff))
end
describe('check_ff_value', function()
-
itp('views empty string as valid', function()
- eq(1, check_ff_value(""))
+ eq(1, check_ff_value(''))
end)
itp('views "unix", "dos" and "mac" as valid', function()
- eq(1, check_ff_value("unix"))
- eq(1, check_ff_value("dos"))
- eq(1, check_ff_value("mac"))
+ eq(1, check_ff_value('unix'))
+ eq(1, check_ff_value('dos'))
+ eq(1, check_ff_value('mac'))
end)
itp('views "foo" as invalid', function()
- eq(0, check_ff_value("foo"))
+ eq(0, check_ff_value('foo'))
end)
end)
diff --git a/test/unit/os/env_spec.lua b/test/unit/os/env_spec.lua
index 24b92edee5..2c638fcb37 100644
--- a/test/unit/os/env_spec.lua
+++ b/test/unit/os/env_spec.lua
@@ -62,7 +62,7 @@ describe('env.c', function()
eq('non-empty', os.getenv(name))
end)
- itp("`overwrite` behavior", function()
+ itp('`overwrite` behavior', function()
local name = 'NVIM_UNIT_TEST_SETENV_2N'
local value = 'NVIM_UNIT_TEST_SETENV_2V'
local value_updated = 'NVIM_UNIT_TEST_SETENV_2V_UPDATED'
@@ -79,7 +79,7 @@ describe('env.c', function()
itp('appends :/foo/bar to $PATH', function()
local original_path = os.getenv('PATH')
eq(true, cimp.os_setenv_append_path(to_cstr('/foo/bar/baz.exe')))
- eq(original_path..':/foo/bar', os.getenv('PATH'))
+ eq(original_path .. ':/foo/bar', os.getenv('PATH'))
end)
itp('avoids redundant separator when appending to $PATH #7377', function()
@@ -166,7 +166,7 @@ describe('env.c', function()
local test_value = 'NVIM_UNIT_TEST_GETENVNAME_AT_INDEX_1V'
os_setenv(test_name, test_value, 1)
local i = 0
- local names = { }
+ local names = {}
local found_name = false
local name = cimp.os_getenvname_at_index(i)
while name ~= NULL do
@@ -245,7 +245,7 @@ describe('env.c', function()
local input = '~/foo ~ foo'
local homedir = cstr(255, '')
cimp.expand_env_esc(to_cstr('~'), homedir, 255, false, true, NULL)
- local output_expected = ffi.string(homedir) .. "/foo ~ foo"
+ local output_expected = ffi.string(homedir) .. '/foo ~ foo'
local output = cstr(255, '')
cimp.expand_env_esc(to_cstr(input), output, 255, false, true, NULL)
eq(ffi.string(output), ffi.string(output_expected))
@@ -256,7 +256,7 @@ describe('env.c', function()
local dst = cstr(255, '')
cimp.expand_env_esc(to_cstr('~'), dst, 255, false, true, NULL)
local homedir = ffi.string(dst)
- local output_expected = homedir .. "/foo " .. homedir .. " foo"
+ local output_expected = homedir .. '/foo ' .. homedir .. ' foo'
local output = cstr(255, '')
cimp.expand_env_esc(input, output, 255, false, false, NULL)
eq(output_expected, ffi.string(output))
@@ -267,8 +267,9 @@ describe('env.c', function()
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")
- local dst = cstr(256, "~"..curuser)
+ local src =
+ to_cstr('~' .. curuser .. '/Vcs/django-rest-framework/rest_framework/renderers.py')
+ local dst = cstr(256, '~' .. curuser)
cimp.expand_env_esc(src, dst, 256, false, false, NULL)
local len = string.len(ffi.string(dst))
assert.True(len > 56)
@@ -283,7 +284,7 @@ describe('env.c', function()
cimp.expand_env_esc(input, output, 5, false, true, NULL)
-- Make sure the first few characters are copied properly and that there is a
-- terminating null character
- for i=0,3 do
+ for i = 0, 3 do
eq(input[i], output[i])
end
eq(0, output[4])
@@ -304,7 +305,7 @@ describe('env.c', function()
-- terminating null character
-- expand_env_esc SHOULD NOT expand the variable if there is not enough space to
-- contain the result
- for i=0,3 do
+ for i = 0, 3 do
eq(output[i], input[i])
end
eq(output[4], 0)
diff --git a/test/unit/os/fileio_spec.lua b/test/unit/os/fileio_spec.lua
index fd30ca70da..617141fd3a 100644
--- a/test/unit/os/fileio_spec.lua
+++ b/test/unit/os/fileio_spec.lua
@@ -1,4 +1,4 @@
-local luv = require('luv')
+local uv = vim.uv
local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
@@ -26,7 +26,7 @@ local linkb = dir .. '/broken.lnk'
local filec = dir .. '/created-file.dat'
before_each(function()
- mkdir(dir);
+ mkdir(dir)
local f1 = io.open(file1, 'w')
f1:write(fcontents)
@@ -36,8 +36,8 @@ before_each(function()
f2:write(fcontents)
f2:close()
- luv.fs_symlink('file1.dat', linkf)
- luv.fs_symlink('broken.dat', linkb)
+ uv.fs_symlink('file1.dat', linkf)
+ uv.fs_symlink('broken.dat', linkb)
end)
after_each(function()
@@ -46,7 +46,7 @@ after_each(function()
os.remove(linkf)
os.remove(linkb)
os.remove(filec)
- luv.fs_rmdir(dir)
+ uv.fs_rmdir(dir)
end)
local function file_open(fname, flags, mode)
@@ -55,32 +55,16 @@ local function file_open(fname, flags, mode)
return ret1, ret2
end
-local function file_open_new(fname, flags, mode)
- local ret1 = ffi.new('int[?]', 1, {0})
- local ret2 = ffi.gc(m.file_open_new(ret1, fname, flags, mode), nil)
- return ret1[0], ret2
-end
-
local function file_open_fd(fd, flags)
local ret2 = ffi.new('FileDescriptor')
local ret1 = m.file_open_fd(ret2, fd, flags)
return ret1, ret2
end
-local function file_open_fd_new(fd, flags)
- local ret1 = ffi.new('int[?]', 1, {0})
- local ret2 = ffi.gc(m.file_open_fd_new(ret1, fd, flags), nil)
- return ret1[0], ret2
-end
-
local function file_write(fp, buf)
return m.file_write(fp, buf, #buf)
end
-local function msgpack_file_write(fp, buf)
- return m.msgpack_file_write(fp, buf, #buf)
-end
-
local function file_read(fp, size)
local buf = nil
if size == nil then
@@ -116,37 +100,17 @@ describe('file_open_fd', function()
local fd = m.os_open(file1, m.kO_RDONLY, 0)
local err, fp = file_open_fd(fd, m.kFileReadOnly)
eq(0, err)
- eq({#fcontents, fcontents}, {file_read(fp, #fcontents)})
+ eq({ #fcontents, fcontents }, { file_read(fp, #fcontents) })
eq(0, m.file_close(fp, false))
end)
itp('can use file descriptor returned by os_open for writing', function()
- eq(nil, luv.fs_stat(filec))
+ eq(nil, uv.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, luv.fs_stat(filec).size)
- eq('test', io.open(filec):read('*a'))
- end)
-end)
-
-describe('file_open_fd_new', function()
- itp('can use file descriptor returned by os_open for reading', function()
- local fd = m.os_open(file1, m.kO_RDONLY, 0)
- local err, fp = file_open_fd_new(fd, m.kFileReadOnly)
- eq(0, err)
- eq({#fcontents, fcontents}, {file_read(fp, #fcontents)})
- eq(0, m.file_free(fp, false))
- end)
- itp('can use file descriptor returned by os_open for writing', function()
- 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, luv.fs_stat(filec).size)
+ eq(4, uv.fs_stat(filec).size)
eq('test', io.open(filec):read('*a'))
end)
end)
@@ -155,7 +119,7 @@ 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 = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(33216, attrs.mode)
eq(0, m.file_close(fp, false))
end)
@@ -163,7 +127,7 @@ describe('file_open', function()
itp('can create a rw------- file with kFileCreate', function()
local err, fp = file_open(filec, m.kFileCreate, 384)
eq(0, err)
- local attrs = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(33152, attrs.mode)
eq(0, m.file_close(fp, false))
end)
@@ -171,7 +135,7 @@ describe('file_open', function()
itp('can create a rwx------ file with kFileCreateOnly', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 448)
eq(0, err)
- local attrs = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(33216, attrs.mode)
eq(0, m.file_close(fp, false))
end)
@@ -179,7 +143,7 @@ describe('file_open', function()
itp('can create a rw------- file with kFileCreateOnly', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 384)
eq(0, err)
- local attrs = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(33152, attrs.mode)
eq(0, m.file_close(fp, false))
end)
@@ -193,7 +157,9 @@ describe('file_open', function()
local err, _ = file_open(linkf, m.kFileNoSymlink, 384)
-- err is UV_EMLINK in FreeBSD, but if I use `ok(err == m.UV_ELOOP or err ==
-- m.UV_EMLINK)`, then I loose the ability to see actual `err` value.
- if err ~= m.UV_ELOOP then eq(m.UV_EMLINK, err) end
+ if err ~= m.UV_ELOOP then
+ eq(m.UV_EMLINK, err)
+ end
end)
itp('can open an existing file write-only with kFileCreate', function()
@@ -229,7 +195,7 @@ describe('file_open', function()
eq(0, err)
eq(true, fp.wr)
eq(0, m.file_close(fp, false))
- local attrs = luv.fs_stat(file1)
+ local attrs = uv.fs_stat(file1)
eq(0, attrs.size)
end)
@@ -238,24 +204,23 @@ describe('file_open', function()
eq(0, err)
eq(true, fp.wr)
eq(0, m.file_close(fp, false))
- local attrs = luv.fs_stat(file1)
+ local attrs = uv.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 = luv.fs_stat(filec)
+ local attrs = uv.fs_stat(filec)
eq(nil, attrs)
end)
- itp('can truncate an existing file with kFileTruncate when opening a symlink',
- function()
+ itp('can truncate an existing file with kFileTruncate when opening a symlink', function()
local err, fp = file_open(linkf, m.kFileTruncate, 384)
eq(0, err)
eq(true, fp.wr)
eq(0, m.file_close(fp, false))
- local attrs = luv.fs_stat(file1)
+ local attrs = uv.fs_stat(file1)
eq(0, attrs.size)
end)
@@ -275,42 +240,15 @@ describe('file_open', function()
end)
end)
-describe('file_open_new', function()
- itp('can open a file read-only', function()
- local err, fp = file_open_new(file1, 0, 384)
- eq(0, err)
- eq(false, fp.wr)
- eq(0, m.file_free(fp, false))
- end)
-
- itp('fails to open an existing file with kFileCreateOnly', function()
- local err, fp = file_open_new(file1, m.kFileCreateOnly, 384)
- eq(m.UV_EEXIST, err)
- eq(nil, fp)
- end)
-end)
-
describe('file_close', function()
itp('can flush writes to disk also with true argument', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 384)
eq(0, err)
local wsize = file_write(fp, 'test')
eq(4, wsize)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
eq(0, m.file_close(fp, true))
- eq(wsize, luv.fs_stat(filec).size)
- end)
-end)
-
-describe('file_free', function()
- itp('can flush writes to disk also with true argument', function()
- local err, fp = file_open_new(filec, m.kFileCreateOnly, 384)
- eq(0, err)
- local wsize = file_write(fp, 'test')
- eq(4, wsize)
- eq(0, luv.fs_stat(filec).size)
- eq(0, m.file_free(fp, true))
- eq(wsize, luv.fs_stat(filec).size)
+ eq(wsize, uv.fs_stat(filec).size)
end)
end)
@@ -319,12 +257,12 @@ describe('file_fsync', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 384)
eq(0, file_fsync(fp))
eq(0, err)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
local wsize = file_write(fp, 'test')
eq(4, wsize)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
eq(0, file_fsync(fp))
- eq(wsize, luv.fs_stat(filec).size)
+ eq(wsize, uv.fs_stat(filec).size)
eq(0, m.file_close(fp, false))
end)
end)
@@ -334,12 +272,12 @@ describe('file_flush', function()
local err, fp = file_open(filec, m.kFileCreateOnly, 384)
eq(0, file_flush(fp))
eq(0, err)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
local wsize = file_write(fp, 'test')
eq(4, wsize)
- eq(0, luv.fs_stat(filec).size)
+ eq(0, uv.fs_stat(filec).size)
eq(0, file_flush(fp))
- eq(wsize, luv.fs_stat(filec).size)
+ eq(wsize, uv.fs_stat(filec).size)
eq(0, m.file_close(fp, false))
end)
end)
@@ -356,10 +294,9 @@ describe('file_read', function()
local exp_s = fcontents:sub(shift + 1, shift + size)
if shift + size >= #fcontents then
exp_err = #fcontents - shift
- exp_s = (fcontents:sub(shift + 1, shift + size)
- .. (('\0'):rep(size - exp_err)))
+ exp_s = (fcontents:sub(shift + 1, shift + size) .. (('\0'):rep(size - exp_err)))
end
- eq({exp_err, exp_s}, {file_read(fp, size)})
+ eq({ exp_err, exp_s }, { file_read(fp, size) })
shift = shift + size
end
eq(0, m.file_close(fp, false))
@@ -369,8 +306,8 @@ describe('file_read', function()
local err, fp = file_open(file1, 0, 384)
eq(0, err)
eq(false, fp.wr)
- eq({#fcontents, fcontents}, {file_read(fp, #fcontents)})
- eq({0, ('\0'):rep(#fcontents)}, {file_read(fp, #fcontents)})
+ eq({ #fcontents, fcontents }, { file_read(fp, #fcontents) })
+ eq({ 0, ('\0'):rep(#fcontents) }, { file_read(fp, #fcontents) })
eq(0, m.file_close(fp, false))
end)
@@ -378,9 +315,8 @@ describe('file_read', function()
local err, fp = file_open(file1, 0, 384)
eq(0, err)
eq(false, fp.wr)
- eq({5, fcontents:sub(1, 5)}, {file_read(fp, 5)})
- eq({#fcontents - 5, fcontents:sub(6) .. (('\0'):rep(5))},
- {file_read(fp, #fcontents)})
+ eq({ 5, fcontents:sub(1, 5) }, { file_read(fp, 5) })
+ eq({ #fcontents - 5, fcontents:sub(6) .. (('\0'):rep(5)) }, { file_read(fp, #fcontents) })
eq(0, m.file_close(fp, false))
end)
@@ -395,10 +331,9 @@ describe('file_read', function()
local exp_s = fcontents:sub(shift + 1, shift + size)
if shift + size >= #fcontents then
exp_err = #fcontents - shift
- exp_s = (fcontents:sub(shift + 1, shift + size)
- .. (('\0'):rep(size - exp_err)))
+ exp_s = (fcontents:sub(shift + 1, shift + size) .. (('\0'):rep(size - exp_err)))
end
- eq({exp_err, exp_s}, {file_read(fp, size)})
+ eq({ exp_err, exp_s }, { file_read(fp, size) })
shift = shift + size
end
eq(0, m.file_close(fp, false))
@@ -413,7 +348,7 @@ describe('file_write', function()
local wr = file_write(fp, fcontents)
eq(#fcontents, wr)
eq(0, m.file_close(fp, false))
- eq(wr, luv.fs_stat(filec).size)
+ eq(wr, uv.fs_stat(filec).size)
eq(fcontents, io.open(filec):read('*a'))
end)
@@ -430,7 +365,7 @@ describe('file_write', function()
shift = shift + size
end
eq(0, m.file_close(fp, false))
- eq(#fcontents, luv.fs_stat(filec).size)
+ eq(#fcontents, uv.fs_stat(filec).size)
eq(fcontents, io.open(filec):read('*a'))
end)
@@ -447,19 +382,7 @@ describe('file_write', function()
shift = shift + size
end
eq(0, m.file_close(fp, false))
- eq(#fcontents, luv.fs_stat(filec).size)
- eq(fcontents, io.open(filec):read('*a'))
- end)
-end)
-
-describe('msgpack_file_write', function()
- itp('can write the whole file at once', function()
- local err, fp = file_open(filec, m.kFileCreateOnly, 384)
- eq(0, err)
- eq(true, fp.wr)
- local wr = msgpack_file_write(fp, fcontents)
- eq(0, wr)
- eq(0, m.file_close(fp, false))
+ eq(#fcontents, uv.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 8f45d2b0c7..c15cd12fef 100644
--- a/test/unit/os/fs_spec.lua
+++ b/test/unit/os/fs_spec.lua
@@ -1,4 +1,4 @@
-local luv = require('luv')
+local uv = vim.uv
local bit = require('bit')
local helpers = require('test.unit.helpers')(after_each)
@@ -17,7 +17,7 @@ local OK = helpers.OK
local FAIL = helpers.FAIL
local NULL = helpers.NULL
local mkdir = helpers.mkdir
-local endswith = helpers.endswith
+local endswith = vim.endswith
local NODE_NORMAL = 0
local NODE_WRITABLE = 1
@@ -46,11 +46,11 @@ local function unset_bit(number, to_unset)
end
local function assert_file_exists(filepath)
- neq(nil, luv.fs_stat(filepath))
+ neq(nil, uv.fs_stat(filepath))
end
local function assert_file_does_not_exist(filepath)
- eq(nil, luv.fs_stat(filepath))
+ eq(nil, uv.fs_stat(filepath))
end
local function os_setperm(filename, perm)
@@ -68,14 +68,14 @@ describe('fs.c', function()
end
before_each(function()
- 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()
- luv.fs_symlink('test.file', 'unit-test-directory/test_link.file')
+ uv.fs_symlink('test.file', 'unit-test-directory/test_link.file')
- luv.fs_symlink('non_existing_file.file', 'unit-test-directory/test_broken_link.file')
+ uv.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.
@@ -88,19 +88,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')
- luv.fs_rmdir('unit-test-directory')
+ uv.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(luv.cwd()) + 1
+ local length = string.len(uv.cwd()) + 1
local buf = cstr(length, '')
eq(OK, fs.os_dirname(buf, length))
- eq(luv.cwd(), ffi.string(buf))
+ eq(uv.cwd(), ffi.string(buf))
end)
itp('returns FAIL if the buffer is too small', function()
- local length = string.len(luv.cwd()) + 1
+ local length = string.len(uv.cwd()) + 1
local buf = cstr(length - 1, '')
eq(FAIL, fs.os_dirname(buf, length - 1))
end)
@@ -115,8 +115,8 @@ describe('fs.c', function()
eq(OK, fs.os_dirname(expected_cwd, length))
-- os_chdir returns 0 for success, not OK (1).
- neq(0, fs.os_chdir('~')) -- fail
- neq(0, fs.os_chdir('~/')) -- fail
+ neq(0, fs.os_chdir('~')) -- fail
+ neq(0, fs.os_chdir('~/')) -- fail
eq(OK, fs.os_dirname(cwd, length))
-- CWD did not change.
@@ -197,24 +197,24 @@ describe('fs.c', function()
itp('returns the absolute path when given an executable inside $PATH', function()
local fullpath = exe('ls')
- eq(1, fs.path_is_absolute(to_cstr(fullpath)))
+ eq(true, fs.path_is_absolute(to_cstr(fullpath)))
end)
itp('returns the absolute path when given an executable relative to the current dir', function()
- local old_dir = luv.cwd()
+ local old_dir = uv.cwd()
- luv.chdir(directory)
+ uv.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 = luv.cwd() .. '/' .. executable_name
+ local canonical = uv.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.
- luv.chdir(old_dir)
+ uv.chdir(old_dir)
eq(expected, res)
end)
end)
@@ -276,39 +276,42 @@ 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 = luv.fs_stat(filename).uid
- local gid = luv.fs_stat(filename).gid
+ local uid = uv.fs_stat(filename).uid
+ local gid = uv.fs_stat(filename).gid
eq(0, os_fchown(filename, -1, -1))
- eq(uid, luv.fs_stat(filename).uid)
- return eq(gid, luv.fs_stat(filename).gid)
+ eq(uid, uv.fs_stat(filename).uid)
+ return eq(gid, uv.fs_stat(filename).gid)
end)
-- Some systems may not have `id` utility.
- if (os.execute('id -G > /dev/null 2>&1') ~= 0) then
+ if os.execute('id -G > /dev/null 2>&1') ~= 0 then
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 = luv.fs_stat(filename).gid
-
- -- Gets ID of any group of which current user is a member except the
- -- group that owns the file.
- local id_fd = io.popen('id -G')
- local new_gid = id_fd:read('*n')
- if (new_gid == file_gid) then
- new_gid = id_fd:read('*n')
+ 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 = uv.fs_stat(filename).gid
+
+ -- Gets ID of any group of which current user is a member except the
+ -- group that owns the file.
+ local id_fd = io.popen('id -G')
+ local new_gid = id_fd:read('*n')
+ if new_gid == file_gid then
+ new_gid = id_fd:read('*n')
+ end
+ id_fd:close()
+
+ -- User can be a member of only one group.
+ -- In that case we can not perform this test.
+ if new_gid then
+ eq(0, (os_fchown(filename, -1, new_gid)))
+ eq(new_gid, uv.fs_stat(filename).gid)
+ end
end
- id_fd:close()
-
- -- User can be a member of only one group.
- -- In that case we can not perform this test.
- if new_gid then
- eq(0, (os_fchown(filename, -1, new_gid)))
- eq(new_gid, luv.fs_stat(filename).gid)
- end
- end)
+ )
end
- if (ffi.os == 'Windows' or ffi.C.geteuid() == 0) then
+ if ffi.os == 'Windows' or ffi.C.geteuid() == 0 then
pending('skipped (uv_fs_chown is no-op on Windows)', function() end)
else
itp('returns nonzero if process has not enough permissions', function()
@@ -318,7 +321,6 @@ describe('fs.c', function()
end
end)
-
describe('os_file_is_readable', function()
itp('returns false if the file is not readable', function()
local perm = os_getperm('unit-test-directory/test.file')
@@ -330,13 +332,11 @@ describe('fs.c', function()
end)
itp('returns false if the file does not exist', function()
- eq(false, os_file_is_readable(
- 'unit-test-directory/what_are_you_smoking.gif'))
+ eq(false, os_file_is_readable('unit-test-directory/what_are_you_smoking.gif'))
end)
itp('returns true if the file is readable', function()
- eq(true, os_file_is_readable(
- 'unit-test-directory/test.file'))
+ eq(true, os_file_is_readable('unit-test-directory/test.file'))
end)
end)
@@ -387,7 +387,7 @@ describe('fs.c', function()
else
buf = ffi.new('char[?]', size + 1, ('\0'):rep(size))
end
- local eof = ffi.new('bool[?]', 1, {true})
+ local eof = ffi.new('bool[?]', 1, { true })
local ret2 = fs.os_read(fd, eof, buf, size, false)
local ret1 = eof[0]
local ret3 = ''
@@ -400,16 +400,16 @@ describe('fs.c', function()
local bufs = {}
for i, size in ipairs(sizes) do
bufs[i] = {
- iov_base=ffi.new('char[?]', size + 1, ('\0'):rep(size)),
- iov_len=size,
+ iov_base = ffi.new('char[?]', size + 1, ('\0'):rep(size)),
+ iov_len = size,
}
end
local iov = ffi.new('struct iovec[?]', #sizes, bufs)
- local eof = ffi.new('bool[?]', 1, {true})
+ local eof = ffi.new('bool[?]', 1, { true })
local ret2 = fs.os_readv(fd, eof, iov, #sizes, false)
local ret1 = eof[0]
local ret3 = {}
- for i = 1,#sizes do
+ for i = 1, #sizes do
-- Warning: iov may not be used.
ret3[i] = ffi.string(bufs[i].iov_base, bufs[i].iov_len)
end
@@ -445,7 +445,7 @@ describe('fs.c', function()
eq(OK, (os_rename(test, not_exist)))
eq(false, (os_path_exists(test)))
eq(true, (os_path_exists(not_exist)))
- eq(OK, (os_rename(not_exist, test))) -- restore test file
+ eq(OK, (os_rename(not_exist, test))) -- restore test file
end)
itp('fail if source file does not exist', function()
@@ -494,14 +494,19 @@ describe('fs.c', function()
local dup0 = fs.os_dup(0)
local dup1 = fs.os_dup(1)
local dup2 = fs.os_dup(2)
- local tbl = {[0]=true, [1]=true, [2]=true,
- [tonumber(dup0)]=true, [tonumber(dup1)]=true,
- [tonumber(dup2)]=true}
+ local tbl = {
+ [0] = true,
+ [1] = true,
+ [2] = true,
+ [tonumber(dup0)] = true,
+ [tonumber(dup1)] = true,
+ [tonumber(dup2)] = true,
+ }
local i = 0
for _, _ in pairs(tbl) do
i = i + 1
end
- eq(i, 6) -- All fds must be unique
+ eq(i, 6) -- All fds must be unique
end)
end)
@@ -522,12 +527,15 @@ describe('fs.c', function()
eq(ffi.C.UV_ENOENT, (os_open('non-existing-file', ffi.C.kO_RDWR, 0)))
end)
- itp('returns non-negative for O_CREAT on a non-existing file which then can be closed', function()
- assert_file_does_not_exist(new_file)
- local fd = os_open(new_file, ffi.C.kO_CREAT, 0)
- assert.is_true(0 <= fd)
- eq(0, os_close(fd))
- end)
+ itp(
+ 'returns non-negative for O_CREAT on a non-existing file which then can be closed',
+ function()
+ assert_file_does_not_exist(new_file)
+ local fd = os_open(new_file, ffi.C.kO_CREAT, 0)
+ assert.is_true(0 <= fd)
+ eq(0, os_close(fd))
+ end
+ )
itp('returns non-negative for O_CREAT on a existing file which then can be closed', function()
assert_file_exists(existing_file)
@@ -544,26 +552,29 @@ describe('fs.c', function()
itp('sets `rwx` permissions for O_CREAT 700 which then can be closed', function()
assert_file_does_not_exist(new_file)
--create the file
- local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber("700", 8))
+ local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber('700', 8))
--verify permissions
- eq(33216, luv.fs_stat(new_file).mode)
+ eq(33216, uv.fs_stat(new_file).mode)
eq(0, os_close(fd))
end)
itp('sets `rw` permissions for O_CREAT 600 which then can be closed', function()
assert_file_does_not_exist(new_file)
--create the file
- local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber("600", 8))
+ local fd = os_open(new_file, ffi.C.kO_CREAT, tonumber('600', 8))
--verify permissions
- eq(33152, luv.fs_stat(new_file).mode)
+ eq(33152, uv.fs_stat(new_file).mode)
eq(0, os_close(fd))
end)
- itp('returns a non-negative file descriptor for an existing file which then can be closed', function()
- local fd = os_open(existing_file, ffi.C.kO_RDWR, 0)
- assert.is_true(0 <= fd)
- eq(0, os_close(fd))
- end)
+ itp(
+ 'returns a non-negative file descriptor for an existing file which then can be closed',
+ function()
+ local fd = os_open(existing_file, ffi.C.kO_RDWR, 0)
+ assert.is_true(0 <= fd)
+ eq(0, os_close(fd))
+ end
+ )
end)
describe('os_close', function()
@@ -589,43 +600,48 @@ describe('fs.c', function()
itp('can read zero bytes from a file', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, 0, ''}, {os_read(fd, nil)})
- eq({false, 0, ''}, {os_read(fd, 0)})
+ eq({ false, 0, '' }, { os_read(fd, nil) })
+ eq({ false, 0, '' }, { os_read(fd, 0) })
eq(0, os_close(fd))
end)
itp('can read from a file multiple times', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, 2, '\000\001'}, {os_read(fd, 2)})
- eq({false, 2, '\002\003'}, {os_read(fd, 2)})
+ eq({ false, 2, '\000\001' }, { os_read(fd, 2) })
+ eq({ false, 2, '\002\003' }, { os_read(fd, 2) })
eq(0, os_close(fd))
end)
itp('can read the whole file at once and then report eof', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, #fcontents, fcontents}, {os_read(fd, #fcontents)})
- eq({true, 0, ('\0'):rep(#fcontents)}, {os_read(fd, #fcontents)})
+ eq({ false, #fcontents, fcontents }, { os_read(fd, #fcontents) })
+ eq({ true, 0, ('\0'):rep(#fcontents) }, { os_read(fd, #fcontents) })
eq(0, os_close(fd))
end)
itp('can read the whole file in two calls, one partially', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, #fcontents * 3/4, fcontents:sub(1, #fcontents * 3/4)},
- {os_read(fd, #fcontents * 3/4)})
- eq({true,
- (#fcontents * 1/4),
- fcontents:sub(#fcontents * 3/4 + 1) .. ('\0'):rep(#fcontents * 2/4)},
- {os_read(fd, #fcontents * 3/4)})
+ eq(
+ { false, #fcontents * 3 / 4, fcontents:sub(1, #fcontents * 3 / 4) },
+ { os_read(fd, #fcontents * 3 / 4) }
+ )
+ eq({
+ true,
+ (#fcontents * 1 / 4),
+ fcontents:sub(#fcontents * 3 / 4 + 1) .. ('\0'):rep(#fcontents * 2 / 4),
+ }, { os_read(fd, #fcontents * 3 / 4) })
eq(0, os_close(fd))
end)
end)
describe('os_readv', function()
-- Function may be absent
- if not pcall(function() return fs.os_readv end) then
+ if not pcall(function()
+ return fs.os_readv
+ end) then
return
end
local file = 'test-unit-os-fs_spec-os_readv.dat'
@@ -643,45 +659,53 @@ describe('fs.c', function()
itp('can read zero bytes from a file', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, 0, {}}, {os_readv(fd, {})})
- eq({false, 0, {'', '', ''}}, {os_readv(fd, {0, 0, 0})})
+ eq({ false, 0, {} }, { os_readv(fd, {}) })
+ eq({ false, 0, { '', '', '' } }, { os_readv(fd, { 0, 0, 0 }) })
eq(0, os_close(fd))
end)
itp('can read from a file multiple times to a differently-sized buffers', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, 2, {'\000\001'}}, {os_readv(fd, {2})})
- eq({false, 5, {'\002\003', '\004\005\006'}}, {os_readv(fd, {2, 3})})
+ eq({ false, 2, { '\000\001' } }, { os_readv(fd, { 2 }) })
+ eq({ false, 5, { '\002\003', '\004\005\006' } }, { os_readv(fd, { 2, 3 }) })
eq(0, os_close(fd))
end)
itp('can read the whole file at once and then report eof', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false,
- #fcontents,
- {fcontents:sub(1, #fcontents * 1/4),
- fcontents:sub(#fcontents * 1/4 + 1, #fcontents * 3/4),
- fcontents:sub(#fcontents * 3/4 + 1, #fcontents * 15/16),
- fcontents:sub(#fcontents * 15/16 + 1, #fcontents)}},
- {os_readv(fd, {#fcontents * 1/4,
- #fcontents * 2/4,
- #fcontents * 3/16,
- #fcontents * 1/16})})
- eq({true, 0, {'\0'}}, {os_readv(fd, {1})})
+ eq({
+ false,
+ #fcontents,
+ {
+ fcontents:sub(1, #fcontents * 1 / 4),
+ fcontents:sub(#fcontents * 1 / 4 + 1, #fcontents * 3 / 4),
+ fcontents:sub(#fcontents * 3 / 4 + 1, #fcontents * 15 / 16),
+ fcontents:sub(#fcontents * 15 / 16 + 1, #fcontents),
+ },
+ }, {
+ os_readv(
+ fd,
+ { #fcontents * 1 / 4, #fcontents * 2 / 4, #fcontents * 3 / 16, #fcontents * 1 / 16 }
+ ),
+ })
+ eq({ true, 0, { '\0' } }, { os_readv(fd, { 1 }) })
eq(0, os_close(fd))
end)
itp('can read the whole file in two calls, one partially', function()
local fd = os_open(file, ffi.C.kO_RDONLY, 0)
ok(fd >= 0)
- eq({false, #fcontents * 3/4, {fcontents:sub(1, #fcontents * 3/4)}},
- {os_readv(fd, {#fcontents * 3/4})})
- eq({true,
- (#fcontents * 1/4),
- {fcontents:sub(#fcontents * 3/4 + 1) .. ('\0'):rep(#fcontents * 2/4)}},
- {os_readv(fd, {#fcontents * 3/4})})
+ eq(
+ { false, #fcontents * 3 / 4, { fcontents:sub(1, #fcontents * 3 / 4) } },
+ { os_readv(fd, { #fcontents * 3 / 4 }) }
+ )
+ eq({
+ true,
+ (#fcontents * 1 / 4),
+ { fcontents:sub(#fcontents * 3 / 4 + 1) .. ('\0'):rep(#fcontents * 2 / 4) },
+ }, { os_readv(fd, { #fcontents * 3 / 4 }) })
eq(0, os_close(fd))
end)
end)
@@ -744,8 +768,8 @@ describe('fs.c', function()
end
local function os_mkdir_recurse(path, mode)
- local failed_str = ffi.new('char *[1]', {nil})
- local created_str = ffi.new('char *[1]', {nil})
+ local failed_str = ffi.new('char *[1]', { nil })
+ 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
@@ -769,7 +793,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')))
- luv.fs_rmdir('unit-test-directory/new-dir')
+ uv.fs_rmdir('unit-test-directory/new-dir')
end)
end)
@@ -784,8 +808,7 @@ describe('fs.c', function()
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_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/test.file', mode)
+ 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_dir)
eq(nil, created_dir)
@@ -793,8 +816,8 @@ describe('fs.c', function()
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_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/test.file/test', mode)
+ 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_dir)
eq(nil, created_dir)
@@ -802,44 +825,44 @@ describe('fs.c', function()
itp('succeeds to create a directory', function()
local mode = ffi.C.kS_IRUSR + ffi.C.kS_IWUSR + ffi.C.kS_IXUSR
- local ret, failed_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/new-dir-recurse', mode)
+ local ret, failed_dir, created_dir =
+ os_mkdir_recurse('unit-test-directory/new-dir-recurse', mode)
eq(0, ret)
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')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
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_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/new-dir-recurse///', mode)
+ local ret, failed_dir, created_dir =
+ os_mkdir_recurse('unit-test-directory/new-dir-recurse///', mode)
eq(0, ret)
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')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
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_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/new-dir-recurse/', mode)
+ local ret, failed_dir, created_dir =
+ os_mkdir_recurse('unit-test-directory/new-dir-recurse/', mode)
eq(0, ret)
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')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
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_dir, created_dir = os_mkdir_recurse(
- 'unit-test-directory/new-dir-recurse/1/2/3', mode)
+ 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_dir)
ok(endswith(created_dir, 'unit-test-directory/new-dir-recurse'))
@@ -847,10 +870,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'))
- 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')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2/3')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse/1/2')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse/1')
+ uv.fs_rmdir('unit-test-directory/new-dir-recurse')
eq(false, os_isdir('unit-test-directory/new-dir-recurse'))
end)
end)
@@ -1015,7 +1038,7 @@ describe('fs.c', function()
file:write('some bytes to get filesize != 0')
file:flush()
file:close()
- local size = luv.fs_stat(path).size
+ local size = uv.fs_stat(path).size
local info = file_info_new()
assert.is_true(fs.os_fileinfo(path, info))
eq(size, fs.os_fileinfo_size(info))
@@ -1029,7 +1052,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))
- luv.fs_link(path, path_link)
+ uv.fs_link(path, path_link)
assert.is_true(fs.os_fileinfo(path, info))
eq(2, fs.os_fileinfo_hardlinks(info))
end)
@@ -1038,7 +1061,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'
- local blksize = luv.fs_stat(path).blksize
+ local blksize = uv.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/os/shell_spec.lua b/test/unit/os/shell_spec.lua
index 3fb1afed44..ae162f2317 100644
--- a/test/unit/os/shell_spec.lua
+++ b/test/unit/os/shell_spec.lua
@@ -21,9 +21,7 @@ describe('shell functions', function()
end)
local function shell_build_argv(cmd, extra_args)
- local res = cimported.shell_build_argv(
- cmd and to_cstr(cmd),
- extra_args and to_cstr(extra_args))
+ local res = cimported.shell_build_argv(cmd and to_cstr(cmd), extra_args and to_cstr(extra_args))
-- `res` is zero-indexed (C pointer, not Lua table)!
local argc = 0
local ret = {}
@@ -40,9 +38,7 @@ describe('shell functions', function()
local function shell_argv_to_str(argv_table)
-- C string array (char **).
- local argv = (argv_table
- and ffi.new("char*[?]", #argv_table+1)
- or NULL)
+ local argv = (argv_table and ffi.new('char*[?]', #argv_table + 1) or NULL)
local argc = 1
while argv_table ~= nil and argv_table[argc] ~= nil do
@@ -64,8 +60,7 @@ describe('shell functions', function()
local output = ffi.new('char *[1]')
local nread = ffi.new('size_t[1]')
- local argv = ffi.cast('char**',
- cimported.shell_build_argv(to_cstr(cmd), nil))
+ local argv = ffi.cast('char**', 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])
@@ -101,37 +96,35 @@ describe('shell functions', function()
describe('shell_build_argv', function()
itp('works with NULL arguments', function()
- eq({'/bin/sh'}, shell_build_argv(nil, nil))
+ eq({ '/bin/sh' }, shell_build_argv(nil, nil))
end)
itp('works with cmd', function()
- eq({'/bin/sh', '-c', 'abc def'}, shell_build_argv('abc def', nil))
+ eq({ '/bin/sh', '-c', 'abc def' }, shell_build_argv('abc def', nil))
end)
itp('works with extra_args', function()
- eq({'/bin/sh', 'ghi jkl'}, shell_build_argv(nil, 'ghi jkl'))
+ eq({ '/bin/sh', 'ghi jkl' }, shell_build_argv(nil, 'ghi jkl'))
end)
itp('works with cmd and extra_args', function()
- eq({'/bin/sh', 'ghi jkl', '-c', 'abc def'}, shell_build_argv('abc def', 'ghi jkl'))
+ eq({ '/bin/sh', 'ghi jkl', '-c', 'abc def' }, shell_build_argv('abc def', 'ghi jkl'))
end)
itp('splits and unquotes &shell and &shellcmdflag', function()
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',
- '-c', 'abc def'},
- shell_build_argv('abc def', 'ghi jkl'))
+ eq(
+ { '/Program Files/zsh', '-f', 'ghi jkl', '-x', '-o', 'sh word split', '-c', 'abc def' },
+ shell_build_argv('abc def', 'ghi jkl')
+ )
end)
itp('applies shellxescape (p_sxe) and shellxquote (p_sxq)', function()
cimported.p_sxq = to_cstr('(')
cimported.p_sxe = to_cstr('"&|<>()@^')
- local argv = ffi.cast('char**',
- cimported.shell_build_argv(to_cstr('echo &|<>()@^'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo &|<>()@^'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '(echo ^&^|^<^>^(^)^@^^)')
@@ -142,8 +135,7 @@ describe('shell functions', function()
cimported.p_sxq = to_cstr('"(')
cimported.p_sxe = to_cstr('"&|<>()@^')
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '"(echo -n some text)"')
@@ -154,8 +146,7 @@ describe('shell functions', function()
cimported.p_sxq = to_cstr('"')
cimported.p_sxe = to_cstr('')
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), '"echo -n some text"')
@@ -163,8 +154,7 @@ describe('shell functions', function()
end)
itp('with empty shellxquote/shellxescape', function()
- local argv = ffi.cast('char**', cimported.shell_build_argv(
- to_cstr('echo -n some text'), nil))
+ local argv = ffi.cast('char**', cimported.shell_build_argv(to_cstr('echo -n some text'), nil))
eq(ffi.string(argv[0]), '/bin/sh')
eq(ffi.string(argv[1]), '-c')
eq(ffi.string(argv[2]), 'echo -n some text')
@@ -176,9 +166,11 @@ describe('shell functions', function()
eq('', shell_argv_to_str({ nil }))
eq("''", shell_argv_to_str({ '' }))
eq("'foo' '' 'bar'", shell_argv_to_str({ 'foo', '', 'bar' }))
- eq("'/bin/sh' '-c' 'abc def'", shell_argv_to_str({'/bin/sh', '-c', 'abc def'}))
- eq("'abc def' 'ghi jkl'", shell_argv_to_str({'abc def', 'ghi jkl'}))
- eq("'/bin/sh' '-c' 'abc def' '"..('x'):rep(225).."...",
- shell_argv_to_str({'/bin/sh', '-c', 'abc def', ('x'):rep(999)}))
+ eq("'/bin/sh' '-c' 'abc def'", shell_argv_to_str({ '/bin/sh', '-c', 'abc def' }))
+ eq("'abc def' 'ghi jkl'", shell_argv_to_str({ 'abc def', 'ghi jkl' }))
+ eq(
+ "'/bin/sh' '-c' 'abc def' '" .. ('x'):rep(225) .. '...',
+ shell_argv_to_str({ '/bin/sh', '-c', 'abc def', ('x'):rep(999) })
+ )
end)
end)
diff --git a/test/unit/path_spec.lua b/test/unit/path_spec.lua
index 23f71cfe78..c564ec119e 100644
--- a/test/unit/path_spec.lua
+++ b/test/unit/path_spec.lua
@@ -1,4 +1,4 @@
-local luv = require('luv')
+local uv = vim.uv
local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
@@ -27,7 +27,7 @@ describe('path.c', function()
end)
teardown(function()
- luv.fs_rmdir('unit-test-directory')
+ uv.fs_rmdir('unit-test-directory')
end)
local function path_full_dir_name(directory, buf, len)
@@ -37,34 +37,34 @@ describe('path.c', function()
before_each(function()
-- Create empty string buffer which will contain the resulting path.
- length = string.len(luv.cwd()) + 22
+ length = string.len(uv.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 = luv.cwd()
- luv.chdir('..')
- local expected = luv.cwd()
- luv.chdir(old_dir)
+ local old_dir = uv.cwd()
+ uv.chdir('..')
+ local expected = uv.cwd()
+ uv.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(luv.cwd(), (ffi.string(buffer)))
+ eq(uv.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(luv.cwd() .. '/unit-test-directory', (ffi.string(buffer)))
+ eq(uv.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(luv.cwd() .. '/does-not-exist', (ffi.string(buffer)))
+ eq(uv.cwd() .. '/does-not-exist', (ffi.string(buffer)))
eq(OK, result)
end)
@@ -184,7 +184,7 @@ describe('path.c', function()
itp('returns the executable name of an invocation given a relative invocation', function()
local invk, len = invocation_path_tail('directory/exe a b c')
- compare("exe a b c", invk, len)
+ compare('exe a b c', invk, len)
eq(3, len)
end)
@@ -202,7 +202,7 @@ describe('path.c', function()
itp('does not count arguments to the executable as part of its path', function()
local invk, len = invocation_path_tail('exe a/b\\c')
- compare("exe a/b\\c", invk, len)
+ compare('exe a/b\\c', invk, len)
eq(3, len)
end)
@@ -212,17 +212,17 @@ describe('path.c', function()
end)
itp('is equivalent to path_tail when args do not contain a path separator', function()
- local ptail = cimp.path_tail(to_cstr("a/b/c x y z"))
+ local ptail = cimp.path_tail(to_cstr('a/b/c x y z'))
neq(NULL, ptail)
local tail = ffi.string(ptail)
- local invk, _ = invocation_path_tail("a/b/c x y z")
+ local invk, _ = invocation_path_tail('a/b/c x y z')
eq(tail, ffi.string(invk))
end)
itp('is not equivalent to path_tail when args contain a path separator', function()
- local ptail = cimp.path_tail(to_cstr("a/b/c x y/z"))
+ local ptail = cimp.path_tail(to_cstr('a/b/c x y/z'))
neq(NULL, ptail)
- local invk, _ = invocation_path_tail("a/b/c x y/z")
+ local invk, _ = invocation_path_tail('a/b/c x y/z')
neq((ffi.string(ptail)), (ffi.string(invk)))
end)
end)
@@ -270,27 +270,27 @@ describe('path.c', function()
end)
describe('path_try_shorten_fname', function()
- local cwd = luv.cwd()
+ local cwd = uv.cwd()
before_each(function()
mkdir('ut_directory')
end)
after_each(function()
- luv.chdir(cwd)
- luv.fs_rmdir('ut_directory')
+ uv.chdir(cwd)
+ uv.fs_rmdir('ut_directory')
end)
describe('path_try_shorten_fname', function()
itp('returns shortened path if possible', function()
- luv.chdir('ut_directory')
- local full = to_cstr(luv.cwd() .. '/subdir/file.txt')
+ uv.chdir('ut_directory')
+ local full = to_cstr(uv.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 = luv.cwd()
- luv.chdir('ut_directory')
+ local old = uv.cwd()
+ uv.chdir('ut_directory')
local full = old .. '/subdir/file.txt'
eq(full, (ffi.string(cimp.path_try_shorten_fname(to_cstr(full)))))
end)
@@ -302,14 +302,14 @@ describe('path_try_shorten_fname', function()
end)
describe('path.c path_guess_exepath', function()
- local cwd = luv.cwd()
+ local cwd = uv.cwd()
- for _,name in ipairs({'./nvim', '.nvim', 'foo/nvim'}) do
- itp('"'..name..'" returns name catenated with CWD', function()
+ for _, name in ipairs({ './nvim', '.nvim', 'foo/nvim' }) do
+ itp('"' .. name .. '" returns name catenated with CWD', function()
local bufsize = 255
local buf = cstr(bufsize, '')
cimp.path_guess_exepath(name, buf, bufsize)
- eq(cwd..'/'..name, ffi.string(buf))
+ eq(cwd .. '/' .. name, ffi.string(buf))
end)
end
@@ -331,10 +331,10 @@ describe('path.c path_guess_exepath', function()
itp('does not crash if $PATH item exceeds MAXPATHL', function()
local orig_path_env = os.getenv('PATH')
- local name = 'cat' -- Some executable in $PATH.
+ local name = 'cat' -- Some executable in $PATH.
local bufsize = 255
local buf = cstr(bufsize, '')
- local insane_path = orig_path_env..':'..(("x/"):rep(4097))
+ local insane_path = orig_path_env .. ':' .. (('x/'):rep(4097))
cimp.os_setenv('PATH', insane_path, true)
cimp.path_guess_exepath(name, buf, bufsize)
@@ -345,7 +345,7 @@ describe('path.c path_guess_exepath', function()
end)
itp('returns full path found in $PATH', function()
- local name = 'cat' -- Some executable in $PATH.
+ local name = 'cat' -- Some executable in $PATH.
local bufsize = 255
local buf = cstr(bufsize, '')
cimp.path_guess_exepath(name, buf, bufsize)
@@ -356,7 +356,7 @@ end)
describe('path.c', function()
setup(function()
- 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
@@ -365,12 +365,12 @@ describe('path.c', function()
-- Split absolute_executable into a directory and the actual file name for
-- later usage.
- local directory, executable_name = string.match(absolute_executable, '^(.*)/(.*)$') -- luacheck: ignore
+ local directory, executable_name = string.match(absolute_executable, '^(.*)/(.*)$') -- luacheck: ignore
end)
teardown(function()
os.remove('unit-test-directory/test.file')
- luv.fs_rmdir('unit-test-directory')
+ uv.fs_rmdir('unit-test-directory')
end)
describe('vim_FullName', function()
@@ -422,7 +422,7 @@ describe('path.c', function()
end)
itp('concatenates filename if it does not contain a slash', function()
- local expected = luv.cwd() .. '/test.file'
+ local expected = uv.cwd() .. '/test.file'
local filename = 'test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -432,7 +432,7 @@ describe('path.c', function()
end)
itp('concatenates directory name if it does not contain a slash', function()
- local expected = luv.cwd() .. '/..'
+ local expected = uv.cwd() .. '/..'
local filename = '..'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -441,18 +441,21 @@ describe('path.c', function()
eq(OK, result)
end)
- itp('enters given directory (instead of just concatenating the strings) if possible and if path contains a slash', function()
- 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
- local buf, result = vim_FullName(filename, buflen, do_expand)
- eq(expected, ffi.string(buf))
- eq(OK, result)
- end)
+ itp(
+ 'enters given directory (instead of just concatenating the strings) if possible and if path contains a slash',
+ function()
+ local old_dir = uv.cwd()
+ uv.chdir('..')
+ local expected = uv.cwd() .. '/test.file'
+ uv.chdir(old_dir)
+ local filename = '../test.file'
+ local buflen = get_buf_len(expected, filename)
+ local do_expand = 1
+ local buf, result = vim_FullName(filename, buflen, do_expand)
+ eq(expected, ffi.string(buf))
+ eq(OK, result)
+ end
+ )
itp('just copies the path if it is already absolute and force=0', function()
local absolute_path = '/absolute/path'
@@ -474,7 +477,7 @@ describe('path.c', function()
end)
itp('works with some "normal" relative path with directories', function()
- local expected = luv.cwd() .. '/unit-test-directory/test.file'
+ local expected = uv.cwd() .. '/unit-test-directory/test.file'
local filename = 'unit-test-directory/test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -484,7 +487,7 @@ describe('path.c', function()
end)
itp('does not modify the given filename', function()
- local expected = luv.cwd() .. '/unit-test-directory/test.file'
+ local expected = uv.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, '')
@@ -507,7 +510,7 @@ describe('path.c', function()
end)
itp('does not remove trailing slash from non-existing relative directory #20847', function()
- local expected = luv.cwd() .. '/non_existing_dir/'
+ local expected = uv.cwd() .. '/non_existing_dir/'
local filename = 'non_existing_dir/'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -517,7 +520,7 @@ describe('path.c', function()
end)
itp('expands "./" to the current directory #7117', function()
- local expected = luv.cwd() .. '/unit-test-directory/test.file'
+ local expected = uv.cwd() .. '/unit-test-directory/test.file'
local filename = './unit-test-directory/test.file'
local buflen = get_buf_len(expected, filename)
local do_expand = 1
@@ -527,7 +530,7 @@ describe('path.c', function()
end)
itp('collapses "foo/../foo" to "foo" #7117', function()
- local expected = luv.cwd() .. '/unit-test-directory/test.file'
+ local expected = uv.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
@@ -544,8 +547,12 @@ describe('path.c', function()
return ffi.string(c_file)
end
- before_each(function() mkdir('CamelCase') end)
- after_each(function() luv.fs_rmdir('CamelCase') end)
+ before_each(function()
+ mkdir('CamelCase')
+ end)
+ after_each(function()
+ uv.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()
@@ -565,14 +572,14 @@ describe('path.c', function()
local path1 = cstr(100, 'path1')
local to_append = to_cstr('path2')
eq(OK, (cimp.append_path(path1, to_append, 100)))
- eq("path1/path2", (ffi.string(path1)))
+ eq('path1/path2', (ffi.string(path1)))
end)
itp('joins given paths without adding an unnecessary slash', function()
local path1 = cstr(100, 'path1/')
local to_append = to_cstr('path2')
eq(OK, cimp.append_path(path1, to_append, 100))
- eq("path1/path2", (ffi.string(path1)))
+ eq('path1/path2', (ffi.string(path1)))
end)
itp('fails and uses filename if there is not enough space left for to_append', function()
@@ -610,15 +617,15 @@ describe('path.c', function()
end
itp('returns true if filename starts with a slash', function()
- eq(OK, path_is_absolute('/some/directory/'))
+ eq(true, path_is_absolute('/some/directory/'))
end)
itp('returns true if filename starts with a tilde', function()
- eq(OK, path_is_absolute('~/in/my/home~/directory'))
+ eq(true, path_is_absolute('~/in/my/home~/directory'))
end)
itp('returns false if filename starts not with slash nor tilde', function()
- eq(FAIL, path_is_absolute('not/in/my/home~/directory'))
+ eq(false, path_is_absolute('not/in/my/home~/directory'))
end)
end)
diff --git a/test/unit/preprocess.lua b/test/unit/preprocess.lua
index e356695c14..6294114e1e 100644
--- a/test/unit/preprocess.lua
+++ b/test/unit/preprocess.lua
@@ -1,7 +1,7 @@
-- helps managing loading different headers into the LuaJIT ffi. Untested on
-- windows, will probably need quite a bit of adjustment to run there.
-local ffi = require("ffi")
+local ffi = require('ffi')
local global_helpers = require('test.helpers')
local argss_to_cmd = global_helpers.argss_to_cmd
@@ -12,37 +12,37 @@ local repeated_read_cmd = global_helpers.repeated_read_cmd
--- @type Compiler[]
local ccs = {}
-local env_cc = os.getenv("CC")
+local env_cc = os.getenv('CC')
if env_cc then
- table.insert(ccs, {path = {"/usr/bin/env", env_cc}, type = "gcc"})
+ table.insert(ccs, { path = { '/usr/bin/env', env_cc }, type = 'gcc' })
end
-if ffi.os == "Windows" then
- table.insert(ccs, {path = {"cl"}, type = "msvc"})
+if ffi.os == 'Windows' then
+ table.insert(ccs, { path = { 'cl' }, type = 'msvc' })
end
-table.insert(ccs, {path = {"/usr/bin/env", "cc"}, type = "gcc"})
-table.insert(ccs, {path = {"/usr/bin/env", "gcc"}, type = "gcc"})
-table.insert(ccs, {path = {"/usr/bin/env", "gcc-4.9"}, type = "gcc"})
-table.insert(ccs, {path = {"/usr/bin/env", "gcc-4.8"}, type = "gcc"})
-table.insert(ccs, {path = {"/usr/bin/env", "gcc-4.7"}, type = "gcc"})
-table.insert(ccs, {path = {"/usr/bin/env", "clang"}, type = "clang"})
-table.insert(ccs, {path = {"/usr/bin/env", "icc"}, type = "gcc"})
+table.insert(ccs, { path = { '/usr/bin/env', 'cc' }, type = 'gcc' })
+table.insert(ccs, { path = { '/usr/bin/env', 'gcc' }, type = 'gcc' })
+table.insert(ccs, { path = { '/usr/bin/env', 'gcc-4.9' }, type = 'gcc' })
+table.insert(ccs, { path = { '/usr/bin/env', 'gcc-4.8' }, type = 'gcc' })
+table.insert(ccs, { path = { '/usr/bin/env', 'gcc-4.7' }, type = 'gcc' })
+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("\\", "")
+ deps = deps:gsub('\n', ''):gsub('\\', '')
-- remove the Makefile "target:" element
- deps = deps:gsub(".+:", "")
+ deps = deps:gsub('.+:', '')
-- remove redundant spaces
- deps = deps:gsub(" +", " ")
+ deps = deps:gsub(' +', ' ')
-- split according to token (space in this case)
local headers = {} --- @type string[]
- for token in deps:gmatch("[^%s]+") do
+ for token in deps:gmatch('[^%s]+') do
-- headers[token] = true
headers[#headers + 1] = token
end
@@ -50,9 +50,9 @@ local function parse_make_deps(deps)
-- resolve path redirections (..) to normalize all paths
for i, v in ipairs(headers) do
-- double dots (..)
- headers[i] = v:gsub("/[^/%s]+/%.%.", "")
+ headers[i] = v:gsub('/[^/%s]+/%.%.', '')
-- single dot (.)
- headers[i] = v:gsub("%./", "")
+ headers[i] = v:gsub('%./', '')
end
return headers
@@ -80,7 +80,7 @@ local function headerize(headers, global)
formatted[#formatted + 1] = string.format(fmt, hdr)
end
- return table.concat(formatted, "\n")
+ return table.concat(formatted, '\n')
end
--- @class Gcc
@@ -90,8 +90,8 @@ end
--- @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'},
+ get_defines_extra_flags = { '-std=c99', '-dM', '-E' },
+ get_declarations_extra_flags = { '-std=c99', '-P', '-E' },
}
--- @param name string
@@ -115,13 +115,13 @@ end
function Gcc:init_defines()
-- preprocessor flags that will hopefully make the compiler produce C
-- declarations that the LuaJIT ffi understands.
- self:define('aligned', {'ARGS'}, '')
- self:define('__attribute__', {'ARGS'}, '')
- self:define('__asm', {'ARGS'}, '')
- self:define('__asm__', {'ARGS'}, '')
+ self:define('aligned', { 'ARGS' }, '')
+ self:define('__attribute__', { 'ARGS' }, '')
+ self:define('__asm', { 'ARGS' }, '')
+ self:define('__asm__', { 'ARGS' }, '')
self:define('__inline__', nil, '')
self:define('EXTERN', nil, 'extern')
- self:define('INIT', {'...'}, '')
+ self:define('INIT', { '...' }, '')
self:define('_GNU_SOURCE')
self:define('INCLUDE_GENERATED_DECLARATIONS')
self:define('UNIT_TESTING')
@@ -158,9 +158,9 @@ end
--- @return string[]?
function Gcc:dependencies(hdr)
--- @type string
- local cmd = argss_to_cmd(self.path, {'-M', hdr}) .. ' 2>&1'
+ local cmd = argss_to_cmd(self.path, { '-M', hdr }) .. ' 2>&1'
local out = assert(io.popen(cmd))
- local deps = out:read("*a")
+ local deps = out:read('*a')
out:close()
if deps then
return parse_make_deps(deps)
@@ -174,10 +174,14 @@ function Gcc:filter_standard_defines(defines)
local pseudoheader_fname = 'tmp_empty_pseudoheader.h'
local pseudoheader_file = assert(io.open(pseudoheader_fname, 'w'))
pseudoheader_file:close()
- local standard_defines = assert(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 = {} --- @type table<string,true>
for line in standard_defines:gmatch('[^\n]+') do
@@ -192,7 +196,7 @@ function Gcc:filter_standard_defines(defines)
end
end
- return table.concat(ret, "\n")
+ return table.concat(ret, '\n')
end
--- returns a stream representing a preprocessed form of the passed-in headers.
@@ -202,24 +206,33 @@ end
--- @return string, string
function Gcc:preprocess(previous_defines, ...)
-- create pseudo-header
- local pseudoheader = headerize({...}, false)
+ local pseudoheader = headerize({ ... }, false)
local pseudoheader_fname = 'tmp_pseudoheader.h'
local pseudoheader_file = assert(io.open(pseudoheader_fname, 'w'))
pseudoheader_file:write(previous_defines)
- pseudoheader_file:write("\n")
+ pseudoheader_file:write('\n')
pseudoheader_file:write(pseudoheader)
pseudoheader_file:flush()
pseudoheader_file:close()
- local defines = assert(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 = assert(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)
@@ -233,10 +246,10 @@ end
--- @return Gcc?
local function find_best_cc(compilers)
for _, meta in pairs(compilers) do
- local version = assert(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 Gcc:new({path = meta.path})
+ return Gcc:new({ path = meta.path })
end
end
end
diff --git a/test/unit/profile_spec.lua b/test/unit/profile_spec.lua
index 08e5cedbab..011d3632d5 100644
--- a/test/unit/profile_spec.lua
+++ b/test/unit/profile_spec.lua
@@ -10,11 +10,11 @@ local prof = cimport('./src/nvim/profile.h')
local function split(inputstr, sep)
if sep == nil then
- sep = "%s"
+ sep = '%s'
end
local t, i = {}, 1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
+ for str in string.gmatch(inputstr, '([^' .. sep .. ']+)') do
t[i] = str
i = i + 1
end
@@ -23,36 +23,44 @@ local function split(inputstr, sep)
end
local function trim(s)
- local from = s:match"^%s*()"
- return from > #s and "" or s:match(".*%S", from)
+ local from = s:match '^%s*()'
+ return from > #s and '' or s:match('.*%S', from)
end
local function starts(str, start)
- return string.sub(str, 1, string.len(start)) == start
+ return string.sub(str, 1, string.len(start)) == start
end
local function cmp_assert(v1, v2, op, opstr)
local res = op(v1, v2)
if res == false then
- print(string.format("expected: %f %s %f", v1, opstr, v2))
+ print(string.format('expected: %f %s %f', v1, opstr, v2))
end
assert.is_true(res)
end
-local function lt(a, b) -- luacheck: ignore
- cmp_assert(a, b, function(x, y) return x < y end, "<")
+local function lt(a, b) -- luacheck: ignore
+ cmp_assert(a, b, function(x, y)
+ return x < y
+ end, '<')
end
-local function lte(a, b) -- luacheck: ignore
- cmp_assert(a, b, function(x, y) return x <= y end, "<=")
+local function lte(a, b) -- luacheck: ignore
+ cmp_assert(a, b, function(x, y)
+ return x <= y
+ end, '<=')
end
-local function gt(a, b) -- luacheck: ignore
- cmp_assert(a, b, function(x, y) return x > y end, ">")
+local function gt(a, b) -- luacheck: ignore
+ cmp_assert(a, b, function(x, y)
+ return x > y
+ end, '>')
end
local function gte(a, b)
- cmp_assert(a, b, function(x, y) return x >= y end, ">=")
+ cmp_assert(a, b, function(x, y)
+ return x >= y
+ end, '>=')
end
-- missing functions:
@@ -61,21 +69,43 @@ end
-- profile_set_wait
-- profile_sub_wait
describe('profiling related functions', function()
- local function profile_start() return prof.profile_start() end
- local function profile_end(t) return prof.profile_end(t) end
- local function profile_zero() return prof.profile_zero() end
- local function profile_setlimit(ms) return prof.profile_setlimit(ms) end
- local function profile_passed_limit(t) return prof.profile_passed_limit(t) end
- local function profile_add(t1, t2) return prof.profile_add(t1, t2) end
- local function profile_sub(t1, t2) return prof.profile_sub(t1, t2) end
- local function profile_divide(t, cnt) return prof.profile_divide(t, cnt) end
- local function profile_cmp(t1, t2) return prof.profile_cmp(t1, t2) end
- local function profile_equal(t1, t2) return prof.profile_equal(t1, t2) end
- local function profile_msg(t) return ffi.string(prof.profile_msg(t)) end
-
- local function toseconds(t) -- luacheck: ignore
+ local function profile_start()
+ return prof.profile_start()
+ end
+ local function profile_end(t)
+ return prof.profile_end(t)
+ end
+ local function profile_zero()
+ return prof.profile_zero()
+ end
+ local function profile_setlimit(ms)
+ return prof.profile_setlimit(ms)
+ end
+ local function profile_passed_limit(t)
+ return prof.profile_passed_limit(t)
+ end
+ local function profile_add(t1, t2)
+ return prof.profile_add(t1, t2)
+ end
+ local function profile_sub(t1, t2)
+ return prof.profile_sub(t1, t2)
+ end
+ local function profile_divide(t, cnt)
+ return prof.profile_divide(t, cnt)
+ end
+ local function profile_cmp(t1, t2)
+ return prof.profile_cmp(t1, t2)
+ end
+ local function profile_equal(t1, t2)
+ return prof.profile_equal(t1, t2)
+ end
+ local function profile_msg(t)
+ return ffi.string(prof.profile_msg(t))
+ end
+
+ local function toseconds(t) -- luacheck: ignore
local str = trim(profile_msg(t))
- local spl = split(str, ".")
+ local spl = split(str, '.')
local s, us = spl[1], spl[2]
return tonumber(s) + tonumber(us) / 1000000
end
@@ -199,14 +229,14 @@ describe('profiling related functions', function()
describe('profile_msg', function()
itp('prints the zero time as 0.00000', function()
local str = trim(profile_msg(profile_zero()))
- eq(str, "0.000000")
+ eq(str, '0.000000')
end)
itp('prints the time passed, in seconds.microsends', function()
local start = profile_start()
local endt = profile_end(start)
local str = trim(profile_msg(endt))
- local spl = split(str, ".")
+ local spl = split(str, '.')
-- string has two parts (before dot and after dot)
eq(2, #spl)
@@ -215,11 +245,11 @@ describe('profiling related functions', function()
-- zero seconds have passed (if this is not true, either LuaJIT is too
-- slow or the profiling functions are too slow and need to be fixed)
- eq(s, "0")
+ eq(s, '0')
-- more or less the same goes for the microsecond part, if it doesn't
-- start with 0, it's too slow.
- assert.is_true(starts(us, "0"))
+ assert.is_true(starts(us, '0'))
end)
end)
diff --git a/test/unit/rbuffer_spec.lua b/test/unit/rbuffer_spec.lua
index e9104dd5c4..328e5b93da 100644
--- a/test/unit/rbuffer_spec.lua
+++ b/test/unit/rbuffer_spec.lua
@@ -1,4 +1,4 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local eq = helpers.eq
@@ -7,7 +7,7 @@ local cstr = helpers.cstr
local to_cstr = helpers.to_cstr
local child_call_once = helpers.child_call_once
-local rbuffer = helpers.cimport("./test/unit/fixtures/rbuffer.h")
+local rbuffer = helpers.cimport('./test/unit/fixtures/rbuffer.h')
describe('rbuffer functions', function()
local capacity = 16
@@ -56,7 +56,7 @@ describe('rbuffer functions', function()
describe('with empty buffer in one contiguous chunk', function()
itp('is called once with the empty chunk', function()
collect_write_chunks()
- eq({'0000000000000000'}, chunks)
+ eq({ '0000000000000000' }, chunks)
end)
end)
@@ -64,7 +64,7 @@ describe('rbuffer functions', function()
itp('is called once with the empty chunk', function()
write('string')
collect_write_chunks()
- eq({'0000000000'}, chunks)
+ eq({ '0000000000' }, chunks)
end)
end)
@@ -81,7 +81,7 @@ describe('rbuffer functions', function()
write('1234567890')
read(8)
collect_write_chunks()
- eq({'000000', '12345678'}, chunks)
+ eq({ '000000', '12345678' }, chunks)
end)
end)
@@ -90,7 +90,7 @@ describe('rbuffer functions', function()
write('12345678')
read(8)
collect_write_chunks()
- eq({'00000000', '12345678'}, chunks)
+ eq({ '00000000', '12345678' }, chunks)
end)
end)
@@ -129,7 +129,7 @@ describe('rbuffer functions', function()
itp('is called once with the filled chunk', function()
write('string')
collect_read_chunks()
- eq({'string'}, chunks)
+ eq({ 'string' }, chunks)
end)
end)
@@ -137,7 +137,7 @@ describe('rbuffer functions', function()
itp('is called once with the filled chunk', function()
write('abcdefghijklmnopq')
collect_read_chunks()
- eq({'abcdefghijklmnop'}, chunks)
+ eq({ 'abcdefghijklmnop' }, chunks)
end)
end)
@@ -147,7 +147,7 @@ describe('rbuffer functions', function()
read(10)
write('long string')
collect_read_chunks()
- eq({'long s', 'tring'}, chunks)
+ eq({ 'long s', 'tring' }, chunks)
end)
end)
@@ -157,7 +157,7 @@ describe('rbuffer functions', function()
read(8)
write('abcdefghijklmnopq')
collect_read_chunks()
- eq({'abcdefgh', 'ijklmnop'}, chunks)
+ eq({ 'abcdefgh', 'ijklmnop' }, chunks)
end)
end)
end)
@@ -167,7 +167,7 @@ describe('rbuffer functions', function()
local function collect_chars()
rbuffer.ut_rbuffer_each(rbuf, function(c, i)
- table.insert(chars, {string.char(c), tonumber(i)})
+ table.insert(chars, { string.char(c), tonumber(i) })
end)
end
before_each(function()
@@ -187,8 +187,19 @@ describe('rbuffer functions', function()
read(10)
write('long string')
collect_chars()
- eq({{'l', 0}, {'o', 1}, {'n', 2}, {'g', 3}, {' ', 4}, {'s', 5},
- {'t', 6}, {'r', 7}, {'i', 8}, {'n', 9}, {'g', 10}}, chars)
+ eq({
+ { 'l', 0 },
+ { 'o', 1 },
+ { 'n', 2 },
+ { 'g', 3 },
+ { ' ', 4 },
+ { 's', 5 },
+ { 't', 6 },
+ { 'r', 7 },
+ { 'i', 8 },
+ { 'n', 9 },
+ { 'g', 10 },
+ }, chars)
end)
end)
end)
@@ -198,7 +209,7 @@ describe('rbuffer functions', function()
local function collect_chars()
rbuffer.ut_rbuffer_each_reverse(rbuf, function(c, i)
- table.insert(chars, {string.char(c), tonumber(i)})
+ table.insert(chars, { string.char(c), tonumber(i) })
end)
end
before_each(function()
@@ -218,8 +229,19 @@ describe('rbuffer functions', function()
read(10)
write('long string')
collect_chars()
- eq({{'g', 10}, {'n', 9}, {'i', 8}, {'r', 7}, {'t', 6}, {'s', 5},
- {' ', 4}, {'g', 3}, {'n', 2}, {'o', 1}, {'l', 0}}, chars)
+ eq({
+ { 'g', 10 },
+ { 'n', 9 },
+ { 'i', 8 },
+ { 'r', 7 },
+ { 't', 6 },
+ { 's', 5 },
+ { ' ', 4 },
+ { 'g', 3 },
+ { 'n', 2 },
+ { 'o', 1 },
+ { 'l', 0 },
+ }, chars)
end)
end)
end)
diff --git a/test/unit/search_spec.lua b/test/unit/search_spec.lua
index be905bf5f0..efe49f974a 100644
--- a/test/unit/search_spec.lua
+++ b/test/unit/search_spec.lua
@@ -1,42 +1,42 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local to_cstr = helpers.to_cstr
-local eq = helpers.eq
+local eq = helpers.eq
-local search = helpers.cimport("./src/nvim/search.h")
+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
- eq(false, search.pat_has_uppercase(to_cstr("")))
+ eq(false, search.pat_has_uppercase(to_cstr('')))
-- works with utf uppercase
- eq(false, search.pat_has_uppercase(to_cstr("ä")))
- eq(true, search.pat_has_uppercase(to_cstr("Ä")))
- eq(true, search.pat_has_uppercase(to_cstr("äaÅ")))
+ eq(false, search.pat_has_uppercase(to_cstr('ä')))
+ eq(true, search.pat_has_uppercase(to_cstr('Ä')))
+ eq(true, search.pat_has_uppercase(to_cstr('äaÅ')))
-- works when pat ends with backslash
- eq(false, search.pat_has_uppercase(to_cstr("\\")))
- eq(false, search.pat_has_uppercase(to_cstr("ab$\\")))
+ eq(false, search.pat_has_uppercase(to_cstr('\\')))
+ eq(false, search.pat_has_uppercase(to_cstr('ab$\\')))
-- skips escaped characters
- eq(false, search.pat_has_uppercase(to_cstr("\\Ab")))
- eq(true, search.pat_has_uppercase(to_cstr("\\AU")))
+ eq(false, search.pat_has_uppercase(to_cstr('\\Ab')))
+ eq(true, search.pat_has_uppercase(to_cstr('\\AU')))
-- skips _X escaped characters
- eq(false, search.pat_has_uppercase(to_cstr("\\_Ab")))
- eq(true, search.pat_has_uppercase(to_cstr("\\_AU")))
+ eq(false, search.pat_has_uppercase(to_cstr('\\_Ab')))
+ eq(true, search.pat_has_uppercase(to_cstr('\\_AU')))
-- skips %X escaped characters
- eq(false, search.pat_has_uppercase(to_cstr("aa\\%Ab")))
- eq(true, search.pat_has_uppercase(to_cstr("aab\\%AU")))
+ 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 search_regcomp = function(pat, pat_save, pat_use, options)
+ local regmatch = ffi.new('regmmatch_T')
local fail = search.search_regcomp(to_cstr(pat), nil, pat_save, pat_use, options, regmatch)
return fail, regmatch
end
@@ -45,13 +45,13 @@ describe('search_regcomp', function()
return helpers.internalize(search.get_search_pat())
end
- itp("accepts regexp pattern with invalid utf", function()
+ 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)
+ local fail = search_regcomp('a\192', 0, 0, 0)
eq(1, fail)
- eq("\192a", get_search_pat())
+ eq('\192a', get_search_pat())
end)
end)
diff --git a/test/unit/set.lua b/test/unit/set.lua
index 7c30be32aa..f93238cc47 100644
--- a/test/unit/set.lua
+++ b/test/unit/set.lua
@@ -33,7 +33,7 @@ end
--- @return Set
function Set:copy()
- local obj = {nelem = self.nelem, tbl = {}, items = {}} --- @type Set
+ local obj = { nelem = self.nelem, tbl = {}, items = {} } --- @type Set
for k, v in pairs(self.tbl) do
obj.tbl[k] = v
end
@@ -128,13 +128,13 @@ function Set:to_table()
-- there might be gaps in @tbl, so we have to be careful and sort first
local keys = {} --- @type string[]
for idx, _ in pairs(self.tbl) do
- keys[#keys+1] = idx
+ keys[#keys + 1] = idx
end
table.sort(keys)
local copy = {} --- @type string[]
for _, idx in ipairs(keys) do
- copy[#copy+1] = self.tbl[idx]
+ copy[#copy + 1] = self.tbl[idx]
end
return copy
end
diff --git a/test/unit/statusline_spec.lua b/test/unit/statusline_spec.lua
index a124a588e9..83ba4176c5 100644
--- a/test/unit/statusline_spec.lua
+++ b/test/unit/statusline_spec.lua
@@ -1,14 +1,15 @@
-local helpers = require("test.unit.helpers")(after_each)
+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 eq = helpers.eq
+local NULL = helpers.NULL
-local buffer = helpers.cimport("./src/nvim/buffer.h")
-local globals = helpers.cimport("./src/nvim/globals.h")
-local stl = helpers.cimport("./src/nvim/statusline.h")
+local buffer = helpers.cimport('./src/nvim/buffer.h')
+local globals = helpers.cimport('./src/nvim/globals.h')
+local stl = helpers.cimport('./src/nvim/statusline.h')
+local grid = helpers.cimport('./src/nvim/grid.h')
describe('build_stl_str_hl', function()
local buffer_byte_size = 100
@@ -22,23 +23,29 @@ describe('build_stl_str_hl', function()
-- .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))
+ output_buffer = to_cstr(string.rep(' ', buffer_byte_size))
local pat = arg.pat or ''
- local fillchar = arg.fillchar or (' '):byte()
+ local fillchar = arg.fillchar or ' '
local maximum_cell_count = arg.maximum_cell_count or buffer_byte_size
+ if type(fillchar) == type('') then
+ fillchar = grid.schar_from_str(fillchar)
+ end
- 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)
+ return stl.build_stl_str_hl(
+ globals.curwin,
+ output_buffer,
+ buffer_byte_size,
+ to_cstr(pat),
+ -1,
+ 0,
+ fillchar,
+ maximum_cell_count,
+ NULL,
+ NULL,
+ NULL,
+ NULL
+ )
end
-- Use this function to simplify testing the comparison between
@@ -54,17 +61,12 @@ describe('build_stl_str_hl', function()
-- .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)
-
+ 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 fillchar = option.fillchar or ' '
local expected_cell_count = option.expected_cell_count or statusline_cell_count
local expected_byte_length = option.expected_byte_length or #expected_stl
@@ -75,9 +77,11 @@ describe('build_stl_str_hl', function()
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}
+ 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)
@@ -85,198 +89,383 @@ describe('build_stl_str_hl', function()
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')
+ 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})
+ 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})
+ statusline_test(
+ 'should handle `!` as a fillchar',
+ 10,
+ 'abcde%=',
+ 'abcde!!!!!',
+ { fillchar = '!' }
+ )
+ statusline_test(
+ 'should handle `~` as a fillchar',
+ 10,
+ '%=abcde',
+ '~~~~~abcde',
+ { fillchar = '~' }
+ )
+ statusline_test(
+ 'should put fillchar `!` in between text',
+ 10,
+ 'abc%=def',
+ 'abc!!!!def',
+ { fillchar = '!' }
+ )
+ statusline_test(
+ 'should put fillchar `~` in between text',
+ 10,
+ 'abc%=def',
+ 'abc~~~~def',
+ { fillchar = '~' }
+ )
+ statusline_test(
+ 'should put fillchar `━` in between text',
+ 10,
+ 'abc%=def',
+ 'abc━━━━def',
+ { fillchar = '━' }
+ )
+ 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})
+ 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})
+ 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<jkl')
- statusline_test('should truncate centered text when using ==', 10,
- 'abcde%=gone%=fghij', 'abcde<ghij')
- statusline_test('should respect the `<` marker', 10,
- 'abc%<defghijkl', 'abc<ghijkl')
- statusline_test('should truncate at `<` with one `=`, test 1', 10,
- 'abc%<def%=ghijklmno', 'abc<jklmno')
- statusline_test('should truncate at `<` with one `=`, test 2', 10,
- 'abcdef%=ghijkl%<mno', 'abcdefghi>')
- statusline_test('should truncate at `<` with one `=`, test 3', 10,
- 'abc%<def%=ghijklmno', 'abc<jklmno')
- statusline_test('should truncate at `<` with one `=`, test 4', 10,
- 'abc%<def%=ghij', 'abcdefghij')
- statusline_test('should truncate at `<` with one `=`, test 4', 10,
- 'abc%<def%=ghijk', 'abc<fghijk')
+ statusline_test(
+ 'should truncate when standard text pattern is too long',
+ 10,
+ '0123456789abcde',
+ '<6789abcde'
+ )
+ statusline_test('should truncate when using =', 10, 'abcdef%=ghijkl', 'abcdef<jkl')
+ statusline_test(
+ 'should truncate centered text when using ==',
+ 10,
+ 'abcde%=gone%=fghij',
+ 'abcde<ghij'
+ )
+ statusline_test('should respect the `<` marker', 10, 'abc%<defghijkl', 'abc<ghijkl')
+ statusline_test(
+ 'should truncate at `<` with one `=`, test 1',
+ 10,
+ 'abc%<def%=ghijklmno',
+ 'abc<jklmno'
+ )
+ statusline_test(
+ 'should truncate at `<` with one `=`, test 2',
+ 10,
+ 'abcdef%=ghijkl%<mno',
+ 'abcdefghi>'
+ )
+ statusline_test(
+ 'should truncate at `<` with one `=`, test 3',
+ 10,
+ 'abc%<def%=ghijklmno',
+ 'abc<jklmno'
+ )
+ statusline_test('should truncate at `<` with one `=`, test 4', 10, 'abc%<def%=ghij', 'abcdefghij')
+ statusline_test(
+ 'should truncate at `<` with one `=`, test 4',
+ 10,
+ 'abc%<def%=ghijk',
+ 'abc<fghijk'
+ )
- statusline_test('should truncate at `<` with many `=`, test 4', 10,
- 'ab%<cdef%=g%=h%=ijk', 'ab<efghijk')
+ statusline_test(
+ 'should truncate at `<` with many `=`, test 4',
+ 10,
+ 'ab%<cdef%=g%=h%=ijk',
+ 'ab<efghijk'
+ )
- statusline_test('should truncate at the first `<`', 10,
- 'abc%<def%<ghijklm', 'abc<hijklm')
+ statusline_test('should truncate at the first `<`', 10, 'abc%<def%<ghijklm', 'abc<hijklm')
statusline_test('should ignore trailing %', 3, 'abc%', 'abc')
-- alignment testing with fillchar
- local function statusline_test_align(description,
- statusline_cell_count,
- input_stl,
- expected_stl,
- arg)
+ 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)
+ statusline_test(
+ description .. ' without fillchar',
+ statusline_cell_count,
+ input_stl,
+ expected_stl:gsub('%~', ' '),
+ arg
+ )
+ arg.fillchar = '!'
+ statusline_test(
+ description .. ' with fillchar `!`',
+ statusline_cell_count,
+ input_stl,
+ expected_stl:gsub('%~', '!'),
+ arg
+ )
+ arg.fillchar = '━'
+ 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 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 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_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_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_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_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_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_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_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_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_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_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_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_align('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 = ''
for i = 1, 1000 do
tabline = tabline .. (i % 2 == 0 and '%#TabLineSel#' or '%#TabLineFill#') .. tostring(i % 2)
end
- statusline_test('should handle a large amount of any items', 20,
- tabline,
- '<1010101010101010101') -- Should not show any error
- statusline_test('should handle a larger amount of = than stl initial item', 20,
+ statusline_test('should handle a large amount of any items', 20, tabline, '<1010101010101010101') -- Should not show any error
+ statusline_test(
+ 'should handle a larger amount of = than stl initial item',
+ 20,
('%='):rep(STL_INITIAL_ITEMS * 5),
- ' ') -- Should not show any error
- statusline_test('should handle many extra characters', 20,
+ ' '
+ ) -- Should not show any error
+ statusline_test(
+ 'should handle many extra characters',
+ 20,
'a' .. ('a'):rep(STL_INITIAL_ITEMS * 5),
- '<aaaaaaaaaaaaaaaaaaa') -- Does not show any error
- statusline_test('should handle many extra characters and flags', 20,
+ '<aaaaaaaaaaaaaaaaaaa'
+ ) -- Does not show any error
+ statusline_test(
+ 'should handle many extra characters and flags',
+ 20,
'a' .. ('%=a'):rep(STL_INITIAL_ITEMS * 2),
- 'a<aaaaaaaaaaaaaaaaaa') -- Should not show any error
+ 'a<aaaaaaaaaaaaaaaaaa'
+ ) -- Should not show any error
-- multi-byte testing
- statusline_test('should handle multibyte characters', 10,
- 'Ĉ%=x', 'Ĉ x')
- statusline_test('should handle multibyte characters and different fillchars', 10,
- 'Ą%=mid%=end', 'Ą@mid@@end',
- {fillchar=('@'):byte()})
+ statusline_test('should handle multibyte characters', 10, 'Ĉ%=x', 'Ĉ x')
+ statusline_test(
+ 'should handle multibyte characters and different fillchars',
+ 10,
+ 'Ą%=mid%=end',
+ 'Ą@mid@@end',
+ { fillchar = '@' }
+ )
-- escaping % testing
statusline_test('should handle escape of %', 4, 'abc%%', 'abc%')
statusline_test('case where escaped % does not fit', 3, 'abc%%abcabc', '<bc')
statusline_test('escaped % is first', 1, '%%', '%')
-
end)
diff --git a/test/unit/strings_spec.lua b/test/unit/strings_spec.lua
index 6d7aceb4b2..eea669c964 100644
--- a/test/unit/strings_spec.lua
+++ b/test/unit/strings_spec.lua
@@ -1,4 +1,4 @@
-local helpers = require("test.unit.helpers")(after_each)
+local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
local cimport = helpers.cimport
@@ -6,8 +6,7 @@ local eq = helpers.eq
local ffi = helpers.ffi
local to_cstr = helpers.to_cstr
-local strings = cimport('stdlib.h', './src/nvim/strings.h',
- './src/nvim/memory.h')
+local strings = cimport('stdlib.h', './src/nvim/strings.h', './src/nvim/memory.h')
describe('vim_strsave_escaped()', function()
local vim_strsave_escaped = function(s, chars)
@@ -21,19 +20,19 @@ describe('vim_strsave_escaped()', function()
end
itp('precedes by a backslash all chars from second argument', function()
- eq([[\a\b\c\d]], vim_strsave_escaped('abcd','abcd'))
+ eq([[\a\b\c\d]], vim_strsave_escaped('abcd', 'abcd'))
end)
itp('precedes by a backslash chars only from second argument', function()
- eq([[\a\bcd]], vim_strsave_escaped('abcd','ab'))
+ eq([[\a\bcd]], vim_strsave_escaped('abcd', 'ab'))
end)
itp('returns a copy of passed string if second argument is empty', function()
- eq('text \n text', vim_strsave_escaped('text \n text',''))
+ eq('text \n text', vim_strsave_escaped('text \n text', ''))
end)
itp('returns an empty string if first argument is empty string', function()
- eq('', vim_strsave_escaped('','\r'))
+ eq('', vim_strsave_escaped('', '\r'))
end)
itp('returns a copy of passed string if it does not contain chars from 2nd argument', function()
@@ -148,14 +147,30 @@ describe('vim_snprintf()', function()
end
end
- local function i(n) return ffi.cast('int', n) end
- local function l(n) return ffi.cast('long', 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
+ local function i(n)
+ return ffi.cast('int', n)
+ end
+ local function l(n)
+ return ffi.cast('long', 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
@@ -232,49 +247,51 @@ describe('vim_snprintf()', function()
end)
end)
-describe('strcase_save()' , function()
+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))
+ eq('A', strcase_save('\xc1\x81', true))
+ eq('a', strcase_save('\xc1\x81', false))
end)
end)
-describe("reverse_text", function()
+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(""))
+ itp('handles empty string', function()
+ eq('', reverse_text(''))
end)
- itp("handles simple cases", function()
- eq("a", reverse_text("a"))
- eq("ba", reverse_text("ab"))
+ 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"))
+ 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"))
+ 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"))
+ 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"))
+ itp('treats an incomplete utf continuation sequence as valid', function()
+ eq('\194ba', reverse_text('ab\194'))
end)
end)
diff --git a/test/unit/undo_spec.lua b/test/unit/undo_spec.lua
index ee4203b94c..0e2f38a8c8 100644
--- a/test/unit/undo_spec.lua
+++ b/test/unit/undo_spec.lua
@@ -1,8 +1,8 @@
local helpers = require('test.unit.helpers')(after_each)
local itp = helpers.gen_itp(it)
-local luv = require('luv')
+local uv = vim.uv
local child_call_once = helpers.child_call_once
-local sleep = helpers.sleep
+local sleep = uv.sleep
local ffi = helpers.ffi
local cimport = helpers.cimport
@@ -23,7 +23,7 @@ local buffer_hash = nil
child_call_once(function()
if old_p_udir == nil then
- old_p_udir = options.p_udir -- save the old value of p_udir (undodir)
+ old_p_udir = options.p_udir -- save the old value of p_udir (undodir)
end
-- create a new buffer
@@ -39,21 +39,20 @@ child_call_once(function()
undo.u_compute_hash(file_buffer, buffer_hash)
end)
-
describe('u_write_undo', function()
setup(function()
mkdir('unit-test-directory')
- luv.chdir('unit-test-directory')
- options.p_udir = to_cstr(luv.cwd()) -- set p_udir to be the test dir
+ uv.chdir('unit-test-directory')
+ options.p_udir = to_cstr(uv.cwd()) -- set p_udir to be the test dir
end)
teardown(function()
- luv.chdir('..')
- local success, err = luv.fs_rmdir('unit-test-directory')
+ uv.chdir('..')
+ local success, err = uv.fs_rmdir('unit-test-directory')
if not success then
- print(err) -- inform tester if directory fails to delete
+ print(err) -- inform tester if directory fails to delete
end
- options.p_udir = old_p_udir --restore old p_udir
+ options.p_udir = old_p_udir --restore old p_udir
end)
-- Lua wrapper for u_write_undo
@@ -68,24 +67,24 @@ describe('u_write_undo', function()
itp('writes an undo file to undodir given a buffer and hash', 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 undo_file = io.open(correct_name, "r")
+ local undo_file = io.open(correct_name, 'r')
neq(undo_file, nil)
- local success, err = os.remove(correct_name) -- delete the file now that we're done with it.
+ local success, err = os.remove(correct_name) -- delete the file now that we're done with it.
if not success then
- print(err) -- inform tester if undofile fails to delete
+ print(err) -- inform tester if undofile fails to delete
end
end)
itp('writes a correctly-named undo file to undodir given a name, buffer, and hash', function()
- local correct_name = "undofile.test"
+ local correct_name = 'undofile.test'
u_write_undo(correct_name, false, file_buffer, buffer_hash)
- local undo_file = io.open(correct_name, "r")
+ local undo_file = io.open(correct_name, 'r')
neq(undo_file, nil)
- local success, err = os.remove(correct_name) -- delete the file now that we're done with it.
+ local success, err = os.remove(correct_name) -- delete the file now that we're done with it.
if not success then
- print(err) -- inform tester if undofile fails to delete
+ print(err) -- inform tester if undofile fails to delete
end
end)
@@ -96,11 +95,11 @@ describe('u_write_undo', function()
itp('writes the undofile with the same permissions as the original file', function()
-- Create Test file and set permissions
- local test_file_name = "./test.file"
- local test_permission_file = io.open(test_file_name, "w")
- test_permission_file:write("testing permissions")
+ local test_file_name = './test.file'
+ local test_permission_file = io.open(test_file_name, 'w')
+ test_permission_file:write('testing permissions')
test_permission_file:close()
- local test_permissions = luv.fs_stat(test_file_name).mode
+ local test_permissions = uv.fs_stat(test_file_name).mode
-- Create vim buffer
local c_file = to_cstr(test_file_name)
@@ -113,23 +112,23 @@ 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 = luv.fs_stat(undo_file_name).mode
+ local permissions = uv.fs_stat(undo_file_name).mode
eq(test_permissions, permissions)
-- delete the file now that we're done with it.
local success, err = os.remove(test_file_name)
if not success then
- print(err) -- inform tester if undofile fails to delete
+ print(err) -- inform tester if undofile fails to delete
end
success, err = os.remove(undo_file_name)
if not success then
- print(err) -- inform tester if undofile fails to delete
+ print(err) -- inform tester if undofile fails to delete
end
end)
itp('writes an undofile only readable by the user if the buffer is unnamed', function()
local correct_permissions = 33152
- local undo_file_name = "test.undo"
+ local undo_file_name = 'test.undo'
-- Create vim buffer
file_buffer = buffer.buflist_new(nil, nil, 1, buffer.BLN_LISTED)
@@ -138,18 +137,18 @@ 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 = luv.fs_stat(undo_file_name).mode
+ local permissions = uv.fs_stat(undo_file_name).mode
eq(correct_permissions, permissions)
-- delete the file now that we're done with it.
local success, err = os.remove(undo_file_name)
if not success then
- print(err) -- inform tester if undofile fails to delete
+ print(err) -- inform tester if undofile fails to delete
end
end)
itp('forces writing undo file for :wundo! command', function()
- local file_contents = "testing permissions"
+ local file_contents = 'testing permissions'
-- Write a text file where the undofile should go
local correct_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false))
helpers.write_file(correct_name, file_contents, true, false)
@@ -160,9 +159,9 @@ describe('u_write_undo', function()
local undo_file_contents = helpers.read_file(correct_name)
neq(file_contents, undo_file_contents)
- local success, deletion_err = os.remove(correct_name) -- delete the file now that we're done with it.
+ local success, deletion_err = os.remove(correct_name) -- delete the file now that we're done with it.
if not success then
- print(deletion_err) -- inform tester if undofile fails to delete
+ print(deletion_err) -- inform tester if undofile fails to delete
end
end)
@@ -170,19 +169,19 @@ 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 = luv.fs_stat(correct_name).mtime.sec
+ local file_last_modified = uv.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
+ 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 = luv.fs_stat(correct_name).mtime.sec
+ local file_last_modified_2 = uv.fs_stat(correct_name).mtime.sec
-- print(file_last_modified, file_last_modified_2)
neq(file_last_modified, file_last_modified_2)
- local success, err = os.remove(correct_name) -- delete the file now that we're done with it.
+ local success, err = os.remove(correct_name) -- delete the file now that we're done with it.
if not success then
- print(err) -- inform tester if undofile fails to delete
+ print(err) -- inform tester if undofile fails to delete
end
end)
@@ -195,16 +194,16 @@ describe('u_write_undo', function()
end)
itp('does not write an undo file if there is no undo information for the buffer', function()
- file_buffer.b_u_numhead = 0 -- Mark it as if there is no undo information
+ file_buffer.b_u_numhead = 0 -- Mark it as if there is no undo information
local correct_name = ffi.string(undo.u_get_undo_file_name(file_buffer.b_ffname, false))
- local existing_file = io.open(correct_name,"r")
+ local existing_file = io.open(correct_name, 'r')
if existing_file then
existing_file:close()
os.remove(correct_name)
end
u_write_undo(nil, false, file_buffer, buffer_hash)
- local undo_file = io.open(correct_name, "r")
+ local undo_file = io.open(correct_name, 'r')
eq(undo_file, nil)
end)
diff --git a/test/unit/viml/expressions/lexer_spec.lua b/test/unit/viml/expressions/lexer_spec.lua
index 358e858d61..96052a5ce1 100644
--- a/test/unit/viml/expressions/lexer_spec.lua
+++ b/test/unit/viml/expressions/lexer_spec.lua
@@ -83,24 +83,23 @@ local function eltkn2lua(pstate, tkn)
type = conv_eltkn_type(tkn.type),
}
pstate_set_str(pstate, tkn.start, tkn.len, ret)
- if not ret.error and (#(ret.str) ~= ret.len) then
+ if not ret.error and (#ret.str ~= ret.len) then
ret.error = '#str /= len'
end
if ret.type == 'Comparison' then
ret.data = {
type = conv_cmp_type(tkn.data.cmp.type),
ccs = conv_ccs(tkn.data.cmp.ccs),
- inv = (not not tkn.data.cmp.inv),
+ inv = not not tkn.data.cmp.inv,
}
elseif ret.type == 'Multiplication' then
ret.data = { type = conv_enum(eltkn_mul_type_tab, tkn.data.mul.type) }
elseif bracket_types[ret.type] then
- ret.data = { closing = (not not tkn.data.brc.closing) }
+ ret.data = { closing = not not tkn.data.brc.closing }
elseif ret.type == 'Register' then
ret.data = { name = intchar2lua(tkn.data.reg.name) }
- elseif (ret.type == 'SingleQuotedString'
- or ret.type == 'DoubleQuotedString') then
- ret.data = { closed = (not not tkn.data.str.closed) }
+ elseif ret.type == 'SingleQuotedString' or ret.type == 'DoubleQuotedString' then
+ ret.data = { closed = not not tkn.data.str.closed }
elseif ret.type == 'Option' then
ret.data = {
scope = conv_enum(eltkn_opt_scope_tab, tkn.data.opt.scope),
@@ -109,16 +108,15 @@ local function eltkn2lua(pstate, tkn)
elseif ret.type == 'PlainIdentifier' then
ret.data = {
scope = intchar2lua(tkn.data.var.scope),
- autoload = (not not tkn.data.var.autoload),
+ autoload = not not tkn.data.var.autoload,
}
elseif ret.type == 'Number' then
ret.data = {
- is_float = (not not tkn.data.num.is_float),
+ is_float = not not tkn.data.num.is_float,
base = tonumber(tkn.data.num.base),
}
- ret.data.val = tonumber(tkn.data.num.is_float
- and tkn.data.num.val.floating
- or tkn.data.num.val.integer)
+ ret.data.val =
+ tonumber(tkn.data.num.is_float and tkn.data.num.val.floating or tkn.data.num.val.integer)
elseif ret.type == 'Assignment' then
ret.data = { type = conv_expr_asgn_type(tkn.data.ass.type) }
elseif ret.type == 'Invalid' then
@@ -150,156 +148,263 @@ describe('Expressions lexer', function()
end
end
local function singl_eltkn_test(typ, str, data)
- local pstate = new_pstate({str})
- eq({data=data, len=#str, start={col=0, line=0}, str=str, type=typ},
- next_eltkn(pstate, flags))
+ local pstate = new_pstate({ str })
+ eq(
+ { data = data, len = #str, start = { col = 0, line = 0 }, str = str, type = typ },
+ next_eltkn(pstate, flags)
+ )
check_advance(pstate, #str, 0)
- if not (
+ if
+ not (
typ == 'Spacing'
or (typ == 'Register' and str == '@')
- or ((typ == 'SingleQuotedString' or typ == 'DoubleQuotedString')
- and not data.closed)
- ) then
- pstate = new_pstate({str .. ' '})
- eq({data=data, len=#str, start={col=0, line=0}, str=str, type=typ},
- next_eltkn(pstate, flags))
+ or ((typ == 'SingleQuotedString' or typ == 'DoubleQuotedString') and not data.closed)
+ )
+ then
+ pstate = new_pstate({ str .. ' ' })
+ eq(
+ { data = data, len = #str, start = { col = 0, line = 0 }, str = str, type = typ },
+ next_eltkn(pstate, flags)
+ )
check_advance(pstate, #str, 0)
end
- pstate = new_pstate({'x' .. str})
+ pstate = new_pstate({ 'x' .. str })
pstate.pos.col = 1
- eq({data=data, len=#str, start={col=1, line=0}, str=str, type=typ},
- next_eltkn(pstate, flags))
+ eq(
+ { data = data, len = #str, start = { col = 1, line = 0 }, str = str, type = typ },
+ next_eltkn(pstate, flags)
+ )
check_advance(pstate, #str, 1)
end
local function scope_test(scope)
- singl_eltkn_test('PlainIdentifier', scope .. ':test#var', {autoload=true, scope=scope})
- singl_eltkn_test('PlainIdentifier', scope .. ':', {autoload=false, scope=scope})
+ singl_eltkn_test('PlainIdentifier', scope .. ':test#var', { autoload = true, scope = scope })
+ singl_eltkn_test('PlainIdentifier', scope .. ':', { autoload = false, scope = scope })
end
local function comparison_test(op, inv_op, cmp_type)
- singl_eltkn_test('Comparison', op, {type=cmp_type, inv=false, ccs='UseOption'})
- singl_eltkn_test('Comparison', inv_op, {type=cmp_type, inv=true, ccs='UseOption'})
- singl_eltkn_test('Comparison', op .. '#', {type=cmp_type, inv=false, ccs='MatchCase'})
- singl_eltkn_test('Comparison', inv_op .. '#', {type=cmp_type, inv=true, ccs='MatchCase'})
- singl_eltkn_test('Comparison', op .. '?', {type=cmp_type, inv=false, ccs='IgnoreCase'})
- singl_eltkn_test('Comparison', inv_op .. '?', {type=cmp_type, inv=true, ccs='IgnoreCase'})
+ singl_eltkn_test('Comparison', op, { type = cmp_type, inv = false, ccs = 'UseOption' })
+ singl_eltkn_test('Comparison', inv_op, { type = cmp_type, inv = true, ccs = 'UseOption' })
+ singl_eltkn_test('Comparison', op .. '#', { type = cmp_type, inv = false, ccs = 'MatchCase' })
+ singl_eltkn_test(
+ 'Comparison',
+ inv_op .. '#',
+ { type = cmp_type, inv = true, ccs = 'MatchCase' }
+ )
+ singl_eltkn_test('Comparison', op .. '?', { type = cmp_type, inv = false, ccs = 'IgnoreCase' })
+ singl_eltkn_test(
+ 'Comparison',
+ inv_op .. '?',
+ { type = cmp_type, inv = true, ccs = 'IgnoreCase' }
+ )
end
local function simple_test(pstate_arg, exp_type, exp_len, exp)
local pstate = new_pstate(pstate_arg)
exp = shallowcopy(exp)
exp.type = exp_type
- exp.len = exp_len or #(pstate_arg[0])
+ exp.len = exp_len or #pstate_arg[0]
exp.start = { col = 0, line = 0 }
eq(exp, next_eltkn(pstate, flags))
end
local function stable_tests()
- singl_eltkn_test('Parenthesis', '(', {closing=false})
- singl_eltkn_test('Parenthesis', ')', {closing=true})
- singl_eltkn_test('Bracket', '[', {closing=false})
- singl_eltkn_test('Bracket', ']', {closing=true})
- singl_eltkn_test('FigureBrace', '{', {closing=false})
- singl_eltkn_test('FigureBrace', '}', {closing=true})
+ singl_eltkn_test('Parenthesis', '(', { closing = false })
+ singl_eltkn_test('Parenthesis', ')', { closing = true })
+ singl_eltkn_test('Bracket', '[', { closing = false })
+ singl_eltkn_test('Bracket', ']', { closing = true })
+ singl_eltkn_test('FigureBrace', '{', { closing = false })
+ singl_eltkn_test('FigureBrace', '}', { closing = true })
singl_eltkn_test('Question', '?')
singl_eltkn_test('Colon', ':')
singl_eltkn_test('Dot', '.')
- singl_eltkn_test('Assignment', '.=', {type='Concat'})
+ singl_eltkn_test('Assignment', '.=', { type = 'Concat' })
singl_eltkn_test('Plus', '+')
- singl_eltkn_test('Assignment', '+=', {type='Add'})
+ singl_eltkn_test('Assignment', '+=', { type = 'Add' })
singl_eltkn_test('Comma', ',')
- singl_eltkn_test('Multiplication', '*', {type='Mul'})
- singl_eltkn_test('Multiplication', '/', {type='Div'})
- singl_eltkn_test('Multiplication', '%', {type='Mod'})
+ singl_eltkn_test('Multiplication', '*', { type = 'Mul' })
+ singl_eltkn_test('Multiplication', '/', { type = 'Div' })
+ singl_eltkn_test('Multiplication', '%', { type = 'Mod' })
singl_eltkn_test('Spacing', ' \t\t \t\t')
singl_eltkn_test('Spacing', ' ')
singl_eltkn_test('Spacing', '\t')
- singl_eltkn_test('Invalid', '\x01\x02\x03', {error='E15: Invalid control character present in input: %.*s'})
- singl_eltkn_test('Number', '0123', {is_float=false, base=8, val=83})
- singl_eltkn_test('Number', '01234567', {is_float=false, base=8, val=342391})
- singl_eltkn_test('Number', '012345678', {is_float=false, base=10, val=12345678})
- singl_eltkn_test('Number', '0x123', {is_float=false, base=16, val=291})
- singl_eltkn_test('Number', '0x56FF', {is_float=false, base=16, val=22271})
- singl_eltkn_test('Number', '0xabcdef', {is_float=false, base=16, val=11259375})
- singl_eltkn_test('Number', '0xABCDEF', {is_float=false, base=16, val=11259375})
- singl_eltkn_test('Number', '0x0', {is_float=false, base=16, val=0})
- singl_eltkn_test('Number', '00', {is_float=false, base=8, val=0})
- singl_eltkn_test('Number', '0b0', {is_float=false, base=2, val=0})
- singl_eltkn_test('Number', '0b010111', {is_float=false, base=2, val=23})
- singl_eltkn_test('Number', '0b100111', {is_float=false, base=2, val=39})
- singl_eltkn_test('Number', '0', {is_float=false, base=10, val=0})
- singl_eltkn_test('Number', '9', {is_float=false, base=10, val=9})
+ singl_eltkn_test(
+ 'Invalid',
+ '\x01\x02\x03',
+ { error = 'E15: Invalid control character present in input: %.*s' }
+ )
+ singl_eltkn_test('Number', '0123', { is_float = false, base = 8, val = 83 })
+ singl_eltkn_test('Number', '01234567', { is_float = false, base = 8, val = 342391 })
+ singl_eltkn_test('Number', '012345678', { is_float = false, base = 10, val = 12345678 })
+ singl_eltkn_test('Number', '0x123', { is_float = false, base = 16, val = 291 })
+ singl_eltkn_test('Number', '0x56FF', { is_float = false, base = 16, val = 22271 })
+ singl_eltkn_test('Number', '0xabcdef', { is_float = false, base = 16, val = 11259375 })
+ singl_eltkn_test('Number', '0xABCDEF', { is_float = false, base = 16, val = 11259375 })
+ singl_eltkn_test('Number', '0x0', { is_float = false, base = 16, val = 0 })
+ singl_eltkn_test('Number', '00', { is_float = false, base = 8, val = 0 })
+ singl_eltkn_test('Number', '0b0', { is_float = false, base = 2, val = 0 })
+ singl_eltkn_test('Number', '0b010111', { is_float = false, base = 2, val = 23 })
+ singl_eltkn_test('Number', '0b100111', { is_float = false, base = 2, val = 39 })
+ singl_eltkn_test('Number', '0', { is_float = false, base = 10, val = 0 })
+ singl_eltkn_test('Number', '9', { is_float = false, base = 10, val = 9 })
singl_eltkn_test('Env', '$abc')
singl_eltkn_test('Env', '$')
- singl_eltkn_test('PlainIdentifier', 'test', {autoload=false, scope=0})
- singl_eltkn_test('PlainIdentifier', '_test', {autoload=false, scope=0})
- singl_eltkn_test('PlainIdentifier', '_test_foo', {autoload=false, scope=0})
- singl_eltkn_test('PlainIdentifier', 't', {autoload=false, scope=0})
- singl_eltkn_test('PlainIdentifier', 'test5', {autoload=false, scope=0})
- singl_eltkn_test('PlainIdentifier', 't0', {autoload=false, scope=0})
- singl_eltkn_test('PlainIdentifier', 'test#var', {autoload=true, scope=0})
- singl_eltkn_test('PlainIdentifier', 'test#var#val###', {autoload=true, scope=0})
- singl_eltkn_test('PlainIdentifier', 't#####', {autoload=true, scope=0})
+ singl_eltkn_test('PlainIdentifier', 'test', { autoload = false, scope = 0 })
+ singl_eltkn_test('PlainIdentifier', '_test', { autoload = false, scope = 0 })
+ singl_eltkn_test('PlainIdentifier', '_test_foo', { autoload = false, scope = 0 })
+ singl_eltkn_test('PlainIdentifier', 't', { autoload = false, scope = 0 })
+ singl_eltkn_test('PlainIdentifier', 'test5', { autoload = false, scope = 0 })
+ singl_eltkn_test('PlainIdentifier', 't0', { autoload = false, scope = 0 })
+ singl_eltkn_test('PlainIdentifier', 'test#var', { autoload = true, scope = 0 })
+ singl_eltkn_test('PlainIdentifier', 'test#var#val###', { autoload = true, scope = 0 })
+ singl_eltkn_test('PlainIdentifier', 't#####', { autoload = true, scope = 0 })
singl_eltkn_test('And', '&&')
singl_eltkn_test('Or', '||')
- singl_eltkn_test('Invalid', '&', {error='E112: Option name missing: %.*s'})
- singl_eltkn_test('Option', '&opt', {scope='Unspecified', name='opt'})
- singl_eltkn_test('Option', '&t_xx', {scope='Unspecified', name='t_xx'})
- singl_eltkn_test('Option', '&t_\r\r', {scope='Unspecified', name='t_\r\r'})
- singl_eltkn_test('Option', '&t_\t\t', {scope='Unspecified', name='t_\t\t'})
- singl_eltkn_test('Option', '&t_ ', {scope='Unspecified', name='t_ '})
- singl_eltkn_test('Option', '&g:opt', {scope='Global', name='opt'})
- singl_eltkn_test('Option', '&l:opt', {scope='Local', name='opt'})
- singl_eltkn_test('Invalid', '&l:', {error='E112: Option name missing: %.*s'})
- singl_eltkn_test('Invalid', '&g:', {error='E112: Option name missing: %.*s'})
- singl_eltkn_test('Register', '@', {name=-1})
- singl_eltkn_test('Register', '@a', {name='a'})
- singl_eltkn_test('Register', '@\r', {name=13})
- singl_eltkn_test('Register', '@ ', {name=' '})
- singl_eltkn_test('Register', '@\t', {name=9})
- singl_eltkn_test('SingleQuotedString', '\'test', {closed=false})
- singl_eltkn_test('SingleQuotedString', '\'test\'', {closed=true})
- singl_eltkn_test('SingleQuotedString', '\'\'\'\'', {closed=true})
- singl_eltkn_test('SingleQuotedString', '\'x\'\'\'', {closed=true})
- singl_eltkn_test('SingleQuotedString', '\'\'\'x\'', {closed=true})
- singl_eltkn_test('SingleQuotedString', '\'\'\'', {closed=false})
- singl_eltkn_test('SingleQuotedString', '\'x\'\'', {closed=false})
- singl_eltkn_test('SingleQuotedString', '\'\'\'x', {closed=false})
- singl_eltkn_test('DoubleQuotedString', '"test', {closed=false})
- singl_eltkn_test('DoubleQuotedString', '"test"', {closed=true})
- singl_eltkn_test('DoubleQuotedString', '"\\""', {closed=true})
- singl_eltkn_test('DoubleQuotedString', '"x\\""', {closed=true})
- singl_eltkn_test('DoubleQuotedString', '"\\"x"', {closed=true})
- singl_eltkn_test('DoubleQuotedString', '"\\"', {closed=false})
- singl_eltkn_test('DoubleQuotedString', '"x\\"', {closed=false})
- singl_eltkn_test('DoubleQuotedString', '"\\"x', {closed=false})
+ singl_eltkn_test('Invalid', '&', { error = 'E112: Option name missing: %.*s' })
+ singl_eltkn_test('Option', '&opt', { scope = 'Unspecified', name = 'opt' })
+ singl_eltkn_test('Option', '&t_xx', { scope = 'Unspecified', name = 't_xx' })
+ singl_eltkn_test('Option', '&t_\r\r', { scope = 'Unspecified', name = 't_\r\r' })
+ singl_eltkn_test('Option', '&t_\t\t', { scope = 'Unspecified', name = 't_\t\t' })
+ singl_eltkn_test('Option', '&t_ ', { scope = 'Unspecified', name = 't_ ' })
+ singl_eltkn_test('Option', '&g:opt', { scope = 'Global', name = 'opt' })
+ singl_eltkn_test('Option', '&l:opt', { scope = 'Local', name = 'opt' })
+ singl_eltkn_test('Invalid', '&l:', { error = 'E112: Option name missing: %.*s' })
+ singl_eltkn_test('Invalid', '&g:', { error = 'E112: Option name missing: %.*s' })
+ singl_eltkn_test('Register', '@', { name = -1 })
+ singl_eltkn_test('Register', '@a', { name = 'a' })
+ singl_eltkn_test('Register', '@\r', { name = 13 })
+ singl_eltkn_test('Register', '@ ', { name = ' ' })
+ singl_eltkn_test('Register', '@\t', { name = 9 })
+ singl_eltkn_test('SingleQuotedString', "'test", { closed = false })
+ singl_eltkn_test('SingleQuotedString', "'test'", { closed = true })
+ singl_eltkn_test('SingleQuotedString', "''''", { closed = true })
+ singl_eltkn_test('SingleQuotedString', "'x'''", { closed = true })
+ singl_eltkn_test('SingleQuotedString', "'''x'", { closed = true })
+ singl_eltkn_test('SingleQuotedString', "'''", { closed = false })
+ singl_eltkn_test('SingleQuotedString', "'x''", { closed = false })
+ singl_eltkn_test('SingleQuotedString', "'''x", { closed = false })
+ singl_eltkn_test('DoubleQuotedString', '"test', { closed = false })
+ singl_eltkn_test('DoubleQuotedString', '"test"', { closed = true })
+ singl_eltkn_test('DoubleQuotedString', '"\\""', { closed = true })
+ singl_eltkn_test('DoubleQuotedString', '"x\\""', { closed = true })
+ singl_eltkn_test('DoubleQuotedString', '"\\"x"', { closed = true })
+ singl_eltkn_test('DoubleQuotedString', '"\\"', { closed = false })
+ singl_eltkn_test('DoubleQuotedString', '"x\\"', { closed = false })
+ singl_eltkn_test('DoubleQuotedString', '"\\"x', { closed = false })
singl_eltkn_test('Not', '!')
- singl_eltkn_test('Assignment', '=', {type='Plain'})
+ singl_eltkn_test('Assignment', '=', { type = 'Plain' })
comparison_test('==', '!=', 'Equal')
comparison_test('=~', '!~', 'Matches')
comparison_test('>', '<=', 'Greater')
comparison_test('>=', '<', 'GreaterOrEqual')
singl_eltkn_test('Minus', '-')
- singl_eltkn_test('Assignment', '-=', {type='Subtract'})
+ singl_eltkn_test('Assignment', '-=', { type = 'Subtract' })
singl_eltkn_test('Arrow', '->')
- singl_eltkn_test('Invalid', '~', {error='E15: Unidentified character: %.*s'})
- simple_test({{data=nil, size=0}}, 'EOC', 0, {error='start.col >= #pstr'})
- simple_test({''}, 'EOC', 0, {error='start.col >= #pstr'})
- simple_test({'2.'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2e5'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.x'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.2.'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0x'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e+'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e-'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e+x'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e-x'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e+1a'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e-1a'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'0b102'}, 'Number', 4, {data={is_float=false, base=2, val=2}, str='0b10'})
- simple_test({'10F'}, 'Number', 2, {data={is_float=false, base=10, val=10}, str='10'})
- simple_test({'0x0123456789ABCDEFG'}, 'Number', 18, {data={is_float=false, base=16, val=81985529216486895}, str='0x0123456789ABCDEF'})
- simple_test({{data='00', size=2}}, 'Number', 2, {data={is_float=false, base=8, val=0}, str='00'})
- simple_test({{data='009', size=2}}, 'Number', 2, {data={is_float=false, base=8, val=0}, str='00'})
- simple_test({{data='01', size=1}}, 'Number', 1, {data={is_float=false, base=10, val=0}, str='0'})
+ singl_eltkn_test('Invalid', '~', { error = 'E15: Unidentified character: %.*s' })
+ simple_test({ { data = nil, size = 0 } }, 'EOC', 0, { error = 'start.col >= #pstr' })
+ simple_test({ '' }, 'EOC', 0, { error = 'start.col >= #pstr' })
+ simple_test(
+ { '2.' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2e5' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.x' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.2.' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0x' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e+' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e-' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e+x' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e-x' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e+1a' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e-1a' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '0b102' },
+ 'Number',
+ 4,
+ { data = { is_float = false, base = 2, val = 2 }, str = '0b10' }
+ )
+ simple_test(
+ { '10F' },
+ 'Number',
+ 2,
+ { data = { is_float = false, base = 10, val = 10 }, str = '10' }
+ )
+ simple_test({ '0x0123456789ABCDEFG' }, 'Number', 18, {
+ data = { is_float = false, base = 16, val = 81985529216486895 },
+ str = '0x0123456789ABCDEF',
+ })
+ simple_test(
+ { { data = '00', size = 2 } },
+ 'Number',
+ 2,
+ { data = { is_float = false, base = 8, val = 0 }, str = '00' }
+ )
+ simple_test(
+ { { data = '009', size = 2 } },
+ 'Number',
+ 2,
+ { data = { is_float = false, base = 8, val = 0 }, str = '00' }
+ )
+ simple_test(
+ { { data = '01', size = 1 } },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 0 }, str = '0' }
+ )
end
local function regular_scope_tests()
@@ -312,29 +417,104 @@ describe('Expressions lexer', function()
scope_test('l')
scope_test('a')
- simple_test({'g:'}, 'PlainIdentifier', 2, {data={scope='g', autoload=false}, str='g:'})
- simple_test({'g:is#foo'}, 'PlainIdentifier', 8, {data={scope='g', autoload=true}, str='g:is#foo'})
- simple_test({'g:isnot#foo'}, 'PlainIdentifier', 11, {data={scope='g', autoload=true}, str='g:isnot#foo'})
+ simple_test(
+ { 'g:' },
+ 'PlainIdentifier',
+ 2,
+ { data = { scope = 'g', autoload = false }, str = 'g:' }
+ )
+ simple_test(
+ { 'g:is#foo' },
+ 'PlainIdentifier',
+ 8,
+ { data = { scope = 'g', autoload = true }, str = 'g:is#foo' }
+ )
+ simple_test(
+ { 'g:isnot#foo' },
+ 'PlainIdentifier',
+ 11,
+ { data = { scope = 'g', autoload = true }, str = 'g:isnot#foo' }
+ )
end
local function regular_is_tests()
comparison_test('is', 'isnot', 'Identical')
- simple_test({'is'}, 'Comparison', 2, {data={type='Identical', inv=false, ccs='UseOption'}, str='is'})
- simple_test({'isnot'}, 'Comparison', 5, {data={type='Identical', inv=true, ccs='UseOption'}, str='isnot'})
- simple_test({'is?'}, 'Comparison', 3, {data={type='Identical', inv=false, ccs='IgnoreCase'}, str='is?'})
- simple_test({'isnot?'}, 'Comparison', 6, {data={type='Identical', inv=true, ccs='IgnoreCase'}, str='isnot?'})
- simple_test({'is#'}, 'Comparison', 3, {data={type='Identical', inv=false, ccs='MatchCase'}, str='is#'})
- simple_test({'isnot#'}, 'Comparison', 6, {data={type='Identical', inv=true, ccs='MatchCase'}, str='isnot#'})
- simple_test({'is#foo'}, 'Comparison', 3, {data={type='Identical', inv=false, ccs='MatchCase'}, str='is#'})
- simple_test({'isnot#foo'}, 'Comparison', 6, {data={type='Identical', inv=true, ccs='MatchCase'}, str='isnot#'})
+ simple_test(
+ { 'is' },
+ 'Comparison',
+ 2,
+ { data = { type = 'Identical', inv = false, ccs = 'UseOption' }, str = 'is' }
+ )
+ simple_test(
+ { 'isnot' },
+ 'Comparison',
+ 5,
+ { data = { type = 'Identical', inv = true, ccs = 'UseOption' }, str = 'isnot' }
+ )
+ simple_test(
+ { 'is?' },
+ 'Comparison',
+ 3,
+ { data = { type = 'Identical', inv = false, ccs = 'IgnoreCase' }, str = 'is?' }
+ )
+ simple_test(
+ { 'isnot?' },
+ 'Comparison',
+ 6,
+ { data = { type = 'Identical', inv = true, ccs = 'IgnoreCase' }, str = 'isnot?' }
+ )
+ simple_test(
+ { 'is#' },
+ 'Comparison',
+ 3,
+ { data = { type = 'Identical', inv = false, ccs = 'MatchCase' }, str = 'is#' }
+ )
+ simple_test(
+ { 'isnot#' },
+ 'Comparison',
+ 6,
+ { data = { type = 'Identical', inv = true, ccs = 'MatchCase' }, str = 'isnot#' }
+ )
+ simple_test(
+ { 'is#foo' },
+ 'Comparison',
+ 3,
+ { data = { type = 'Identical', inv = false, ccs = 'MatchCase' }, str = 'is#' }
+ )
+ simple_test(
+ { 'isnot#foo' },
+ 'Comparison',
+ 6,
+ { data = { type = 'Identical', inv = true, ccs = 'MatchCase' }, str = 'isnot#' }
+ )
end
local function regular_number_tests()
- simple_test({'2.0'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e5'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e+5'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({'2.0e-5'}, 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
+ simple_test(
+ { '2.0' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e5' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e+5' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { '2.0e-5' },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
end
local function regular_eoc_tests()
@@ -369,7 +549,12 @@ describe('Expressions lexer', function()
regular_is_tests()
regular_number_tests()
- simple_test({'g:'}, 'PlainIdentifier', 1, {data={scope=0, autoload=false}, str='g'})
+ simple_test(
+ { 'g:' },
+ 'PlainIdentifier',
+ 1,
+ { data = { scope = 0, autoload = false }, str = 'g' }
+ )
end)
itp('allows floats', function()
flags = tonumber(lib.kELFlagAllowFloat)
@@ -379,20 +564,72 @@ describe('Expressions lexer', function()
regular_scope_tests()
regular_is_tests()
- simple_test({'2.2'}, 'Number', 3, {data={is_float=true, base=10, val=2.2}, str='2.2'})
- simple_test({'2.0e5'}, 'Number', 5, {data={is_float=true, base=10, val=2e5}, str='2.0e5'})
- simple_test({'2.0e+5'}, 'Number', 6, {data={is_float=true, base=10, val=2e5}, str='2.0e+5'})
- simple_test({'2.0e-5'}, 'Number', 6, {data={is_float=true, base=10, val=2e-5}, str='2.0e-5'})
- simple_test({'2.500000e-5'}, 'Number', 11, {data={is_float=true, base=10, val=2.5e-5}, str='2.500000e-5'})
- simple_test({'2.5555e2'}, 'Number', 8, {data={is_float=true, base=10, val=2.5555e2}, str='2.5555e2'})
- simple_test({'2.5555e+2'}, 'Number', 9, {data={is_float=true, base=10, val=2.5555e2}, str='2.5555e+2'})
- simple_test({'2.5555e-2'}, 'Number', 9, {data={is_float=true, base=10, val=2.5555e-2}, str='2.5555e-2'})
- simple_test({{data='2.5e-5', size=3}},
- 'Number', 3, {data={is_float=true, base=10, val=2.5}, str='2.5'})
- simple_test({{data='2.5e5', size=4}},
- 'Number', 1, {data={is_float=false, base=10, val=2}, str='2'})
- simple_test({{data='2.5e-50', size=6}},
- 'Number', 6, {data={is_float=true, base=10, val=2.5e-5}, str='2.5e-5'})
+ simple_test(
+ { '2.2' },
+ 'Number',
+ 3,
+ { data = { is_float = true, base = 10, val = 2.2 }, str = '2.2' }
+ )
+ simple_test(
+ { '2.0e5' },
+ 'Number',
+ 5,
+ { data = { is_float = true, base = 10, val = 2e5 }, str = '2.0e5' }
+ )
+ simple_test(
+ { '2.0e+5' },
+ 'Number',
+ 6,
+ { data = { is_float = true, base = 10, val = 2e5 }, str = '2.0e+5' }
+ )
+ simple_test(
+ { '2.0e-5' },
+ 'Number',
+ 6,
+ { data = { is_float = true, base = 10, val = 2e-5 }, str = '2.0e-5' }
+ )
+ simple_test(
+ { '2.500000e-5' },
+ 'Number',
+ 11,
+ { data = { is_float = true, base = 10, val = 2.5e-5 }, str = '2.500000e-5' }
+ )
+ simple_test(
+ { '2.5555e2' },
+ 'Number',
+ 8,
+ { data = { is_float = true, base = 10, val = 2.5555e2 }, str = '2.5555e2' }
+ )
+ simple_test(
+ { '2.5555e+2' },
+ 'Number',
+ 9,
+ { data = { is_float = true, base = 10, val = 2.5555e2 }, str = '2.5555e+2' }
+ )
+ simple_test(
+ { '2.5555e-2' },
+ 'Number',
+ 9,
+ { data = { is_float = true, base = 10, val = 2.5555e-2 }, str = '2.5555e-2' }
+ )
+ simple_test(
+ { { data = '2.5e-5', size = 3 } },
+ 'Number',
+ 3,
+ { data = { is_float = true, base = 10, val = 2.5 }, str = '2.5' }
+ )
+ simple_test(
+ { { data = '2.5e5', size = 4 } },
+ 'Number',
+ 1,
+ { data = { is_float = false, base = 10, val = 2 }, str = '2' }
+ )
+ simple_test(
+ { { data = '2.5e-50', size = 6 } },
+ 'Number',
+ 6,
+ { data = { is_float = true, base = 10, val = 2.5e-5 }, str = '2.5e-5' }
+ )
end)
itp('treats `is` as an identifier', function()
flags = tonumber(lib.kELFlagIsNotCmp)
@@ -402,14 +639,54 @@ describe('Expressions lexer', function()
regular_scope_tests()
regular_number_tests()
- simple_test({'is'}, 'PlainIdentifier', 2, {data={scope=0, autoload=false}, str='is'})
- simple_test({'isnot'}, 'PlainIdentifier', 5, {data={scope=0, autoload=false}, str='isnot'})
- simple_test({'is?'}, 'PlainIdentifier', 2, {data={scope=0, autoload=false}, str='is'})
- simple_test({'isnot?'}, 'PlainIdentifier', 5, {data={scope=0, autoload=false}, str='isnot'})
- simple_test({'is#'}, 'PlainIdentifier', 3, {data={scope=0, autoload=true}, str='is#'})
- simple_test({'isnot#'}, 'PlainIdentifier', 6, {data={scope=0, autoload=true}, str='isnot#'})
- simple_test({'is#foo'}, 'PlainIdentifier', 6, {data={scope=0, autoload=true}, str='is#foo'})
- simple_test({'isnot#foo'}, 'PlainIdentifier', 9, {data={scope=0, autoload=true}, str='isnot#foo'})
+ simple_test(
+ { 'is' },
+ 'PlainIdentifier',
+ 2,
+ { data = { scope = 0, autoload = false }, str = 'is' }
+ )
+ simple_test(
+ { 'isnot' },
+ 'PlainIdentifier',
+ 5,
+ { data = { scope = 0, autoload = false }, str = 'isnot' }
+ )
+ simple_test(
+ { 'is?' },
+ 'PlainIdentifier',
+ 2,
+ { data = { scope = 0, autoload = false }, str = 'is' }
+ )
+ simple_test(
+ { 'isnot?' },
+ 'PlainIdentifier',
+ 5,
+ { data = { scope = 0, autoload = false }, str = 'isnot' }
+ )
+ simple_test(
+ { 'is#' },
+ 'PlainIdentifier',
+ 3,
+ { data = { scope = 0, autoload = true }, str = 'is#' }
+ )
+ simple_test(
+ { 'isnot#' },
+ 'PlainIdentifier',
+ 6,
+ { data = { scope = 0, autoload = true }, str = 'isnot#' }
+ )
+ simple_test(
+ { 'is#foo' },
+ 'PlainIdentifier',
+ 6,
+ { data = { scope = 0, autoload = true }, str = 'is#foo' }
+ )
+ simple_test(
+ { 'isnot#foo' },
+ 'PlainIdentifier',
+ 9,
+ { data = { scope = 0, autoload = true }, str = 'isnot#foo' }
+ )
end)
itp('forbids EOC', function()
flags = tonumber(lib.kELFlagForbidEOC)
@@ -419,8 +696,8 @@ describe('Expressions lexer', function()
regular_is_tests()
regular_number_tests()
- singl_eltkn_test('Invalid', '|', {error='E15: Unexpected EOC character: %.*s'})
- singl_eltkn_test('Invalid', '\0', {error='E15: Unexpected EOC character: %.*s'})
- singl_eltkn_test('Invalid', '\n', {error='E15: Unexpected EOC character: %.*s'})
+ singl_eltkn_test('Invalid', '|', { error = 'E15: Unexpected EOC character: %.*s' })
+ singl_eltkn_test('Invalid', '\0', { error = 'E15: Unexpected EOC character: %.*s' })
+ singl_eltkn_test('Invalid', '\n', { error = 'E15: Unexpected EOC character: %.*s' })
end)
end)
diff --git a/test/unit/viml/expressions/parser_spec.lua b/test/unit/viml/expressions/parser_spec.lua
index 51a703b593..c7d3f8532f 100644
--- a/test/unit/viml/expressions/parser_spec.lua
+++ b/test/unit/viml/expressions/parser_spec.lua
@@ -14,8 +14,8 @@ local ffi = helpers.ffi
local neq = helpers.neq
local eq = helpers.eq
local mergedicts_copy = helpers.mergedicts_copy
-local format_string = helpers.format_string
-local format_luav = helpers.format_luav
+local format_string = require('test.format_string').format_string
+local format_luav = require('test.format_string').format_luav
local intchar2lua = helpers.intchar2lua
local dictdiff = helpers.dictdiff
@@ -25,100 +25,99 @@ local conv_cmp_type = viml_helpers.conv_cmp_type
local pstate_set_str = viml_helpers.pstate_set_str
local conv_expr_asgn_type = viml_helpers.conv_expr_asgn_type
-local lib = cimport('./src/nvim/viml/parser/expressions.h',
- './src/nvim/syntax.h')
+local lib = cimport('./src/nvim/viml/parser/expressions.h', './src/nvim/syntax.h')
local alloc_log = alloc_log_new()
local predefined_hl_defs = {
-- From highlight_init_both
- Conceal=true,
- Cursor=true,
- lCursor=true,
- DiffText=true,
- ErrorMsg=true,
- IncSearch=true,
- ModeMsg=true,
- NonText=true,
- PmenuSbar=true,
- StatusLine=true,
- StatusLineNC=true,
- TabLineFill=true,
- TabLineSel=true,
- TermCursor=true,
- VertSplit=true,
- WildMenu=true,
- WinSeparator=true,
- EndOfBuffer=true,
- QuickFixLine=true,
- Substitute=true,
- Whitespace=true,
- Error=true,
- Todo=true,
- String=true,
- Character=true,
- Number=true,
- Boolean=true,
- Float=true,
- Function=true,
- Conditional=true,
- Repeat=true,
- Label=true,
- Operator=true,
- Keyword=true,
- Exception=true,
- Include=true,
- Define=true,
- Macro=true,
- PreCondit=true,
- StorageClass=true,
- Structure=true,
- Typedef=true,
- Tag=true,
- SpecialChar=true,
- Delimiter=true,
- SpecialComment=true,
- Debug=true,
+ Conceal = true,
+ Cursor = true,
+ lCursor = true,
+ DiffText = true,
+ ErrorMsg = true,
+ IncSearch = true,
+ ModeMsg = true,
+ NonText = true,
+ PmenuSbar = true,
+ StatusLine = true,
+ StatusLineNC = true,
+ TabLineFill = true,
+ TabLineSel = true,
+ TermCursor = true,
+ VertSplit = true,
+ WildMenu = true,
+ WinSeparator = true,
+ EndOfBuffer = true,
+ QuickFixLine = true,
+ Substitute = true,
+ Whitespace = true,
+ Error = true,
+ Todo = true,
+ String = true,
+ Character = true,
+ Number = true,
+ Boolean = true,
+ Float = true,
+ Function = true,
+ Conditional = true,
+ Repeat = true,
+ Label = true,
+ Operator = true,
+ Keyword = true,
+ Exception = true,
+ Include = true,
+ Define = true,
+ Macro = true,
+ PreCondit = true,
+ StorageClass = true,
+ Structure = true,
+ Typedef = true,
+ Tag = true,
+ SpecialChar = true,
+ Delimiter = true,
+ SpecialComment = true,
+ Debug = true,
-- From highlight_init_(dark|light)
- ColorColumn=true,
- CursorColumn=true,
- CursorLine=true,
- CursorLineNr=true,
- DiffAdd=true,
- DiffChange=true,
- DiffDelete=true,
- Directory=true,
- FoldColumn=true,
- Folded=true,
- LineNr=true,
- MatchParen=true,
- MoreMsg=true,
- Pmenu=true,
- PmenuSel=true,
- PmenuThumb=true,
- Question=true,
- Search=true,
- SignColumn=true,
- SpecialKey=true,
- SpellBad=true,
- SpellCap=true,
- SpellLocal=true,
- SpellRare=true,
- TabLine=true,
- Title=true,
- Visual=true,
- WarningMsg=true,
- Normal=true,
- Comment=true,
- Constant=true,
- Special=true,
- Identifier=true,
- Statement=true,
- PreProc=true,
- Type=true,
- Underlined=true,
- Ignore=true,
+ ColorColumn = true,
+ CursorColumn = true,
+ CursorLine = true,
+ CursorLineNr = true,
+ DiffAdd = true,
+ DiffChange = true,
+ DiffDelete = true,
+ Directory = true,
+ FoldColumn = true,
+ Folded = true,
+ LineNr = true,
+ MatchParen = true,
+ MoreMsg = true,
+ Pmenu = true,
+ PmenuSel = true,
+ PmenuThumb = true,
+ Question = true,
+ Search = true,
+ SignColumn = true,
+ SpecialKey = true,
+ SpellBad = true,
+ SpellCap = true,
+ SpellLocal = true,
+ SpellRare = true,
+ TabLine = true,
+ Title = true,
+ Visual = true,
+ WarningMsg = true,
+ Normal = true,
+ Comment = true,
+ Constant = true,
+ Special = true,
+ Identifier = true,
+ Statement = true,
+ PreProc = true,
+ Type = true,
+ Underlined = true,
+ Ignore = true,
}
local nvim_hl_defs = {}
@@ -136,22 +135,18 @@ child_call_once(function()
-- linking, otherwise it will be created as cleared. So existence
-- of the group is checked here and not in the next pass over
-- nvim_hl_defs.
- eq(true, not not (nvim_hl_defs[grp_link]
- or predefined_hl_defs[grp_link]))
- eq(false, not not (nvim_hl_defs[new_grp]
- or predefined_hl_defs[new_grp]))
- nvim_hl_defs[new_grp] = {'link', grp_link}
+ eq(true, not not (nvim_hl_defs[grp_link] or predefined_hl_defs[grp_link]))
+ eq(false, not not (nvim_hl_defs[new_grp] or predefined_hl_defs[new_grp]))
+ nvim_hl_defs[new_grp] = { 'link', grp_link }
else
local new_grp, grp_args = s:match('^(%w+) (.*)')
neq(nil, new_grp)
- eq(false, not not (nvim_hl_defs[new_grp]
- or predefined_hl_defs[new_grp]))
- nvim_hl_defs[new_grp] = {'definition', grp_args}
+ eq(false, not not (nvim_hl_defs[new_grp] or predefined_hl_defs[new_grp]))
+ nvim_hl_defs[new_grp] = { 'definition', grp_args }
end
end)
if not err then
- msg = format_string(
- 'Error while processing string %s at position %u:\n%s', s, i, msg)
+ msg = format_string('Error while processing string %s at position %u:\n%s', s, i, msg)
error(msg)
end
i = i + 1
@@ -185,12 +180,12 @@ local function hls_to_hl_fs(hls)
local col_shift = col - next_col
assert(col_shift >= 0)
next_col = col + #str
- ret[i] = format_string('hl(%r, %r%s)',
- group,
- str,
- (col_shift == 0
- and ''
- or (', %u'):format(col_shift)))
+ ret[i] = format_string(
+ 'hl(%r, %r%s)',
+ group,
+ str,
+ (col_shift == 0 and '' or (', %u'):format(col_shift))
+ )
end
return ret
end
@@ -205,9 +200,9 @@ local function format_check(expr, format_check_data, opts)
dig_len = #opts.funcname + 2
else
print(format_string('\n_check_parsing(%r, %r, {', opts, expr))
- dig_len = #('_check_parsing(, \'') + #(format_string('%r', opts))
+ dig_len = #"_check_parsing(, '" + #(format_string('%r', opts))
end
- local digits = ' --' .. (' '):rep(dig_len - #(' --'))
+ local digits = ' --' .. (' '):rep(dig_len - #' --')
local digits2 = digits:sub(1, -10)
for i = 0, #expr - 1 do
if i % 10 == 0 then
@@ -240,10 +235,9 @@ local function format_check(expr, format_check_data, opts)
diffs[flags] = dictdiff(zdata, v)
if diffs[flags] then
if flags == 3 + zflags then
- if (dictdiff(format_check_data[1 + zflags],
- format_check_data[3 + zflags]) == nil
- or dictdiff(format_check_data[2 + zflags],
- format_check_data[3 + zflags]) == nil)
+ if
+ dictdiff(format_check_data[1 + zflags], format_check_data[3 + zflags]) == nil
+ or dictdiff(format_check_data[2 + zflags], format_check_data[3 + zflags]) == nil
then
diffs[flags] = nil
else
@@ -268,7 +262,7 @@ local function format_check(expr, format_check_data, opts)
end
if diff.hl_fs then
print(' hl_fs = ' .. format_luav(diff.hl_fs, ' ', {
- literal_strings=true
+ literal_strings = true,
}) .. ',')
end
print(' },')
@@ -280,47 +274,54 @@ local function format_check(expr, format_check_data, opts)
end
local east_node_type_tab
-make_enum_conv_tab(lib, {
- 'kExprNodeMissing',
- 'kExprNodeOpMissing',
- 'kExprNodeTernary',
- 'kExprNodeTernaryValue',
- 'kExprNodeRegister',
- 'kExprNodeSubscript',
- 'kExprNodeListLiteral',
- 'kExprNodeUnaryPlus',
- 'kExprNodeBinaryPlus',
- 'kExprNodeNested',
- 'kExprNodeCall',
- 'kExprNodePlainIdentifier',
- 'kExprNodePlainKey',
- 'kExprNodeComplexIdentifier',
- 'kExprNodeUnknownFigure',
- 'kExprNodeLambda',
- 'kExprNodeDictLiteral',
- 'kExprNodeCurlyBracesIdentifier',
- 'kExprNodeComma',
- 'kExprNodeColon',
- 'kExprNodeArrow',
- 'kExprNodeComparison',
- 'kExprNodeConcat',
- 'kExprNodeConcatOrSubscript',
- 'kExprNodeInteger',
- 'kExprNodeFloat',
- 'kExprNodeSingleQuotedString',
- 'kExprNodeDoubleQuotedString',
- 'kExprNodeOr',
- 'kExprNodeAnd',
- 'kExprNodeUnaryMinus',
- 'kExprNodeBinaryMinus',
- 'kExprNodeNot',
- 'kExprNodeMultiplication',
- 'kExprNodeDivision',
- 'kExprNodeMod',
- 'kExprNodeOption',
- 'kExprNodeEnvironment',
- 'kExprNodeAssignment',
-}, 'kExprNode', function(ret) east_node_type_tab = ret end)
+make_enum_conv_tab(
+ lib,
+ {
+ 'kExprNodeMissing',
+ 'kExprNodeOpMissing',
+ 'kExprNodeTernary',
+ 'kExprNodeTernaryValue',
+ 'kExprNodeRegister',
+ 'kExprNodeSubscript',
+ 'kExprNodeListLiteral',
+ 'kExprNodeUnaryPlus',
+ 'kExprNodeBinaryPlus',
+ 'kExprNodeNested',
+ 'kExprNodeCall',
+ 'kExprNodePlainIdentifier',
+ 'kExprNodePlainKey',
+ 'kExprNodeComplexIdentifier',
+ 'kExprNodeUnknownFigure',
+ 'kExprNodeLambda',
+ 'kExprNodeDictLiteral',
+ 'kExprNodeCurlyBracesIdentifier',
+ 'kExprNodeComma',
+ 'kExprNodeColon',
+ 'kExprNodeArrow',
+ 'kExprNodeComparison',
+ 'kExprNodeConcat',
+ 'kExprNodeConcatOrSubscript',
+ 'kExprNodeInteger',
+ 'kExprNodeFloat',
+ 'kExprNodeSingleQuotedString',
+ 'kExprNodeDoubleQuotedString',
+ 'kExprNodeOr',
+ 'kExprNodeAnd',
+ 'kExprNodeUnaryMinus',
+ 'kExprNodeBinaryMinus',
+ 'kExprNodeNot',
+ 'kExprNodeMultiplication',
+ 'kExprNodeDivision',
+ 'kExprNodeMod',
+ 'kExprNodeOption',
+ 'kExprNodeEnvironment',
+ 'kExprNodeAssignment',
+ },
+ 'kExprNode',
+ function(ret)
+ east_node_type_tab = ret
+ end
+)
local function conv_east_node_type(typ)
return conv_enum(east_node_type_tab, typ)
@@ -346,25 +347,35 @@ local function eastnode2lua(pstate, eastnode, checked_nodes)
ret_str = ('%u:%u:%s'):format(str.start.line, str.start.col, str.str)
end
if typ == 'Register' then
- typ = typ .. ('(name=%s)'):format(
- tostring(intchar2lua(eastnode.data.reg.name)))
+ typ = typ .. ('(name=%s)'):format(tostring(intchar2lua(eastnode.data.reg.name)))
elseif typ == 'PlainIdentifier' then
- typ = typ .. ('(scope=%s,ident=%s)'):format(
- tostring(intchar2lua(eastnode.data.var.scope)),
- ffi.string(eastnode.data.var.ident, eastnode.data.var.ident_len))
+ typ = typ
+ .. ('(scope=%s,ident=%s)'):format(
+ tostring(intchar2lua(eastnode.data.var.scope)),
+ ffi.string(eastnode.data.var.ident, eastnode.data.var.ident_len)
+ )
elseif typ == 'PlainKey' then
- typ = typ .. ('(key=%s)'):format(
- ffi.string(eastnode.data.var.ident, eastnode.data.var.ident_len))
- elseif (typ == 'UnknownFigure' or typ == 'DictLiteral'
- or typ == 'CurlyBracesIdentifier' or typ == 'Lambda') then
- typ = typ .. ('(%s)'):format(
- (eastnode.data.fig.type_guesses.allow_lambda and '\\' or '-')
- .. (eastnode.data.fig.type_guesses.allow_dict and 'd' or '-')
- .. (eastnode.data.fig.type_guesses.allow_ident and 'i' or '-'))
+ typ = typ
+ .. ('(key=%s)'):format(ffi.string(eastnode.data.var.ident, eastnode.data.var.ident_len))
+ elseif
+ typ == 'UnknownFigure'
+ or typ == 'DictLiteral'
+ or typ == 'CurlyBracesIdentifier'
+ or typ == 'Lambda'
+ then
+ typ = typ
+ .. ('(%s)'):format(
+ (eastnode.data.fig.type_guesses.allow_lambda and '\\' or '-')
+ .. (eastnode.data.fig.type_guesses.allow_dict and 'd' or '-')
+ .. (eastnode.data.fig.type_guesses.allow_ident and 'i' or '-')
+ )
elseif typ == 'Comparison' then
- typ = typ .. ('(type=%s,inv=%u,ccs=%s)'):format(
- conv_cmp_type(eastnode.data.cmp.type), eastnode.data.cmp.inv and 1 or 0,
- conv_ccs(eastnode.data.cmp.ccs))
+ typ = typ
+ .. ('(type=%s,inv=%u,ccs=%s)'):format(
+ conv_cmp_type(eastnode.data.cmp.type),
+ eastnode.data.cmp.inv and 1 or 0,
+ conv_ccs(eastnode.data.cmp.ccs)
+ )
elseif typ == 'Integer' then
typ = typ .. ('(val=%u)'):format(tonumber(eastnode.data.num.value))
elseif typ == 'Float' then
@@ -380,11 +391,13 @@ local function eastnode2lua(pstate, eastnode, checked_nodes)
typ = ('%s(scope=%s,ident=%s)'):format(
typ,
tostring(intchar2lua(eastnode.data.opt.scope)),
- ffi.string(eastnode.data.opt.ident, eastnode.data.opt.ident_len))
+ ffi.string(eastnode.data.opt.ident, eastnode.data.opt.ident_len)
+ )
elseif typ == 'Environment' then
typ = ('%s(ident=%s)'):format(
typ,
- ffi.string(eastnode.data.env.ident, eastnode.data.env.ident_len))
+ ffi.string(eastnode.data.env.ident, eastnode.data.env.ident_len)
+ )
elseif typ == 'Assignment' then
typ = ('%s(%s)'):format(typ, conv_expr_asgn_type(eastnode.data.ass.type))
end
@@ -433,22 +446,21 @@ local function phl2lua(pstate)
local ret = {}
for i = 0, (tonumber(pstate.colors.size) - 1) do
local chunk = pstate.colors.items[i]
- local chunk_tbl = pstate_set_str(
- pstate, chunk.start, chunk.end_col - chunk.start.col, {
- group = ffi.string(chunk.group),
- })
+ local chunk_tbl = pstate_set_str(pstate, chunk.start, chunk.end_col - chunk.start.col, {
+ group = ffi.string(chunk.group),
+ })
ret[i + 1] = ('%s:%u:%u:%s'):format(
chunk_tbl.group,
chunk_tbl.start.line,
chunk_tbl.start.col,
- chunk_tbl.str)
+ chunk_tbl.str
+ )
end
return ret
end
describe('Expressions parser', function()
- local function _check_parsing(opts, str, exp_ast, exp_highlighting_fs,
- nz_flags_exps)
+ local function _check_parsing(opts, str, exp_ast, exp_highlighting_fs, nz_flags_exps)
local zflags = opts.flags[1]
nz_flags_exps = nz_flags_exps or {}
local format_check_data = {}
@@ -460,12 +472,12 @@ describe('Expressions parser', function()
end
alloc_log:check({})
- local pstate = new_pstate({str})
+ local pstate = new_pstate({ str })
local east = lib.viml_pexpr_parse(pstate, flags)
local ast = east2lua(str, pstate, east)
local hls = phl2lua(pstate)
if exp_ast == nil then
- format_check_data[flags] = {ast=ast, hl_fs=hls_to_hl_fs(hls)}
+ format_check_data[flags] = { ast = ast, hl_fs = hls_to_hl_fs(hls) }
else
local exps = {
ast = exp_ast,
@@ -499,8 +511,7 @@ describe('Expressions parser', function()
alloc_log:check({})
end)
if not err then
- msg = format_string('Error while processing test (%r, %u):\n%s',
- str, flags, msg)
+ msg = format_string('Error while processing test (%r, %u):\n%s', str, flags, msg)
error(msg)
end
end
@@ -514,16 +525,11 @@ describe('Expressions parser', function()
error(('Unknown group: Nvim%s'):format(group))
end
local col = next_col + (shift or 0)
- return (('%s:%u:%u:%s'):format(
- 'Nvim' .. group,
- 0,
- col,
- str)), (col + #str)
+ return (('%s:%u:%u:%s'):format('Nvim' .. group, 0, col, str)), (col + #str)
end
end
local function fmtn(typ, args, rest)
return ('%s(%s)%s'):format(typ, args, rest)
end
- require('test.unit.viml.expressions.parser_tests')(
- itp, _check_parsing, hl, fmtn)
+ require('test.unit.viml.expressions.parser_tests')(itp, _check_parsing, hl, fmtn)
end)
diff --git a/test/unit/viml/expressions/parser_tests.lua b/test/unit/viml/expressions/parser_tests.lua
index da61672bb1..aa2bf740de 100644
--- a/test/unit/viml/expressions/parser_tests.lua
+++ b/test/unit/viml/expressions/parser_tests.lua
@@ -1,15 +1,13 @@
-local global_helpers = require('test.helpers')
-
-local REMOVE_THIS = global_helpers.REMOVE_THIS
+local REMOVE_THIS = vim.NIL
return function(itp, _check_parsing, hl, fmtn)
local function check_parsing(...)
- return _check_parsing({flags={0, 1, 2, 3}, funcname='check_parsing'}, ...)
+ return _check_parsing({ flags = { 0, 1, 2, 3 }, funcname = 'check_parsing' }, ...)
end
local function check_asgn_parsing(...)
return _check_parsing({
- flags={4, 5, 6, 7},
- funcname='check_asgn_parsing',
+ flags = { 4, 5, 6, 7 },
+ funcname = 'check_asgn_parsing',
}, ...)
end
itp('works with + and @a', function()
@@ -142,7 +140,7 @@ return function(itp, _check_parsing, hl, fmtn)
len = 2,
err = REMOVE_THIS,
ast = {
- 'Register(name=a):0:0:@a'
+ 'Register(name=a):0:0:@a',
},
},
hl_fs = {
@@ -174,7 +172,7 @@ return function(itp, _check_parsing, hl, fmtn)
len = 6,
err = REMOVE_THIS,
ast = {
- 'Register(name=a):0:0: @a'
+ 'Register(name=a):0:0: @a',
},
},
hl_fs = {
@@ -541,7 +539,7 @@ return function(itp, _check_parsing, hl, fmtn)
children = {
{
'Nested:0:4:(',
- children = { 'Register(name=b):0:5:@b' }
+ children = { 'Register(name=b):0:5:@b' },
},
},
},
@@ -579,7 +577,7 @@ return function(itp, _check_parsing, hl, fmtn)
children = {
{
'Nested:0:4:(',
- children = { 'Register(name=b):0:5:@b' }
+ children = { 'Register(name=b):0:5:@b' },
},
},
},
@@ -600,13 +598,13 @@ return function(itp, _check_parsing, hl, fmtn)
hl('BinaryPlus', '+'),
hl('Register', '@c'),
})
- check_parsing(
- '@a + (@b + @c) + @d(@e) + (+@f) + ((+@g(@h))(@j)(@k))(@l)', {--[[
+ check_parsing('@a + (@b + @c) + @d(@e) + (+@f) + ((+@g(@h))(@j)(@k))(@l)', {--[[
| | | | | | | | || | | || | | ||| || || || ||
000000000011111111112222222222333333333344444444445555555
012345678901234567890123456789012345678901234567890123456
]]
- ast = {{
+ ast = {
+ {
'BinaryPlus:0:31: +',
children = {
{
@@ -696,45 +694,46 @@ return function(itp, _check_parsing, hl, fmtn)
},
},
},
- }},
- }, {
- hl('Register', '@a'),
- hl('BinaryPlus', '+', 1),
- hl('NestingParenthesis', '(', 1),
- hl('Register', '@b'),
- hl('BinaryPlus', '+', 1),
- hl('Register', '@c', 1),
- hl('NestingParenthesis', ')'),
- hl('BinaryPlus', '+', 1),
- hl('Register', '@d', 1),
- hl('CallingParenthesis', '('),
- hl('Register', '@e'),
- hl('CallingParenthesis', ')'),
- hl('BinaryPlus', '+', 1),
- hl('NestingParenthesis', '(', 1),
- hl('UnaryPlus', '+'),
- hl('Register', '@f'),
- hl('NestingParenthesis', ')'),
- hl('BinaryPlus', '+', 1),
- hl('NestingParenthesis', '(', 1),
- hl('NestingParenthesis', '('),
- hl('UnaryPlus', '+'),
- hl('Register', '@g'),
- hl('CallingParenthesis', '('),
- hl('Register', '@h'),
- hl('CallingParenthesis', ')'),
- hl('NestingParenthesis', ')'),
- hl('CallingParenthesis', '('),
- hl('Register', '@j'),
- hl('CallingParenthesis', ')'),
- hl('CallingParenthesis', '('),
- hl('Register', '@k'),
- hl('CallingParenthesis', ')'),
- hl('NestingParenthesis', ')'),
- hl('CallingParenthesis', '('),
- hl('Register', '@l'),
- hl('CallingParenthesis', ')'),
- })
+ },
+ },
+ }, {
+ hl('Register', '@a'),
+ hl('BinaryPlus', '+', 1),
+ hl('NestingParenthesis', '(', 1),
+ hl('Register', '@b'),
+ hl('BinaryPlus', '+', 1),
+ hl('Register', '@c', 1),
+ hl('NestingParenthesis', ')'),
+ hl('BinaryPlus', '+', 1),
+ hl('Register', '@d', 1),
+ hl('CallingParenthesis', '('),
+ hl('Register', '@e'),
+ hl('CallingParenthesis', ')'),
+ hl('BinaryPlus', '+', 1),
+ hl('NestingParenthesis', '(', 1),
+ hl('UnaryPlus', '+'),
+ hl('Register', '@f'),
+ hl('NestingParenthesis', ')'),
+ hl('BinaryPlus', '+', 1),
+ hl('NestingParenthesis', '(', 1),
+ hl('NestingParenthesis', '('),
+ hl('UnaryPlus', '+'),
+ hl('Register', '@g'),
+ hl('CallingParenthesis', '('),
+ hl('Register', '@h'),
+ hl('CallingParenthesis', ')'),
+ hl('NestingParenthesis', ')'),
+ hl('CallingParenthesis', '('),
+ hl('Register', '@j'),
+ hl('CallingParenthesis', ')'),
+ hl('CallingParenthesis', '('),
+ hl('Register', '@k'),
+ hl('CallingParenthesis', ')'),
+ hl('NestingParenthesis', ')'),
+ hl('CallingParenthesis', '('),
+ hl('Register', '@l'),
+ hl('CallingParenthesis', ')'),
+ })
check_parsing('@a)', {
-- 012
ast = {
@@ -1078,25 +1077,25 @@ return function(itp, _check_parsing, hl, fmtn)
end)
itp('works with variable names, including curly braces ones', function()
check_parsing('var', {
- ast = {
- 'PlainIdentifier(scope=0,ident=var):0:0:var',
- },
+ ast = {
+ 'PlainIdentifier(scope=0,ident=var):0:0:var',
+ },
}, {
hl('IdentifierName', 'var'),
})
check_parsing('g:var', {
- ast = {
- 'PlainIdentifier(scope=g,ident=var):0:0:g:var',
- },
+ ast = {
+ 'PlainIdentifier(scope=g,ident=var):0:0:g:var',
+ },
}, {
hl('IdentifierScope', 'g'),
hl('IdentifierScopeDelimiter', ':'),
hl('IdentifierName', 'var'),
})
check_parsing('g:', {
- ast = {
- 'PlainIdentifier(scope=g,ident=):0:0:g:',
- },
+ ast = {
+ 'PlainIdentifier(scope=g,ident=):0:0:g:',
+ },
}, {
hl('IdentifierScope', 'g'),
hl('IdentifierScopeDelimiter', ':'),
@@ -1141,7 +1140,7 @@ return function(itp, _check_parsing, hl, fmtn)
children = {
{
'OpMissing:0:3:',
- children={
+ children = {
'PlainIdentifier(scope=a,ident=):0:1:a:',
'Register(name=b):0:3:@b',
},
@@ -1783,7 +1782,7 @@ return function(itp, _check_parsing, hl, fmtn)
{
'Comma:0:3:,',
children = {
- 'PlainIdentifier(scope=0,ident=b):0:2:b',
+ 'PlainIdentifier(scope=0,ident=b):0:2:b',
{
'Comma:0:5:,',
children = {
@@ -1819,7 +1818,7 @@ return function(itp, _check_parsing, hl, fmtn)
{
'Comma:0:3:,',
children = {
- 'PlainIdentifier(scope=0,ident=b):0:2:b',
+ 'PlainIdentifier(scope=0,ident=b):0:2:b',
{
'Comma:0:5:,',
children = {
@@ -2851,7 +2850,7 @@ return function(itp, _check_parsing, hl, fmtn)
},
err = {
arg = '{a : b',
- msg = 'E723: Missing end of Dictionary \'}\': %.*s',
+ msg = "E723: Missing end of Dictionary '}': %.*s",
},
}, {
hl('Dict', '{'),
@@ -3182,7 +3181,7 @@ return function(itp, _check_parsing, hl, fmtn)
},
err = {
arg = '?b',
- msg = 'E109: Missing \':\' after \'?\': %.*s',
+ msg = "E109: Missing ':' after '?': %.*s",
},
}, {
hl('IdentifierName', 'a'),
@@ -3207,7 +3206,7 @@ return function(itp, _check_parsing, hl, fmtn)
},
err = {
arg = '?b:',
- msg = 'E109: Missing \':\' after \'?\': %.*s',
+ msg = "E109: Missing ':' after '?': %.*s",
},
}, {
hl('IdentifierName', 'a'),
@@ -4840,7 +4839,7 @@ return function(itp, _check_parsing, hl, fmtn)
},
err = {
arg = '[1',
- msg = 'E697: Missing end of List \']\': %.*s',
+ msg = "E697: Missing end of List ']': %.*s",
},
}, {
hl('List', '['),
@@ -4848,15 +4847,15 @@ return function(itp, _check_parsing, hl, fmtn)
})
end)
itp('works with strings', function()
- check_parsing('\'abc\'', {
+ check_parsing("'abc'", {
-- 01234
ast = {
- fmtn('SingleQuotedString', 'val="abc"', ':0:0:\'abc\''),
+ fmtn('SingleQuotedString', 'val="abc"', ":0:0:'abc'"),
},
}, {
- hl('SingleQuote', '\''),
+ hl('SingleQuote', "'"),
hl('SingleQuotedBody', 'abc'),
- hl('SingleQuote', '\''),
+ hl('SingleQuote', "'"),
})
check_parsing('"abc"', {
-- 01234
@@ -4868,14 +4867,14 @@ return function(itp, _check_parsing, hl, fmtn)
hl('DoubleQuotedBody', 'abc'),
hl('DoubleQuote', '"'),
})
- check_parsing('\'\'', {
+ check_parsing("''", {
-- 01
ast = {
- fmtn('SingleQuotedString', 'val=NULL', ':0:0:\'\''),
+ fmtn('SingleQuotedString', 'val=NULL', ":0:0:''"),
},
}, {
- hl('SingleQuote', '\''),
- hl('SingleQuote', '\''),
+ hl('SingleQuote', "'"),
+ hl('SingleQuote', "'"),
})
check_parsing('""', {
-- 01
@@ -4898,17 +4897,17 @@ return function(itp, _check_parsing, hl, fmtn)
}, {
hl('InvalidDoubleQuote', '"'),
})
- check_parsing('\'', {
+ check_parsing("'", {
-- 0
ast = {
- fmtn('SingleQuotedString', 'val=NULL', ':0:0:\''),
+ fmtn('SingleQuotedString', 'val=NULL', ":0:0:'"),
},
err = {
- arg = '\'',
+ arg = "'",
msg = 'E115: Missing single quote: %.*s',
},
}, {
- hl('InvalidSingleQuote', '\''),
+ hl('InvalidSingleQuote', "'"),
})
check_parsing('"a', {
-- 01
@@ -4923,71 +4922,71 @@ return function(itp, _check_parsing, hl, fmtn)
hl('InvalidDoubleQuote', '"'),
hl('InvalidDoubleQuotedBody', 'a'),
})
- check_parsing('\'a', {
+ check_parsing("'a", {
-- 01
ast = {
- fmtn('SingleQuotedString', 'val="a"', ':0:0:\'a'),
+ fmtn('SingleQuotedString', 'val="a"', ":0:0:'a"),
},
err = {
- arg = '\'a',
+ arg = "'a",
msg = 'E115: Missing single quote: %.*s',
},
}, {
- hl('InvalidSingleQuote', '\''),
+ hl('InvalidSingleQuote', "'"),
hl('InvalidSingleQuotedBody', 'a'),
})
- check_parsing('\'abc\'\'def\'', {
+ check_parsing("'abc''def'", {
-- 0123456789
ast = {
- fmtn('SingleQuotedString', 'val="abc\'def"', ':0:0:\'abc\'\'def\''),
+ fmtn('SingleQuotedString', 'val="abc\'def"', ":0:0:'abc''def'"),
},
}, {
- hl('SingleQuote', '\''),
+ hl('SingleQuote', "'"),
hl('SingleQuotedBody', 'abc'),
- hl('SingleQuotedQuote', '\'\''),
+ hl('SingleQuotedQuote', "''"),
hl('SingleQuotedBody', 'def'),
- hl('SingleQuote', '\''),
+ hl('SingleQuote', "'"),
})
- check_parsing('\'abc\'\'', {
+ check_parsing("'abc''", {
-- 012345
ast = {
- fmtn('SingleQuotedString', 'val="abc\'"', ':0:0:\'abc\'\''),
+ fmtn('SingleQuotedString', 'val="abc\'"', ":0:0:'abc''"),
},
err = {
- arg = '\'abc\'\'',
+ arg = "'abc''",
msg = 'E115: Missing single quote: %.*s',
},
}, {
- hl('InvalidSingleQuote', '\''),
+ hl('InvalidSingleQuote', "'"),
hl('InvalidSingleQuotedBody', 'abc'),
- hl('InvalidSingleQuotedQuote', '\'\''),
+ hl('InvalidSingleQuotedQuote', "''"),
})
- check_parsing('\'\'\'\'\'\'\'\'', {
+ check_parsing("''''''''", {
-- 01234567
ast = {
- fmtn('SingleQuotedString', 'val="\'\'\'"', ':0:0:\'\'\'\'\'\'\'\''),
+ fmtn('SingleQuotedString', "val=\"'''\"", ":0:0:''''''''"),
},
}, {
- hl('SingleQuote', '\''),
- hl('SingleQuotedQuote', '\'\''),
- hl('SingleQuotedQuote', '\'\''),
- hl('SingleQuotedQuote', '\'\''),
- hl('SingleQuote', '\''),
+ hl('SingleQuote', "'"),
+ hl('SingleQuotedQuote', "''"),
+ hl('SingleQuotedQuote', "''"),
+ hl('SingleQuotedQuote', "''"),
+ hl('SingleQuote', "'"),
})
- check_parsing('\'\'\'a\'\'\'\'bc\'', {
+ check_parsing("'''a''''bc'", {
-- 01234567890
-- 0 1
ast = {
- fmtn('SingleQuotedString', 'val="\'a\'\'bc"', ':0:0:\'\'\'a\'\'\'\'bc\''),
+ fmtn('SingleQuotedString', "val=\"'a''bc\"", ":0:0:'''a''''bc'"),
},
}, {
- hl('SingleQuote', '\''),
- hl('SingleQuotedQuote', '\'\''),
+ hl('SingleQuote', "'"),
+ hl('SingleQuotedQuote', "''"),
hl('SingleQuotedBody', 'a'),
- hl('SingleQuotedQuote', '\'\''),
- hl('SingleQuotedQuote', '\'\''),
+ hl('SingleQuotedQuote', "''"),
+ hl('SingleQuotedQuote', "''"),
hl('SingleQuotedBody', 'bc'),
- hl('SingleQuote', '\''),
+ hl('SingleQuote', "'"),
})
check_parsing('"\\"\\"\\"\\""', {
-- 0123456789
@@ -5006,7 +5005,11 @@ return function(itp, _check_parsing, hl, fmtn)
-- 0123456789012345678901234
-- 0 1 2
ast = {
- fmtn('DoubleQuotedString', 'val="abc\\"def\\"ghi\\"jkl\\"mno"', ':0:0:"abc\\"def\\"ghi\\"jkl\\"mno"'),
+ fmtn(
+ 'DoubleQuotedString',
+ 'val="abc\\"def\\"ghi\\"jkl\\"mno"',
+ ':0:0:"abc\\"def\\"ghi\\"jkl\\"mno"'
+ ),
},
}, {
hl('DoubleQuote', '"'),
@@ -6977,8 +6980,7 @@ return function(itp, _check_parsing, hl, fmtn)
arg = '\0002&A:\000',
msg = 'E15: Expected value, got EOC: %.*s',
},
- }, {
- }, {
+ }, {}, {
[2] = {
ast = {
len = REMOVE_THIS,
@@ -7025,7 +7027,7 @@ return function(itp, _check_parsing, hl, fmtn)
},
},
})
- check_parsing({data='01', size=1}, {
+ check_parsing({ data = '01', size = 1 }, {
len = 1,
ast = {
'Integer(val=0):0:0:0',
@@ -7033,7 +7035,7 @@ return function(itp, _check_parsing, hl, fmtn)
}, {
hl('Number', '0'),
})
- check_parsing({data='001', size=2}, {
+ check_parsing({ data = '001', size = 2 }, {
len = 2,
ast = {
'Integer(val=0):0:0:00',
@@ -7076,8 +7078,7 @@ return function(itp, _check_parsing, hl, fmtn)
arg = '|"\\U\\',
msg = 'E15: Expected value, got EOC: %.*s',
},
- }, {
- }, {
+ }, {}, {
[2] = {
ast = {
len = REMOVE_THIS,
@@ -7109,8 +7110,7 @@ return function(itp, _check_parsing, hl, fmtn)
arg = '|"\\e"',
msg = 'E15: Expected value, got EOC: %.*s',
},
- }, {
- }, {
+ }, {}, {
[2] = {
ast = {
len = REMOVE_THIS,
@@ -7142,8 +7142,7 @@ return function(itp, _check_parsing, hl, fmtn)
arg = '|\029',
msg = 'E15: Expected value, got EOC: %.*s',
},
- }, {
- }, {
+ }, {}, {
[2] = {
ast = {
len = REMOVE_THIS,
@@ -7373,7 +7372,7 @@ return function(itp, _check_parsing, hl, fmtn)
hl_fs = {
[2] = REMOVE_THIS,
[3] = REMOVE_THIS,
- }
+ },
},
})
diff --git a/test/unit/viml/helpers.lua b/test/unit/viml/helpers.lua
index 9d8102e023..92661e3027 100644
--- a/test/unit/viml/helpers.lua
+++ b/test/unit/viml/helpers.lua
@@ -76,7 +76,7 @@ local function pstate_set_str(pstate, start, len, ret)
ret = ret or {}
ret.start = {
line = tonumber(start.line),
- col = tonumber(start.col)
+ col = tonumber(start.col),
}
ret.len = tonumber(len)
ret.str, ret.error = pstate_str(pstate, start, len)
@@ -84,36 +84,57 @@ local function pstate_set_str(pstate, start, len, ret)
end
local eltkn_cmp_type_tab
-make_enum_conv_tab(lib, {
- 'kExprCmpEqual',
- 'kExprCmpMatches',
- 'kExprCmpGreater',
- 'kExprCmpGreaterOrEqual',
- 'kExprCmpIdentical',
-}, 'kExprCmp', function(ret) eltkn_cmp_type_tab = ret end)
+make_enum_conv_tab(
+ lib,
+ {
+ 'kExprCmpEqual',
+ 'kExprCmpMatches',
+ 'kExprCmpGreater',
+ 'kExprCmpGreaterOrEqual',
+ 'kExprCmpIdentical',
+ },
+ 'kExprCmp',
+ function(ret)
+ eltkn_cmp_type_tab = ret
+ end
+)
local function conv_cmp_type(typ)
return conv_enum(eltkn_cmp_type_tab, typ)
end
local ccs_tab
-make_enum_conv_tab(lib, {
- 'kCCStrategyUseOption',
- 'kCCStrategyMatchCase',
- 'kCCStrategyIgnoreCase',
-}, 'kCCStrategy', function(ret) ccs_tab = ret end)
+make_enum_conv_tab(
+ lib,
+ {
+ 'kCCStrategyUseOption',
+ 'kCCStrategyMatchCase',
+ 'kCCStrategyIgnoreCase',
+ },
+ 'kCCStrategy',
+ function(ret)
+ ccs_tab = ret
+ end
+)
local function conv_ccs(ccs)
return conv_enum(ccs_tab, ccs)
end
local expr_asgn_type_tab
-make_enum_conv_tab(lib, {
- 'kExprAsgnPlain',
- 'kExprAsgnAdd',
- 'kExprAsgnSubtract',
- 'kExprAsgnConcat',
-}, 'kExprAsgn', function(ret) expr_asgn_type_tab = ret end)
+make_enum_conv_tab(
+ lib,
+ {
+ 'kExprAsgnPlain',
+ 'kExprAsgnAdd',
+ 'kExprAsgnSubtract',
+ 'kExprAsgnConcat',
+ },
+ 'kExprAsgn',
+ function(ret)
+ expr_asgn_type_tab = ret
+ end
+)
local function conv_expr_asgn_type(expr_asgn_type)
return conv_enum(expr_asgn_type_tab, expr_asgn_type)