aboutsummaryrefslogtreecommitdiff
path: root/test/functional/eval/json_functions_spec.lua
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-02-05 02:29:10 +0300
committerZyX <kp-pav@yandex.ru>2016-04-18 02:45:49 +0300
commite303ea8a19bcd385eb7829beb7f2ef691c064b35 (patch)
treea9af20db9ba12cdd5002464054829ff4af56e0c8 /test/functional/eval/json_functions_spec.lua
parent2c378fdfaf4927b7071b2e673c19c8acb8dcdfd4 (diff)
downloadrneovim-e303ea8a19bcd385eb7829beb7f2ef691c064b35.tar.gz
rneovim-e303ea8a19bcd385eb7829beb7f2ef691c064b35.tar.bz2
rneovim-e303ea8a19bcd385eb7829beb7f2ef691c064b35.zip
eval/decode: Add support for special maps
Special dictionaries representing map are created when encountering duplicate key or when key is empty or contains NUL. Also checks that values are separated by a comma/colon properly.
Diffstat (limited to 'test/functional/eval/json_functions_spec.lua')
-rw-r--r--test/functional/eval/json_functions_spec.lua52
1 files changed, 52 insertions, 0 deletions
diff --git a/test/functional/eval/json_functions_spec.lua b/test/functional/eval/json_functions_spec.lua
index 7916bc829c..6f81a36479 100644
--- a/test/functional/eval/json_functions_spec.lua
+++ b/test/functional/eval/json_functions_spec.lua
@@ -203,6 +203,19 @@ describe('jsondecode() function', function()
exc_exec('call jsondecode("[}")'))
end)
+ it('fails to parse concat inside container', function()
+ eq('Vim(call):E474: Expected comma before list item: []]',
+ exc_exec('call jsondecode("[[][]]")'))
+ eq('Vim(call):E474: Expected comma before list item: {}]',
+ exc_exec('call jsondecode("[{}{}]")'))
+ eq('Vim(call):E474: Expected comma before list item: ]',
+ exc_exec('call jsondecode("[1 2]")'))
+ eq('Vim(call):E474: Expected comma before dictionary key: ": 4}',
+ exc_exec('call jsondecode("{\\"1\\": 2 \\"3\\": 4}")'))
+ eq('Vim(call):E474: Expected colon before dictionary value: , "3" 4}',
+ exc_exec('call jsondecode("{\\"1\\" 2, \\"3\\" 4}")'))
+ end)
+
it('fails to parse containers with leading comma or colon', function()
eq('Vim(call):E474: Leading comma: ,}',
exc_exec('call jsondecode("{,}")'))
@@ -384,6 +397,45 @@ describe('jsondecode() function', function()
sp_decode_eq({_TYPE='string', _VAL={'\n'}}, '"\\u0000"')
sp_decode_eq({_TYPE='string', _VAL={'\n', '\n'}}, '"\\u0000\\n\\u0000"')
end)
+
+ it('parses dictionaries with duplicate keys to special maps', function()
+ sp_decode_eq({_TYPE='map', _VAL={{'a', 1}, {'a', 2}}},
+ '{"a": 1, "a": 2}')
+ sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'a', 2}}},
+ '{"b": 3, "a": 1, "a": 2}')
+ sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}}},
+ '{"b": 3, "a": 1, "c": 4, "a": 2}')
+ sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}},
+ '{"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}')
+ sp_decode_eq({{_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}},
+ '[{"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}]')
+ sp_decode_eq({{d={_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}}},
+ '[{"d": {"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}}]')
+ sp_decode_eq({1, {d={_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}}},
+ '[1, {"d": {"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}}]')
+ sp_decode_eq({1, {a={}, d={_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'a', 2}, {'c', 4}}}}},
+ '[1, {"a": [], "d": {"b": 3, "a": 1, "c": 4, "a": 2, "c": 4}}]')
+ end)
+
+ it('parses dictionaries with empty keys to special maps', function()
+ sp_decode_eq({_TYPE='map', _VAL={{'', 4}}},
+ '{"": 4}')
+ sp_decode_eq({_TYPE='map', _VAL={{'b', 3}, {'a', 1}, {'c', 4}, {'d', 2}, {'', 4}}},
+ '{"b": 3, "a": 1, "c": 4, "d": 2, "": 4}')
+ sp_decode_eq({_TYPE='map', _VAL={{'', 3}, {'a', 1}, {'c', 4}, {'d', 2}, {'', 4}}},
+ '{"": 3, "a": 1, "c": 4, "d": 2, "": 4}')
+ sp_decode_eq({{_TYPE='map', _VAL={{'', 3}, {'a', 1}, {'c', 4}, {'d', 2}, {'', 4}}}},
+ '[{"": 3, "a": 1, "c": 4, "d": 2, "": 4}]')
+ 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={{'b', 3}, {'a', 1}, {'c', 4}, {'d', 2}, {{_TYPE='string', _VAL={'\n'}}, 4}}},
+ '{"b": 3, "a": 1, "c": 4, "d": 2, "\\u0000": 4}')
+ end)
end)
describe('jsonencode() function', function()