2016-04-23 16:53:11 -07:00
local helpers = require ( ' test.functional.helpers ' ) ( after_each )
2015-11-17 15:31:22 -07:00
local clear = helpers.clear
2024-01-12 10:59:57 -07:00
local fn = helpers.fn
2015-11-17 15:31:22 -07:00
local eval , eq = helpers.eval , helpers.eq
2017-04-08 14:12:26 -07:00
local command = helpers.command
2024-01-12 10:59:57 -07:00
local api = helpers.api
2015-09-18 15:47:37 -07:00
local exc_exec = helpers.exc_exec
2022-11-21 17:13:30 -07:00
local is_os = helpers.is_os
2015-09-18 15:47:37 -07:00
2015-07-12 07:31:55 -07:00
describe ( ' msgpack*() functions ' , function ( )
2015-09-18 15:47:37 -07:00
before_each ( clear )
2015-07-12 07:31:55 -07:00
local obj_test = function ( msg , obj )
it ( msg , function ( )
2024-01-12 10:59:57 -07:00
api.nvim_set_var ( ' obj ' , obj )
2015-07-12 07:31:55 -07:00
eq ( obj , eval ( ' msgpackparse(msgpackdump(g:obj)) ' ) )
2021-07-29 09:46:45 -07:00
eq ( obj , eval ( ' msgpackparse(msgpackdump(g:obj, "B")) ' ) )
2015-07-12 07:31:55 -07:00
end )
end
2015-09-18 15:47:37 -07:00
2016-11-16 16:33:45 -07:00
-- Regression test: msgpack_list_write was failing to write buffer with zero
2015-07-12 07:31:55 -07:00
-- length.
2023-12-07 04:19:35 -07:00
obj_test ( ' are able to dump and restore {"file": ""} ' , { { file = ' ' } } )
2016-11-16 16:33:45 -07:00
-- Regression test: msgpack_list_write was failing to write buffer with NL at
2015-07-12 07:31:55 -07:00
-- the end.
2023-12-07 04:19:35 -07:00
obj_test ( ' are able to dump and restore {0, "echo mpack"} ' , { { 0 , ' echo mpack ' } } )
obj_test ( ' are able to dump and restore "Test \\ n" ' , { ' Test \n ' } )
2016-11-16 16:33:45 -07:00
-- Regression test: msgpack_list_write was failing to write buffer with NL
2015-07-12 07:31:55 -07:00
-- inside.
2023-12-07 04:19:35 -07:00
obj_test ( ' are able to dump and restore "Test \\ nTest 2" ' , { ' Test \n Test 2 ' } )
2016-11-16 16:33:45 -07:00
-- Test that big objects (requirement: dump to something that is bigger then
-- IOSIZE) are also fine. This particular object is obtained by concatenating
2015-07-12 07:31:55 -07:00
-- 5 identical shada files.
2023-12-07 04:19:35 -07:00
-- stylua: ignore
2015-07-12 07:31:55 -07:00
local big_obj = {
1 , 1436711454 , 78 , {
encoding = " utf-8 " ,
max_kbyte = 10 ,
pid = 19269 ,
version = " NVIM 0.0.0-alpha+201507121634 "
} ,
8 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
8 , 1436711391 , 8 , { file = " " } ,
4 , 1436700940 , 30 , { 0 , " call mkdir('/tmp/tty/tty') " } ,
4 , 1436701355 , 35 , { 0 , " call mkdir('/tmp/tty/tty', 'p') " } ,
4 , 1436701368 , 24 , { 0 , " call mkdir('/', 'p') " } ,
4 , 1436701375 , 26 , { 0 , " call mkdir('/tty/tty') " } ,
4 , 1436701383 , 30 , { 0 , " call mkdir('/tty/tty/tty') " } ,
4 , 1436701407 , 35 , { 0 , " call mkdir('/usr/tty/tty', 'p') " } ,
4 , 1436701666 , 35 , { 0 , " call mkdir('/tty/tty/tty', 'p') " } ,
4 , 1436708101 , 25 , { 0 , " echo msgpackdump([1]) " } ,
4 , 1436708966 , 6 , { 0 , " cq " } ,
4 , 1436709606 , 25 , { 0 , " echo msgpackdump([5]) " } ,
4 , 1436709610 , 26 , { 0 , " echo msgpackdump([10]) " } ,
4 , 1436709615 , 31 , { 0 , " echo msgpackdump([5, 5, 5]) " } ,
4 , 1436709618 , 35 , { 0 , " echo msgpackdump([5, 5, 5, 10]) " } ,
4 , 1436709634 , 57 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1}]]) "
} ,
4 , 1436709651 , 67 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}]]) "
} ,
4 , 1436709660 , 70 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}], 0]) "
} ,
4 , 1436710095 , 29 , { 0 , " echo msgpackparse([ \" \\ n \" ]) " } ,
4 , 1436710100 , 28 , { 0 , " echo msgpackparse([ \" j \" ]) " } ,
4 , 1436710109 , 31 , { 0 , " echo msgpackparse([ \" \" , \" \" ]) " } ,
4 , 1436710424 , 33 , { 0 , " echo msgpackparse([ \" \" , \" \\ n \" ]) " } ,
4 , 1436710428 , 32 , { 0 , " echo msgpackparse([ \" \" , \" j \" ]) " } ,
4 , 1436711142 , 14 , { 0 , " echo mpack " } ,
4 , 1436711196 , 45 , { 0 , " let lengths = map(mpack[:], 'len(v:val)') " } ,
4 , 1436711206 , 16 , { 0 , " echo lengths " } ,
4 , 1436711244 , 92 , {
0 ,
( " let sum = len(lengths) - 1 | call map(copy(lengths), "
.. " 'extend(g:, { \" sum \" : sum + v:val})') " )
} ,
4 , 1436711245 , 12 , { 0 , " echo sum " } ,
4 , 1436711398 , 10 , { 0 , " echo s " } ,
4 , 1436711404 , 41 , { 0 , " let mpack = readfile('/tmp/foo', 'b') " } ,
4 , 1436711408 , 41 , { 0 , " let shada_objects=msgpackparse(mpack) " } ,
4 , 1436711415 , 22 , { 0 , " echo shada_objects " } ,
4 , 1436711451 , 30 , { 0 , " e ~/.nvim/shada/main.shada " } ,
4 , 1436711454 , 6 , { 0 , " qa " } ,
4 , 1436711442 , 9 , { 1 , " test " , 47 } ,
4 , 1436711443 , 15 , { 1 , " aontsuesan " , 47 } ,
2 , 1436711443 , 38 , { hlsearch = 1 , pat = " aontsuesan " , smartcase = 1 } ,
2 , 0 , 31 , { islast = 0 , pat = " " , smartcase = 1 , sub = 1 } ,
3 , 0 , 3 , { " " } ,
10 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
1 , 1436711454 , 78 , {
encoding = " utf-8 " ,
max_kbyte = 10 ,
pid = 19269 ,
version = " NVIM 0.0.0-alpha+201507121634 "
} ,
8 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
8 , 1436711391 , 8 , { file = " " } ,
4 , 1436700940 , 30 , { 0 , " call mkdir('/tmp/tty/tty') " } ,
4 , 1436701355 , 35 , { 0 , " call mkdir('/tmp/tty/tty', 'p') " } ,
4 , 1436701368 , 24 , { 0 , " call mkdir('/', 'p') " } ,
4 , 1436701375 , 26 , { 0 , " call mkdir('/tty/tty') " } ,
4 , 1436701383 , 30 , { 0 , " call mkdir('/tty/tty/tty') " } ,
4 , 1436701407 , 35 , { 0 , " call mkdir('/usr/tty/tty', 'p') " } ,
4 , 1436701666 , 35 , { 0 , " call mkdir('/tty/tty/tty', 'p') " } ,
4 , 1436708101 , 25 , { 0 , " echo msgpackdump([1]) " } ,
4 , 1436708966 , 6 , { 0 , " cq " } ,
4 , 1436709606 , 25 , { 0 , " echo msgpackdump([5]) " } ,
4 , 1436709610 , 26 , { 0 , " echo msgpackdump([10]) " } ,
4 , 1436709615 , 31 , { 0 , " echo msgpackdump([5, 5, 5]) " } ,
4 , 1436709618 , 35 , { 0 , " echo msgpackdump([5, 5, 5, 10]) " } ,
4 , 1436709634 , 57 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1}]]) "
} ,
4 , 1436709651 , 67 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}]]) "
} ,
4 , 1436709660 , 70 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}], 0]) "
} ,
4 , 1436710095 , 29 , { 0 , " echo msgpackparse([ \" \\ n \" ]) " } ,
4 , 1436710100 , 28 , { 0 , " echo msgpackparse([ \" j \" ]) " } ,
4 , 1436710109 , 31 , { 0 , " echo msgpackparse([ \" \" , \" \" ]) " } ,
4 , 1436710424 , 33 , { 0 , " echo msgpackparse([ \" \" , \" \\ n \" ]) " } ,
4 , 1436710428 , 32 , { 0 , " echo msgpackparse([ \" \" , \" j \" ]) " } ,
4 , 1436711142 , 14 , { 0 , " echo mpack " } ,
4 , 1436711196 , 45 , { 0 , " let lengths = map(mpack[:], 'len(v:val)') " } ,
4 , 1436711206 , 16 , { 0 , " echo lengths " } ,
4 , 1436711244 , 92 , {
0 ,
( " let sum = len(lengths) - 1 | call map(copy(lengths), "
.. " 'extend(g:, { \" sum \" : sum + v:val})') " )
} ,
4 , 1436711245 , 12 , { 0 , " echo sum " } ,
4 , 1436711398 , 10 , { 0 , " echo s " } ,
4 , 1436711404 , 41 , { 0 , " let mpack = readfile('/tmp/foo', 'b') " } ,
4 , 1436711408 , 41 , { 0 , " let shada_objects=msgpackparse(mpack) " } ,
4 , 1436711415 , 22 , { 0 , " echo shada_objects " } ,
4 , 1436711451 , 30 , { 0 , " e ~/.nvim/shada/main.shada " } ,
4 , 1436711454 , 6 , { 0 , " qa " } ,
4 , 1436711442 , 9 , { 1 , " test " , 47 } ,
4 , 1436711443 , 15 , { 1 , " aontsuesan " , 47 } ,
2 , 1436711443 , 38 , { hlsearch = 1 , pat = " aontsuesan " , smartcase = 1 } ,
2 , 0 , 31 , { islast = 0 , pat = " " , smartcase = 1 , sub = 1 } ,
3 , 0 , 3 , { " " } ,
10 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
1 , 1436711454 , 78 , {
encoding = " utf-8 " ,
max_kbyte = 10 ,
pid = 19269 ,
version = " NVIM 0.0.0-alpha+201507121634 "
} ,
8 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
8 , 1436711391 , 8 , { file = " " } ,
4 , 1436700940 , 30 , { 0 , " call mkdir('/tmp/tty/tty') " } ,
4 , 1436701355 , 35 , { 0 , " call mkdir('/tmp/tty/tty', 'p') " } ,
4 , 1436701368 , 24 , { 0 , " call mkdir('/', 'p') " } ,
4 , 1436701375 , 26 , { 0 , " call mkdir('/tty/tty') " } ,
4 , 1436701383 , 30 , { 0 , " call mkdir('/tty/tty/tty') " } ,
4 , 1436701407 , 35 , { 0 , " call mkdir('/usr/tty/tty', 'p') " } ,
4 , 1436701666 , 35 , { 0 , " call mkdir('/tty/tty/tty', 'p') " } ,
4 , 1436708101 , 25 , { 0 , " echo msgpackdump([1]) " } ,
4 , 1436708966 , 6 , { 0 , " cq " } ,
4 , 1436709606 , 25 , { 0 , " echo msgpackdump([5]) " } ,
4 , 1436709610 , 26 , { 0 , " echo msgpackdump([10]) " } ,
4 , 1436709615 , 31 , { 0 , " echo msgpackdump([5, 5, 5]) " } ,
4 , 1436709618 , 35 , { 0 , " echo msgpackdump([5, 5, 5, 10]) " } ,
4 , 1436709634 , 57 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1}]]) "
} ,
4 , 1436709651 , 67 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}]]) "
} ,
4 , 1436709660 , 70 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}], 0]) "
} ,
4 , 1436710095 , 29 , { 0 , " echo msgpackparse([ \" \\ n \" ]) " } ,
4 , 1436710100 , 28 , { 0 , " echo msgpackparse([ \" j \" ]) " } ,
4 , 1436710109 , 31 , { 0 , " echo msgpackparse([ \" \" , \" \" ]) " } ,
4 , 1436710424 , 33 , { 0 , " echo msgpackparse([ \" \" , \" \\ n \" ]) " } ,
4 , 1436710428 , 32 , { 0 , " echo msgpackparse([ \" \" , \" j \" ]) " } ,
4 , 1436711142 , 14 , { 0 , " echo mpack " } ,
4 , 1436711196 , 45 , { 0 , " let lengths = map(mpack[:], 'len(v:val)') " } ,
4 , 1436711206 , 16 , { 0 , " echo lengths " } ,
4 , 1436711244 , 92 , {
0 ,
( " let sum = len(lengths) - 1 | call map(copy(lengths), "
.. " 'extend(g:, { \" sum \" : sum + v:val})') " )
} ,
4 , 1436711245 , 12 , { 0 , " echo sum " } ,
4 , 1436711398 , 10 , { 0 , " echo s " } ,
4 , 1436711404 , 41 , { 0 , " let mpack = readfile('/tmp/foo', 'b') " } ,
4 , 1436711408 , 41 , { 0 , " let shada_objects=msgpackparse(mpack) " } ,
4 , 1436711415 , 22 , { 0 , " echo shada_objects " } ,
4 , 1436711451 , 30 , { 0 , " e ~/.nvim/shada/main.shada " } ,
4 , 1436711454 , 6 , { 0 , " qa " } ,
4 , 1436711442 , 9 , { 1 , " test " , 47 } ,
4 , 1436711443 , 15 , { 1 , " aontsuesan " , 47 } ,
2 , 1436711443 , 38 , { hlsearch = 1 , pat = " aontsuesan " , smartcase = 1 } ,
2 , 0 , 31 , { islast = 0 , pat = " " , smartcase = 1 , sub = 1 } ,
3 , 0 , 3 , { " " } ,
10 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
1 , 1436711454 , 78 , {
encoding = " utf-8 " ,
max_kbyte = 10 ,
pid = 19269 ,
version = " NVIM 0.0.0-alpha+201507121634 "
} ,
8 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
8 , 1436711391 , 8 , { file = " " } ,
4 , 1436700940 , 30 , { 0 , " call mkdir('/tmp/tty/tty') " } ,
4 , 1436701355 , 35 , { 0 , " call mkdir('/tmp/tty/tty', 'p') " } ,
4 , 1436701368 , 24 , { 0 , " call mkdir('/', 'p') " } ,
4 , 1436701375 , 26 , { 0 , " call mkdir('/tty/tty') " } ,
4 , 1436701383 , 30 , { 0 , " call mkdir('/tty/tty/tty') " } ,
4 , 1436701407 , 35 , { 0 , " call mkdir('/usr/tty/tty', 'p') " } ,
4 , 1436701666 , 35 , { 0 , " call mkdir('/tty/tty/tty', 'p') " } ,
4 , 1436708101 , 25 , { 0 , " echo msgpackdump([1]) " } ,
4 , 1436708966 , 6 , { 0 , " cq " } ,
4 , 1436709606 , 25 , { 0 , " echo msgpackdump([5]) " } ,
4 , 1436709610 , 26 , { 0 , " echo msgpackdump([10]) " } ,
4 , 1436709615 , 31 , { 0 , " echo msgpackdump([5, 5, 5]) " } ,
4 , 1436709618 , 35 , { 0 , " echo msgpackdump([5, 5, 5, 10]) " } ,
4 , 1436709634 , 57 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1}]]) "
} ,
4 , 1436709651 , 67 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}]]) "
} ,
4 , 1436709660 , 70 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}], 0]) "
} ,
4 , 1436710095 , 29 , { 0 , " echo msgpackparse([ \" \\ n \" ]) " } ,
4 , 1436710100 , 28 , { 0 , " echo msgpackparse([ \" j \" ]) " } ,
4 , 1436710109 , 31 , { 0 , " echo msgpackparse([ \" \" , \" \" ]) " } ,
4 , 1436710424 , 33 , { 0 , " echo msgpackparse([ \" \" , \" \\ n \" ]) " } ,
4 , 1436710428 , 32 , { 0 , " echo msgpackparse([ \" \" , \" j \" ]) " } ,
4 , 1436711142 , 14 , { 0 , " echo mpack " } ,
4 , 1436711196 , 45 , { 0 , " let lengths = map(mpack[:], 'len(v:val)') " } ,
4 , 1436711206 , 16 , { 0 , " echo lengths " } ,
4 , 1436711244 , 92 , {
0 ,
( " let sum = len(lengths) - 1 | call map(copy(lengths), "
.. " 'extend(g:, { \" sum \" : sum + v:val})') " )
} ,
4 , 1436711245 , 12 , { 0 , " echo sum " } ,
4 , 1436711398 , 10 , { 0 , " echo s " } ,
4 , 1436711404 , 41 , { 0 , " let mpack = readfile('/tmp/foo', 'b') " } ,
4 , 1436711408 , 41 , { 0 , " let shada_objects=msgpackparse(mpack) " } ,
4 , 1436711415 , 22 , { 0 , " echo shada_objects " } ,
4 , 1436711451 , 30 , { 0 , " e ~/.nvim/shada/main.shada " } ,
4 , 1436711454 , 6 , { 0 , " qa " } ,
4 , 1436711442 , 9 , { 1 , " test " , 47 } ,
4 , 1436711443 , 15 , { 1 , " aontsuesan " , 47 } ,
2 , 1436711443 , 38 , { hlsearch = 1 , pat = " aontsuesan " , smartcase = 1 } ,
2 , 0 , 31 , { islast = 0 , pat = " " , smartcase = 1 , sub = 1 } ,
3 , 0 , 3 , { " " } ,
10 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
1 , 1436711454 , 78 , {
encoding = " utf-8 " ,
max_kbyte = 10 ,
pid = 19269 ,
version = " NVIM 0.0.0-alpha+201507121634 "
} ,
8 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " } ,
8 , 1436711391 , 8 , { file = " " } ,
4 , 1436700940 , 30 , { 0 , " call mkdir('/tmp/tty/tty') " } ,
4 , 1436701355 , 35 , { 0 , " call mkdir('/tmp/tty/tty', 'p') " } ,
4 , 1436701368 , 24 , { 0 , " call mkdir('/', 'p') " } ,
4 , 1436701375 , 26 , { 0 , " call mkdir('/tty/tty') " } ,
4 , 1436701383 , 30 , { 0 , " call mkdir('/tty/tty/tty') " } ,
4 , 1436701407 , 35 , { 0 , " call mkdir('/usr/tty/tty', 'p') " } ,
4 , 1436701666 , 35 , { 0 , " call mkdir('/tty/tty/tty', 'p') " } ,
4 , 1436708101 , 25 , { 0 , " echo msgpackdump([1]) " } ,
4 , 1436708966 , 6 , { 0 , " cq " } ,
4 , 1436709606 , 25 , { 0 , " echo msgpackdump([5]) " } ,
4 , 1436709610 , 26 , { 0 , " echo msgpackdump([10]) " } ,
4 , 1436709615 , 31 , { 0 , " echo msgpackdump([5, 5, 5]) " } ,
4 , 1436709618 , 35 , { 0 , " echo msgpackdump([5, 5, 5, 10]) " } ,
4 , 1436709634 , 57 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1}]]) "
} ,
4 , 1436709651 , 67 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}]]) "
} ,
4 , 1436709660 , 70 , {
0 ,
" echo msgpackdump([5, 5, 5, 10, [10, 20, { \" abc \" : 1, \" def \" : 0}], 0]) "
} ,
4 , 1436710095 , 29 , { 0 , " echo msgpackparse([ \" \\ n \" ]) " } ,
4 , 1436710100 , 28 , { 0 , " echo msgpackparse([ \" j \" ]) " } ,
4 , 1436710109 , 31 , { 0 , " echo msgpackparse([ \" \" , \" \" ]) " } ,
4 , 1436710424 , 33 , { 0 , " echo msgpackparse([ \" \" , \" \\ n \" ]) " } ,
4 , 1436710428 , 32 , { 0 , " echo msgpackparse([ \" \" , \" j \" ]) " } ,
4 , 1436711142 , 14 , { 0 , " echo mpack " } ,
4 , 1436711196 , 45 , { 0 , " let lengths = map(mpack[:], 'len(v:val)') " } ,
4 , 1436711206 , 16 , { 0 , " echo lengths " } ,
4 , 1436711244 , 92 , {
0 ,
( " let sum = len(lengths) - 1 | call map(copy(lengths), "
.. " 'extend(g:, { \" sum \" : sum + v:val})') " )
} ,
4 , 1436711245 , 12 , { 0 , " echo sum " } ,
4 , 1436711398 , 10 , { 0 , " echo s " } ,
4 , 1436711404 , 41 , { 0 , " let mpack = readfile('/tmp/foo', 'b') " } ,
4 , 1436711408 , 41 , { 0 , " let shada_objects=msgpackparse(mpack) " } ,
4 , 1436711415 , 22 , { 0 , " echo shada_objects " } ,
4 , 1436711451 , 30 , { 0 , " e ~/.nvim/shada/main.shada " } ,
4 , 1436711454 , 6 , { 0 , " qa " } ,
4 , 1436711442 , 9 , { 1 , " test " , 47 } ,
4 , 1436711443 , 15 , { 1 , " aontsuesan " , 47 } ,
2 , 1436711443 , 38 , { hlsearch = 1 , pat = " aontsuesan " , smartcase = 1 } ,
2 , 0 , 31 , { islast = 0 , pat = " " , smartcase = 1 , sub = 1 } ,
3 , 0 , 3 , { " " } ,
10 , 1436711451 , 40 , { file = " /home/zyx/.nvim/shada/main.shada " }
}
obj_test ( ' are able to dump and restore rather big object ' , big_obj )
2023-12-07 04:19:35 -07:00
obj_test ( ' are able to dump and restore floating-point value ' , { 0.125 } )
2015-07-16 14:42:53 -07:00
2015-09-18 15:47:37 -07:00
it ( ' can restore and dump UINT64_MAX ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let dumped = [" \\ xCF" . repeat(" \\ xFF", 8)] ' )
command ( ' let parsed = msgpackparse(dumped) ' )
command ( ' let dumped2 = msgpackdump(parsed) ' )
2023-12-07 04:19:35 -07:00
eq ( 1 , eval ( ' type(parsed[0]) == type(0) ' .. ' || parsed[0]._TYPE is v:msgpack_types.integer ' ) )
2015-09-18 15:47:37 -07:00
if eval ( ' type(parsed[0]) == type(0) ' ) == 1 then
2017-06-06 08:37:56 -07:00
command ( ' call assert_equal(0xFFFFFFFFFFFFFFFF, parsed[0]) ' )
eq ( { } , eval ( ' v:errors ' ) )
2015-09-18 15:47:37 -07:00
else
2023-12-07 04:19:35 -07:00
eq ( { _TYPE = { } , _VAL = { 1 , 3 , 0x7FFFFFFF , 0x7FFFFFFF } } , eval ( ' parsed[0] ' ) )
2015-09-18 15:47:37 -07:00
end
eq ( 1 , eval ( ' dumped ==# dumped2 ' ) )
end )
it ( ' can restore and dump INT64_MIN ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let dumped = [" \\ xD3 \\ x80" . repeat(" \\ n", 7)] ' )
command ( ' let parsed = msgpackparse(dumped) ' )
command ( ' let dumped2 = msgpackdump(parsed) ' )
2023-12-07 04:19:35 -07:00
eq ( 1 , eval ( ' type(parsed[0]) == type(0) ' .. ' || parsed[0]._TYPE is v:msgpack_types.integer ' ) )
2015-09-18 15:47:37 -07:00
if eval ( ' type(parsed[0]) == type(0) ' ) == 1 then
2017-06-06 10:38:23 -07:00
command ( ' call assert_equal(-0x7fffffffffffffff - 1, parsed[0]) ' )
2017-06-06 08:37:56 -07:00
eq ( { } , eval ( ' v:errors ' ) )
2015-09-18 15:47:37 -07:00
else
2023-12-07 04:19:35 -07:00
eq ( { _TYPE = { } , _VAL = { - 1 , 2 , 0 , 0 } } , eval ( ' parsed[0] ' ) )
2015-09-18 15:47:37 -07:00
end
eq ( 1 , eval ( ' dumped ==# dumped2 ' ) )
end )
it ( ' can restore and dump BIN string with zero byte ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let dumped = [" \\ xC4 \\ x01 \\ n"] ' )
command ( ' let parsed = msgpackparse(dumped) ' )
command ( ' let dumped2 = msgpackdump(parsed) ' )
2023-12-07 04:19:35 -07:00
eq ( { ' \000 ' } , eval ( ' parsed ' ) )
2015-09-18 15:47:37 -07:00
eq ( 1 , eval ( ' dumped ==# dumped2 ' ) )
end )
it ( ' can restore and dump STR string with zero byte ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let dumped = [" \\ xA1 \\ n"] ' )
command ( ' let parsed = msgpackparse(dumped) ' )
command ( ' let dumped2 = msgpackdump(parsed) ' )
2023-12-07 04:19:35 -07:00
eq ( { { _TYPE = { } , _VAL = { ' \n ' } } } , eval ( ' parsed ' ) )
2015-09-18 15:47:37 -07:00
eq ( 1 , eval ( ' parsed[0]._TYPE is v:msgpack_types.string ' ) )
eq ( 1 , eval ( ' dumped ==# dumped2 ' ) )
end )
it ( ' can restore and dump BIN string with NL ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let dumped = [" \\ xC4 \\ x01", ""] ' )
command ( ' let parsed = msgpackparse(dumped) ' )
command ( ' let dumped2 = msgpackdump(parsed) ' )
2023-12-07 04:19:35 -07:00
eq ( { ' \n ' } , eval ( ' parsed ' ) )
2015-09-18 15:47:37 -07:00
eq ( 1 , eval ( ' dumped ==# dumped2 ' ) )
end )
2016-01-30 11:54:57 -07:00
it ( ' dump and restore special mapping with floating-point value ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.float, "_VAL": 0.125} ' )
2023-12-07 04:19:35 -07:00
eq ( { 0.125 } , eval ( ' msgpackparse(msgpackdump([todump])) ' ) )
2016-01-30 11:54:57 -07:00
end )
2015-09-18 15:47:37 -07:00
end )
2021-07-29 09:46:45 -07:00
local blobstr = function ( list )
local l = { }
2023-12-07 04:19:35 -07:00
for i , v in ipairs ( list ) do
2021-07-29 09:46:45 -07:00
l [ i ] = v : gsub ( ' \n ' , ' \000 ' )
end
return table.concat ( l , ' \n ' )
end
-- Test msgpackparse() with a readfile()-style list and a blob argument
local parse_eq = function ( expect , list_arg )
2023-12-07 04:19:35 -07:00
local blob_expr = ' 0z '
.. blobstr ( list_arg ) : gsub ( ' (.) ' , function ( c )
return ( ' %.2x ' ) : format ( c : byte ( ) )
end )
2024-01-12 10:59:57 -07:00
eq ( expect , fn.msgpackparse ( list_arg ) )
2021-07-29 09:46:45 -07:00
command ( ' let g:parsed = msgpackparse( ' .. blob_expr .. ' ) ' )
eq ( expect , eval ( ' g:parsed ' ) )
end
2015-09-18 15:47:37 -07:00
describe ( ' msgpackparse() function ' , function ( )
before_each ( clear )
2016-02-03 10:04:16 -07:00
it ( ' restores nil as v:null ' , function ( )
2023-12-07 04:19:35 -07:00
parse_eq ( eval ( ' [v:null] ' ) , { ' \192 ' } )
2015-07-12 07:31:55 -07:00
end )
2016-02-03 10:04:16 -07:00
it ( ' restores boolean false as v:false ' , function ( )
2023-12-07 04:19:35 -07:00
parse_eq ( { false } , { ' \194 ' } )
2015-07-12 07:31:55 -07:00
end )
2016-02-03 10:04:16 -07:00
it ( ' restores boolean true as v:true ' , function ( )
2023-12-07 04:19:35 -07:00
parse_eq ( { true } , { ' \195 ' } )
2015-07-12 07:31:55 -07:00
end )
2015-09-18 15:47:37 -07:00
it ( ' restores FIXSTR as special dict ' , function ( )
2023-12-07 04:19:35 -07:00
parse_eq ( { { _TYPE = { } , _VAL = { ' ab ' } } } , { ' \162 ab ' } )
2015-07-16 14:42:53 -07:00
eq ( 1 , eval ( ' g:parsed[0]._TYPE is v:msgpack_types.string ' ) )
2015-07-12 07:31:55 -07:00
end )
2015-09-18 15:47:37 -07:00
it ( ' restores BIN 8 as string ' , function ( )
2023-12-07 04:19:35 -07:00
parse_eq ( { ' ab ' } , { ' \196 \002 ab ' } )
2015-07-12 07:31:55 -07:00
end )
2015-07-16 14:42:53 -07:00
2015-09-18 15:47:37 -07:00
it ( ' restores FIXEXT1 as special dictionary ' , function ( )
2023-12-07 04:19:35 -07:00
parse_eq ( { { _TYPE = { } , _VAL = { 0x10 , { ' ' , ' ' } } } } , { ' \212 \016 ' , ' ' } )
2015-07-16 14:42:53 -07:00
eq ( 1 , eval ( ' g:parsed[0]._TYPE is v:msgpack_types.ext ' ) )
end )
2015-09-18 15:47:37 -07:00
it ( ' restores MAP with BIN key as special dictionary ' , function ( )
2023-12-07 04:19:35 -07:00
parse_eq ( { { _TYPE = { } , _VAL = { { ' a ' , ' ' } } } } , { ' \129 \196 \001 a \196 \n ' } )
2015-07-16 14:42:53 -07:00
eq ( 1 , eval ( ' g:parsed[0]._TYPE is v:msgpack_types.map ' ) )
end )
2015-09-18 15:47:37 -07:00
it ( ' restores MAP with duplicate STR keys as special dictionary ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let dumped = [" \\ x82 \\ xA1a \\ xC4 \\ n \\ xA1a \\ xC4 \\ n"] ' )
2021-07-29 09:46:45 -07:00
-- FIXME Internal error bug, can't use parse_eq() here
2017-04-08 14:12:26 -07:00
command ( ' silent! let parsed = msgpackparse(dumped) ' )
2023-12-07 04:19:35 -07:00
eq ( {
{
_TYPE = { } ,
_VAL = {
{ { _TYPE = { } , _VAL = { ' a ' } } , ' ' } ,
{ { _TYPE = { } , _VAL = { ' a ' } } , ' ' } ,
} ,
} ,
} , eval ( ' parsed ' ) )
2015-07-16 14:42:53 -07:00
eq ( 1 , eval ( ' g:parsed[0]._TYPE is v:msgpack_types.map ' ) )
eq ( 1 , eval ( ' g:parsed[0]._VAL[0][0]._TYPE is v:msgpack_types.string ' ) )
eq ( 1 , eval ( ' g:parsed[0]._VAL[1][0]._TYPE is v:msgpack_types.string ' ) )
end )
2015-09-18 15:47:37 -07:00
it ( ' restores MAP with MAP key as special dictionary ' , function ( )
2023-12-07 04:19:35 -07:00
parse_eq ( { { _TYPE = { } , _VAL = { { { } , ' ' } } } } , { ' \129 \128 \196 \n ' } )
2015-07-16 14:42:53 -07:00
eq ( 1 , eval ( ' g:parsed[0]._TYPE is v:msgpack_types.map ' ) )
end )
2015-09-18 15:47:37 -07:00
it ( ' msgpackparse(systemlist(...)) does not segfault. #3135 ' , function ( )
2023-12-07 04:19:35 -07:00
local cmd = " sort(keys(msgpackparse(systemlist(' " .. helpers.nvim_prog .. " --api-info'))[0])) "
2015-11-17 15:31:22 -07:00
eval ( cmd )
2023-12-07 04:19:35 -07:00
eval ( cmd ) -- do it again (try to force segfault)
local api_info = eval ( cmd ) -- do it again
2022-11-21 17:13:30 -07:00
if is_os ( ' win ' ) then
2022-04-23 03:04:38 -07:00
helpers.assert_alive ( )
pending ( ' msgpackparse() has a bug on windows ' )
return
end
2023-12-07 04:19:35 -07:00
eq ( { ' error_types ' , ' functions ' , ' types ' , ' ui_events ' , ' ui_options ' , ' version ' } , api_info )
2015-07-16 14:42:53 -07:00
end )
2015-09-18 15:52:19 -07:00
it ( ' fails when called with no arguments ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E119: Not enough arguments for function: msgpackparse ' ,
exc_exec ( ' call msgpackparse() ' )
)
2015-09-18 15:52:19 -07:00
end )
it ( ' fails when called with two arguments ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E118: Too many arguments for function: msgpackparse ' ,
exc_exec ( ' call msgpackparse(["", ""], 1) ' )
)
2015-09-18 15:52:19 -07:00
end )
it ( ' fails to parse a string ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E899: Argument of msgpackparse() must be a List or Blob ' ,
exc_exec ( ' call msgpackparse("abcdefghijklmnopqrstuvwxyz") ' )
)
2015-09-18 15:52:19 -07:00
end )
it ( ' fails to parse a number ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E899: Argument of msgpackparse() must be a List or Blob ' ,
exc_exec ( ' call msgpackparse(127) ' )
)
2015-09-18 15:52:19 -07:00
end )
it ( ' fails to parse a dictionary ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E899: Argument of msgpackparse() must be a List or Blob ' ,
exc_exec ( ' call msgpackparse({}) ' )
)
2015-09-18 15:52:19 -07:00
end )
it ( ' fails to parse a funcref ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E899: Argument of msgpackparse() must be a List or Blob ' ,
exc_exec ( ' call msgpackparse(function("tr")) ' )
)
2015-09-18 15:52:19 -07:00
end )
2017-01-03 12:51:29 -07:00
it ( ' fails to parse a partial ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' function T() dict \n endfunction ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E899: Argument of msgpackparse() must be a List or Blob ' ,
exc_exec ( ' call msgpackparse(function("T", [1, 2], {})) ' )
)
2017-01-03 12:51:29 -07:00
end )
2015-09-18 15:52:19 -07:00
it ( ' fails to parse a float ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E899: Argument of msgpackparse() must be a List or Blob ' ,
exc_exec ( ' call msgpackparse(0.0) ' )
)
2015-09-18 15:52:19 -07:00
end )
2021-07-29 09:46:45 -07:00
it ( ' fails on incomplete msgpack string ' , function ( )
local expected = ' Vim(call):E475: Invalid argument: Incomplete msgpack string '
eq ( expected , exc_exec ( [[call msgpackparse(["\xc4"])]] ) )
eq ( expected , exc_exec ( [[call msgpackparse(["\xca", "\x02\x03"])]] ) )
eq ( expected , exc_exec ( ' call msgpackparse(0zc4) ' ) )
eq ( expected , exc_exec ( ' call msgpackparse(0zca0a0203) ' ) )
end )
it ( ' fails when unable to parse msgpack string ' , function ( )
local expected = ' Vim(call):E475: Invalid argument: Failed to parse msgpack string '
eq ( expected , exc_exec ( [[call msgpackparse(["\xc1"])]] ) )
eq ( expected , exc_exec ( ' call msgpackparse(0zc1) ' ) )
end )
2015-09-18 15:47:37 -07:00
end )
2015-07-16 14:42:53 -07:00
2015-09-18 15:47:37 -07:00
describe ( ' msgpackdump() function ' , function ( )
before_each ( clear )
2015-07-16 14:42:53 -07:00
2021-07-29 06:05:55 -07:00
local dump_eq = function ( exp_list , arg_expr )
eq ( exp_list , eval ( ' msgpackdump( ' .. arg_expr .. ' ) ' ) )
2021-07-29 09:46:45 -07:00
eq ( blobstr ( exp_list ) , eval ( ' msgpackdump( ' .. arg_expr .. ' , "B") ' ) )
2021-07-29 06:05:55 -07:00
end
2015-09-18 15:47:37 -07:00
it ( ' dumps string as BIN 8 ' , function ( )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \196 \004 Test ' } , ' ["Test"] ' )
2015-07-16 14:42:53 -07:00
end )
2021-08-02 11:27:52 -07:00
it ( ' dumps blob as BIN 8 ' , function ( )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \196 \005 Bl \n b! ' } , ' [0z426c006221] ' )
2021-08-02 11:27:52 -07:00
end )
2015-07-16 14:42:53 -07:00
it ( ' can dump generic mapping with generic mapping keys and values ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []} ' )
command ( ' let todumpv1 = {"_TYPE": v:msgpack_types.map, "_VAL": []} ' )
command ( ' let todumpv2 = {"_TYPE": v:msgpack_types.map, "_VAL": []} ' )
command ( ' call add(todump._VAL, [todumpv1, todumpv2]) ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \129 \128 \128 ' } , ' [todump] ' )
2015-07-16 14:42:53 -07:00
end )
2016-01-30 15:25:00 -07:00
it ( ' can dump v:true ' , function ( )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \195 ' } , ' [v:true] ' )
2016-01-30 15:25:00 -07:00
end )
it ( ' can dump v:false ' , function ( )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \194 ' } , ' [v:false] ' )
2016-01-30 15:25:00 -07:00
end )
2021-07-29 06:05:55 -07:00
it ( ' can dump v:null ' , function ( )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \192 ' } , ' [v:null] ' )
2016-01-30 16:32:46 -07:00
end )
it ( ' can dump special bool mapping (true) ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 1} ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \195 ' } , ' [todump] ' )
2016-01-30 16:32:46 -07:00
end )
it ( ' can dump special bool mapping (false) ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.boolean, "_VAL": 0} ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \194 ' } , ' [todump] ' )
2016-01-30 16:32:46 -07:00
end )
it ( ' can dump special nil mapping ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.nil, "_VAL": 0} ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \192 ' } , ' [todump] ' )
2016-01-30 15:25:00 -07:00
end )
2016-01-30 11:53:55 -07:00
it ( ' can dump special ext mapping ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]} ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \212 \005 ' , ' ' } , ' [todump] ' )
2015-07-16 14:42:53 -07:00
end )
2016-01-30 11:53:55 -07:00
it ( ' can dump special array mapping ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.array, "_VAL": [5, [""]]} ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \146 \005 \145 \196 \n ' } , ' [todump] ' )
2015-07-16 14:42:53 -07:00
end )
2016-01-30 11:53:55 -07:00
it ( ' can dump special UINT64_MAX mapping ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.integer} ' )
command ( ' let todump._VAL = [1, 3, 0x7FFFFFFF, 0x7FFFFFFF] ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \207 \255 \255 \255 \255 \255 \255 \255 \255 ' } , ' [todump] ' )
2015-07-16 14:42:53 -07:00
end )
2016-01-30 11:53:55 -07:00
it ( ' can dump special INT64_MIN mapping ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.integer} ' )
command ( ' let todump._VAL = [-1, 2, 0, 0] ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \211 \128 \n \n \n \n \n \n \n ' } , ' [todump] ' )
2015-07-16 14:42:53 -07:00
end )
it ( ' fails to dump a function reference ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let Todump = function("tr") ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference ' ,
exc_exec ( ' call msgpackdump([Todump]) ' )
)
2015-07-16 14:42:53 -07:00
end )
2017-01-03 12:51:29 -07:00
it ( ' fails to dump a partial ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' function T() dict \n endfunction ' )
command ( ' let Todump = function("T", [1, 2], {}) ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, itself: attempt to dump function reference ' ,
exc_exec ( ' call msgpackdump([Todump]) ' )
)
2017-01-03 12:51:29 -07:00
end )
2015-07-16 14:42:53 -07:00
it ( ' fails to dump a function reference in a list ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = [function("tr")] ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5004: Error while dumping msgpackdump() argument, index 0, index 0: attempt to dump function reference ' ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2015-07-16 14:42:53 -07:00
end )
it ( ' fails to dump a recursive list ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = [[[]]] ' )
command ( ' call add(todump[0][0], todump) ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 0, index 0 ' ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2015-07-16 14:42:53 -07:00
end )
it ( ' fails to dump a recursive dict ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"d": {"d": {}}} ' )
command ( ' call extend(todump.d.d, {"d": todump}) ' )
2023-12-07 04:19:35 -07:00
eq (
" Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key 'd', key 'd', key 'd' " ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2015-07-16 14:42:53 -07:00
end )
2015-09-20 03:16:37 -07:00
it ( ' can dump dict with two same dicts inside ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let inter = {} ' )
command ( ' let todump = {"a": inter, "b": inter} ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \130 \161 a \128 \161 b \128 ' } , ' [todump] ' )
2015-09-20 03:16:37 -07:00
end )
it ( ' can dump list with two same lists inside ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let inter = [] ' )
command ( ' let todump = [inter, inter] ' )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \146 \144 \144 ' } , ' [todump] ' )
2015-09-20 03:16:37 -07:00
end )
2015-07-16 14:42:53 -07:00
it ( ' fails to dump a recursive list in a special dict ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []} ' )
command ( ' call add(todump._VAL, todump) ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0 ' ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2015-07-16 14:42:53 -07:00
end )
it ( ' fails to dump a recursive (key) map in a special dict ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []} ' )
command ( ' call add(todump._VAL, [todump, 0]) ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0 ' ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2015-07-16 14:42:53 -07:00
end )
it ( ' fails to dump a recursive (val) map in a special dict ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.map, "_VAL": []} ' )
command ( ' call add(todump._VAL, [0, todump]) ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key 0 at index 0 from special map ' ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2016-01-06 12:33:56 -07:00
end )
it ( ' fails to dump a recursive (key) map in a special dict, _VAL reference ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]} ' )
command ( ' call add(todump._VAL[0][0], todump._VAL) ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [[[[...@0], []]]] at index 0 from special map, index 0 ' ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2016-01-06 12:33:56 -07:00
end )
it ( ' fails to dump a recursive (val) map in a special dict, _VAL reference ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[[], []]]} ' )
command ( ' call add(todump._VAL[0][1], todump._VAL) ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in key [] at index 0 from special map, index 0 ' ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2015-07-16 14:42:53 -07:00
end )
2023-12-07 04:19:35 -07:00
it ( ' fails to dump a recursive (val) special list in a special dict ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' let todump = {"_TYPE": v:msgpack_types.array, "_VAL": []} ' )
command ( ' call add(todump._VAL, [0, todump._VAL]) ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E5005: Unable to dump msgpackdump() argument, index 0: container references itself in index 0, index 1 ' ,
exc_exec ( ' call msgpackdump([todump]) ' )
)
2015-08-01 07:24:01 -07:00
end )
2015-09-18 15:52:19 -07:00
it ( ' fails when called with no arguments ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E119: Not enough arguments for function: msgpackdump ' ,
exc_exec ( ' call msgpackdump() ' )
)
2015-09-18 15:52:19 -07:00
end )
2021-07-29 06:05:55 -07:00
it ( ' fails when called with three arguments ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E118: Too many arguments for function: msgpackdump ' ,
exc_exec ( ' call msgpackdump(["", ""], 1, 2) ' )
)
2015-09-18 15:52:19 -07:00
end )
it ( ' fails to dump a string ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E686: Argument of msgpackdump() must be a List ' ,
exc_exec ( ' call msgpackdump("abcdefghijklmnopqrstuvwxyz") ' )
)
2015-09-18 15:52:19 -07:00
end )
it ( ' fails to dump a number ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E686: Argument of msgpackdump() must be a List ' ,
exc_exec ( ' call msgpackdump(127) ' )
)
2015-09-18 15:52:19 -07:00
end )
it ( ' fails to dump a dictionary ' , function ( )
2023-12-07 04:19:35 -07:00
eq ( ' Vim(call):E686: Argument of msgpackdump() must be a List ' , exc_exec ( ' call msgpackdump({}) ' ) )
2015-09-18 15:52:19 -07:00
end )
it ( ' fails to dump a funcref ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E686: Argument of msgpackdump() must be a List ' ,
exc_exec ( ' call msgpackdump(function("tr")) ' )
)
2015-09-18 15:52:19 -07:00
end )
2017-01-03 12:51:29 -07:00
it ( ' fails to dump a partial ' , function ( )
2017-04-08 14:12:26 -07:00
command ( ' function T() dict \n endfunction ' )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E686: Argument of msgpackdump() must be a List ' ,
exc_exec ( ' call msgpackdump(function("T", [1, 2], {})) ' )
)
2017-01-03 12:51:29 -07:00
end )
2015-09-18 15:52:19 -07:00
it ( ' fails to dump a float ' , function ( )
2023-12-07 04:19:35 -07:00
eq (
' Vim(call):E686: Argument of msgpackdump() must be a List ' ,
exc_exec ( ' call msgpackdump(0.0) ' )
)
2015-09-18 15:52:19 -07:00
end )
2016-01-30 15:25:00 -07:00
it ( ' fails to dump special value ' , function ( )
2023-12-07 04:19:35 -07:00
for _ , val in ipairs ( { ' v:true ' , ' v:false ' , ' v:null ' } ) do
eq (
' Vim(call):E686: Argument of msgpackdump() must be a List ' ,
exc_exec ( ' call msgpackdump( ' .. val .. ' ) ' )
)
2016-01-30 15:25:00 -07:00
end
end )
2016-04-03 18:53:07 -07:00
it ( ' can dump NULL string ' , function ( )
2023-12-07 04:19:35 -07:00
dump_eq ( { ' \196 \n ' } , ' [$XXX_UNEXISTENT_VAR_XXX] ' )
dump_eq ( { ' \196 \n ' } , ' [{"_TYPE": v:msgpack_types.binary, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}] ' )
dump_eq ( { ' \160 ' } , ' [{"_TYPE": v:msgpack_types.string, "_VAL": [$XXX_UNEXISTENT_VAR_XXX]}] ' )
2016-04-03 18:53:07 -07:00
end )
2021-08-02 11:27:52 -07:00
it ( ' can dump NULL blob ' , function ( )
2023-12-07 04:19:35 -07:00
eq ( { ' \196 \n ' } , eval ( ' msgpackdump([v:_null_blob]) ' ) )
2021-08-02 11:27:52 -07:00
end )
2016-04-03 18:53:07 -07:00
it ( ' can dump NULL list ' , function ( )
2023-12-07 04:19:35 -07:00
eq ( { ' \144 ' } , eval ( ' msgpackdump([v:_null_list]) ' ) )
2016-04-03 18:53:07 -07:00
end )
it ( ' can dump NULL dictionary ' , function ( )
2023-12-07 04:19:35 -07:00
eq ( { ' \128 ' } , eval ( ' msgpackdump([v:_null_dict]) ' ) )
2016-04-03 18:53:07 -07:00
end )
2015-07-12 07:31:55 -07:00
end )