diff options
-rw-r--r-- | test/unit/helpers.lua | 11 | ||||
-rw-r--r-- | test/unit/viml/expressions/parser_spec.lua | 56 |
2 files changed, 45 insertions, 22 deletions
diff --git a/test/unit/helpers.lua b/test/unit/helpers.lua index d3d14a5ca2..68ce9eed62 100644 --- a/test/unit/helpers.lua +++ b/test/unit/helpers.lua @@ -315,7 +315,7 @@ local function alloc_log_new() eq(exp, self.log) self:clear() end - function log:clear_tmp_allocs() + function log:clear_tmp_allocs(clear_null_frees) local toremove = {} local allocs = {} for i, v in ipairs(self.log) do @@ -327,6 +327,8 @@ local function alloc_log_new() if v.func == 'free' then toremove[#toremove + 1] = i end + elseif clear_null_frees and v.args[1] == self.null then + toremove[#toremove + 1] = i end if v.func == 'realloc' then allocs[tostring(v.ret)] = i @@ -779,6 +781,12 @@ local function kvi_init(kvi) return kvi end +local function kvi_destroy(kvi) + if kvi.items ~= kvi.init_array then + lib.xfree(kvi.items) + end +end + local function kvi_new(ct) return kvi_init(ffi.new(ct)) end @@ -830,6 +838,7 @@ local module = { sc = sc, conv_enum = conv_enum, array_size = array_sive, + kvi_destroy = kvi_destroy, kvi_size = kvi_size, kvi_init = kvi_init, kvi_new = kvi_new, diff --git a/test/unit/viml/expressions/parser_spec.lua b/test/unit/viml/expressions/parser_spec.lua index 54fd54aea8..5f5924c630 100644 --- a/test/unit/viml/expressions/parser_spec.lua +++ b/test/unit/viml/expressions/parser_spec.lua @@ -5,6 +5,8 @@ local viml_helpers = require('test.unit.viml.helpers') local make_enum_conv_tab = helpers.make_enum_conv_tab local child_call_once = helpers.child_call_once +local alloc_log_new = helpers.alloc_log_new +local kvi_destroy = helpers.kvi_destroy local conv_enum = helpers.conv_enum local ptr2key = helpers.ptr2key local cimport = helpers.cimport @@ -23,6 +25,8 @@ local format_luav = global_helpers.format_luav local lib = cimport('./src/nvim/viml/parser/expressions.h') +local alloc_log = alloc_log_new() + local function format_check(expr, flags, ast, hls) -- That forces specific order. print( format_string('\ncheck_parsing(%r, %u, {', expr, flags)) @@ -230,30 +234,40 @@ end) describe('Expressions parser', function() local function check_parsing(str, flags, exp_ast, exp_highlighting_fs) - flags = flags or 0 - - if os.getenv('NVIM_TEST_PARSER_SPEC_PRINT_TEST_CASE') == '1' then - print(str, flags) - end + local err, msg = pcall(function() + flags = flags or 0 - local pstate = new_pstate({str}) - local east = lib.viml_pexpr_parse(pstate, flags) - local ast = east2lua(pstate, east) - local hls = phl2lua(pstate) - if exp_ast == nil then - format_check(str, flags, ast, hls) - return - end - eq(exp_ast, ast) - if exp_highlighting_fs then - local exp_highlighting = {} - local next_col = 0 - for i, h in ipairs(exp_highlighting_fs) do - exp_highlighting[i], next_col = h(next_col) + if os.getenv('NVIM_TEST_PARSER_SPEC_PRINT_TEST_CASE') == '1' then + print(str, flags) + end + alloc_log:check({}) + + local pstate = new_pstate({str}) + local east = lib.viml_pexpr_parse(pstate, flags) + local ast = east2lua(pstate, east) + local hls = phl2lua(pstate) + if exp_ast == nil then + format_check(str, flags, ast, hls) + return + end + eq(exp_ast, ast) + if exp_highlighting_fs then + local exp_highlighting = {} + local next_col = 0 + for i, h in ipairs(exp_highlighting_fs) do + exp_highlighting[i], next_col = h(next_col) + end + eq(exp_highlighting, hls) end - eq(exp_highlighting, hls) + lib.viml_pexpr_free_ast(east) + kvi_destroy(pstate.colors) + alloc_log:clear_tmp_allocs(true) + alloc_log:check({}) + end) + if not err then + msg = format_string('Error while processing test (%r, %u):\n%s', str, flags, msg) + error(msg) end - lib.viml_pexpr_free_ast(east) end local function hl(group, str, shift) return function(next_col) |