2024-04-09 04:26:16 -07:00
|
|
|
local t = require('test.unit.testutil')
|
2024-04-08 02:03:20 -07:00
|
|
|
local itp = t.gen_itp(it)
|
|
|
|
local t_eval = require('test.unit.eval.testutil')
|
|
|
|
|
|
|
|
local cimport = t.cimport
|
|
|
|
local to_cstr = t.to_cstr
|
|
|
|
local eq = t.eq
|
|
|
|
|
|
|
|
local list = t_eval.list
|
|
|
|
local lst2tbl = t_eval.lst2tbl
|
|
|
|
local type_key = t_eval.type_key
|
|
|
|
local list_type = t_eval.list_type
|
|
|
|
local null_string = t_eval.null_string
|
2016-02-08 17:20:16 -07:00
|
|
|
|
|
|
|
local encode = cimport('./src/nvim/eval/encode.h')
|
|
|
|
|
|
|
|
describe('encode_list_write()', function()
|
|
|
|
local encode_list_write = function(l, s)
|
|
|
|
return encode.encode_list_write(l, to_cstr(s), #s)
|
|
|
|
end
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes empty string', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ [type_key] = list_type }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes ASCII string literal with printable characters', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, 'abc')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ 'abc' }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string starting with NL', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\nabc')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, 'abc' }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string starting with NL twice', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\nabc')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, 'abc' }, lst2tbl(l))
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\nabc')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, 'abc', 'abc' }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string ending with NL', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, 'abc\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ 'abc', null_string }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string ending with NL twice', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, 'abc\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ 'abc', null_string }, lst2tbl(l))
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, 'abc\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ 'abc', 'abc', null_string }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string starting, ending and containing NL twice', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\na\nb\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, 'a', 'b', null_string }, lst2tbl(l))
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\na\nb\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, 'a', 'b', null_string, 'a', 'b', null_string }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string starting, ending and containing NUL with NL between twice', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\0\n\0\n\0')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ '\n', '\n', '\n' }, lst2tbl(l))
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\0\n\0\n\0')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ '\n', '\n', '\n\n', '\n', '\n' }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string starting, ending and containing NL with NUL between twice', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\n\0\n\0\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, '\n', '\n', null_string }, lst2tbl(l))
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\n\0\n\0\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, '\n', '\n', null_string, '\n', '\n', null_string }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string containing a single NL twice', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, null_string }, lst2tbl(l))
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, null_string, null_string }, lst2tbl(l))
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
|
2017-03-04 18:02:45 -07:00
|
|
|
itp('writes string containing a few NLs twice', function()
|
2016-02-08 17:20:16 -07:00
|
|
|
local l = list()
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\n\n\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq({ null_string, null_string, null_string, null_string }, lst2tbl(l))
|
2024-07-02 04:45:50 -07:00
|
|
|
encode_list_write(l, '\n\n\n')
|
2023-12-04 15:32:39 -07:00
|
|
|
eq(
|
|
|
|
{ null_string, null_string, null_string, null_string, null_string, null_string, null_string },
|
|
|
|
lst2tbl(l)
|
|
|
|
)
|
2016-02-08 17:20:16 -07:00
|
|
|
end)
|
|
|
|
end)
|