aboutsummaryrefslogtreecommitdiff
path: root/test/functional/vimscript/json_functions_spec.lua
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-06-25 15:33:47 +0200
committerbfredl <bjorn.linse@gmail.com>2024-06-27 11:04:04 +0200
commitbda63d5b97dfb333de6f4bd757dbb978906062a2 (patch)
tree65b2460064f42b39e33bf7bc7507f973b907dd37 /test/functional/vimscript/json_functions_spec.lua
parent9e436251de0329b1479365ff162d87ef18d6d14c (diff)
downloadrneovim-bda63d5b97dfb333de6f4bd757dbb978906062a2.tar.gz
rneovim-bda63d5b97dfb333de6f4bd757dbb978906062a2.tar.bz2
rneovim-bda63d5b97dfb333de6f4bd757dbb978906062a2.zip
refactor(typval)!: remove distinction of binary and nonbinary strings
This is a breaking change which will make refactor of typval and shada code a lot easier. In particular, code that would use or check for v:msgpack_types.binary in the wild would be broken. This appears to be rarely used in existing plugins. Also some cases where v:msgpack_type.string would be used to represent a binary string of "string" type, we use a BLOB instead, which is vimscripts native type for binary blobs, and already was used for BIN formats when necessary. msgpackdump(msgpackparse(data)) no longer preserves the distinction of BIN and STR strings. This is very common behavior for language-specific msgpack bindings. Nvim uses msgpack as a tool to serialize its data. Nvim is not a tool to bit-perfectly manipulate arbitrary msgpack data out in the wild. The changed tests should indicate how behavior changes in various edge cases.
Diffstat (limited to 'test/functional/vimscript/json_functions_spec.lua')
-rw-r--r--test/functional/vimscript/json_functions_spec.lua32
1 files changed, 6 insertions, 26 deletions
diff --git a/test/functional/vimscript/json_functions_spec.lua b/test/functional/vimscript/json_functions_spec.lua
index ae56e8873d..c6e0e75bdc 100644
--- a/test/functional/vimscript/json_functions_spec.lua
+++ b/test/functional/vimscript/json_functions_spec.lua
@@ -502,9 +502,9 @@ describe('json_decode() function', function()
end
it('parses strings with NUL properly', function()
- sp_decode_eq({ _TYPE = 'string', _VAL = { '\n' } }, '"\\u0000"')
- sp_decode_eq({ _TYPE = 'string', _VAL = { '\n', '\n' } }, '"\\u0000\\n\\u0000"')
- sp_decode_eq({ _TYPE = 'string', _VAL = { '\n«\n' } }, '"\\u0000\\u00AB\\u0000"')
+ sp_decode_eq('\000', '"\\u0000"')
+ sp_decode_eq('\000\n\000', '"\\u0000\\n\\u0000"')
+ sp_decode_eq('\000«\000', '"\\u0000\\u00AB\\u0000"')
end)
it('parses dictionaries with duplicate keys to special maps', function()
@@ -580,14 +580,8 @@ describe('json_decode() function', function()
end)
it('parses dictionaries with keys with NUL bytes to special maps', function()
- sp_decode_eq(
- { _TYPE = 'map', _VAL = { { { _TYPE = 'string', _VAL = { 'a\n', 'b' } }, 4 } } },
- '{"a\\u0000\\nb": 4}'
- )
- sp_decode_eq(
- { _TYPE = 'map', _VAL = { { { _TYPE = 'string', _VAL = { 'a\n', 'b', '' } }, 4 } } },
- '{"a\\u0000\\nb\\n": 4}'
- )
+ sp_decode_eq({ _TYPE = 'map', _VAL = { { 'a\000\nb', 4 } } }, '{"a\\u0000\\nb": 4}')
+ sp_decode_eq({ _TYPE = 'map', _VAL = { { 'a\000\nb\n', 4 } } }, '{"a\\u0000\\nb\\n": 4}')
sp_decode_eq({
_TYPE = 'map',
_VAL = {
@@ -595,10 +589,7 @@ describe('json_decode() function', function()
{ 'a', 1 },
{ 'c', 4 },
{ 'd', 2 },
- {
- { _TYPE = 'string', _VAL = { '\n' } },
- 4,
- },
+ { '\000', 4 },
},
}, '{"b": 3, "a": 1, "c": 4, "d": 2, "\\u0000": 4}')
end)
@@ -738,22 +729,11 @@ describe('json_encode() function', function()
eq('{"\\u0000": 1}', eval('json_encode(todump)'))
end)
- it('can dump generic mapping with BIN special key and NUL', function()
- command('let todump = {"_TYPE": v:msgpack_types.binary, "_VAL": ["\\n"]}')
- command('let todump = {"_TYPE": v:msgpack_types.map, "_VAL": [[todump, 1]]}')
- eq('{"\\u0000": 1}', eval('json_encode(todump)'))
- end)
-
it('can dump STR special mapping with NUL and NL', function()
command('let todump = {"_TYPE": v:msgpack_types.string, "_VAL": ["\\n", ""]}')
eq('"\\u0000\\n"', eval('json_encode(todump)'))
end)
- it('can dump BIN special mapping with NUL and NL', function()
- command('let todump = {"_TYPE": v:msgpack_types.binary, "_VAL": ["\\n", ""]}')
- eq('"\\u0000\\n"', eval('json_encode(todump)'))
- end)
-
it('cannot dump special ext mapping', function()
command('let todump = {"_TYPE": v:msgpack_types.ext, "_VAL": [5, ["",""]]}')
eq('Vim(call):E474: Unable to convert EXT string to JSON', exc_exec('call json_encode(todump)'))