aboutsummaryrefslogtreecommitdiff
path: root/test/unit/viml/expressions
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2017-09-03 19:57:24 +0300
committerZyX <kp-pav@yandex.ru>2017-10-08 22:12:00 +0300
commit919223c23ae3c8c904f35e7d605b1cf14d44a5f0 (patch)
treef4bf252835533c02e9111f1463a6688766d48073 /test/unit/viml/expressions
parent1265da028882d9877a5ebbd3f3f52cb4b52a4b94 (diff)
downloadrneovim-919223c23ae3c8c904f35e7d605b1cf14d44a5f0.tar.gz
rneovim-919223c23ae3c8c904f35e7d605b1cf14d44a5f0.tar.bz2
rneovim-919223c23ae3c8c904f35e7d605b1cf14d44a5f0.zip
unittests: Move some functions into helpers modules
Diffstat (limited to 'test/unit/viml/expressions')
-rw-r--r--test/unit/viml/expressions/lexer_spec.lua104
1 files changed, 10 insertions, 94 deletions
diff --git a/test/unit/viml/expressions/lexer_spec.lua b/test/unit/viml/expressions/lexer_spec.lua
index c877ce4bbf..32182f650d 100644
--- a/test/unit/viml/expressions/lexer_spec.lua
+++ b/test/unit/viml/expressions/lexer_spec.lua
@@ -1,11 +1,18 @@
local helpers = require('test.unit.helpers')(after_each)
+local viml_helpers = require('test.unit.viml.helpers')
local itp = helpers.gen_itp(it)
local child_call_once = helpers.child_call_once
+local conv_enum = helpers.conv_enum
local cimport = helpers.cimport
local ffi = helpers.ffi
local eq = helpers.eq
+local pline2lua = viml_helpers.pline2lua
+local new_pstate = viml_helpers.new_pstate
+local intchar2lua = viml_helpers.intchar2lua
+local pstate_set_str = viml_helpers.pstate_set_str
+
local lib = cimport('./src/nvim/viml/parser/expressions.h')
local eltkn_type_tab, eltkn_cmp_type_tab, ccs_tab, eltkn_mul_type_tab
@@ -71,114 +78,23 @@ child_call_once(function()
}
end)
-local function array_size(arr)
- return ffi.sizeof(arr) / ffi.sizeof(arr[0])
-end
-
-local function kvi_size(kvi)
- return array_size(kvi.init_array)
-end
-
-local function kvi_init(kvi)
- kvi.capacity = kvi_size(kvi)
- kvi.items = kvi.init_array
- return kvi
-end
-
-local function kvi_new(ct)
- return kvi_init(ffi.new(ct))
-end
-
-local function new_pstate(strings)
- local strings_idx = 0
- local function get_line(_, ret_pline)
- strings_idx = strings_idx + 1
- local str = strings[strings_idx]
- local data, size
- if type(str) == 'string' then
- data = str
- size = #str
- elseif type(str) == 'nil' then
- data = nil
- size = 0
- elseif type(str) == 'table' then
- data = str.data
- size = str.size
- elseif type(str) == 'function' then
- data, size = str()
- size = size or 0
- end
- ret_pline.data = data
- ret_pline.size = size
- ret_pline.allocated = false
- end
- local pline_init = {
- data = nil,
- size = 0,
- allocated = false,
- }
- local state = {
- reader = {
- get_line = get_line,
- cookie = nil,
- conv = {
- vc_type = 0,
- vc_factor = 1,
- vc_fail = false,
- },
- },
- pos = { line = 0, col = 0 },
- colors = kvi_new('ParserHighlight'),
- can_continuate = false,
- }
- local ret = ffi.new('ParserState', state)
- kvi_init(ret.reader.lines)
- kvi_init(ret.stack)
- return ret
-end
-
-local function conv_enum(etab, eval)
- local n = tonumber(eval)
- return etab[n] or n
-end
-
local function conv_eltkn_type(typ)
return conv_enum(eltkn_type_tab, typ)
end
-local function pline2lua(pline)
- return ffi.string(pline.data, pline.size)
-end
-
local bracket_types = {
Bracket = true,
FigureBrace = true,
Parenthesis = true,
}
-local function intchar2lua(ch)
- ch = tonumber(ch)
- return (20 <= ch and ch < 127) and ('%c'):format(ch) or ch
-end
-
local function eltkn2lua(pstate, tkn)
local ret = {
type = conv_eltkn_type(tkn.type),
- len = tonumber(tkn.len),
- start = { line = tonumber(tkn.start.line), col = tonumber(tkn.start.col) },
}
- if ret.start.line < pstate.reader.lines.size then
- local pstr = pline2lua(pstate.reader.lines.items[ret.start.line])
- if ret.start.col >= #pstr then
- ret.error = 'start.col >= #pstr'
- else
- ret.str = pstr:sub(ret.start.col + 1, ret.start.col + ret.len)
- if #(ret.str) ~= ret.len then
- ret.error = '#str /= len'
- end
- end
- else
- ret.error = 'start.line >= pstate.reader.lines.size'
+ pstate_set_str(pstate, tkn.start, tkn.len, ret)
+ if not ret.error and (#(ret.str) ~= ret.len) then
+ ret.error = '#str /= len'
end
if ret.type == 'Comparison' then
ret.data = {