Mercurial > vim
diff src/testdir/test_json.vim @ 21261:018339de3099 v8.2.1181
patch 8.2.1181: json code not fully tested
Commit: https://github.com/vim/vim/commit/21e5bdd271fa4d0ff4511cf74b160315e1d17cff
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jul 11 14:26:08 2020 +0200
patch 8.2.1181: json code not fully tested
Problem: Json code not fully tested.
Solution: Add more test coverage. (Dominique Pell?, closes https://github.com/vim/vim/issues/6433)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 11 Jul 2020 14:30:05 +0200 |
parents | 947e50e438d3 |
children | 6a4806e326dd |
line wrap: on
line diff
--- a/src/testdir/test_json.vim +++ b/src/testdir/test_json.vim @@ -96,6 +96,12 @@ func Test_json_encode() call assert_equal(s:jsonvals, json_encode(s:varvals)) + " JSON is always encoded in utf-8 regardless of 'encoding' value. + let save_encoding = &encoding + set encoding=latin1 + call assert_equal('"café"', json_encode("caf\xe9")) + let &encoding = save_encoding + call assert_fails('echo json_encode(function("tr"))', 'E474:') call assert_fails('echo json_encode([function("tr")])', 'E474:') @@ -142,6 +148,15 @@ func Test_json_decode() call assert_equal(type(v:none), type(json_decode(''))) call assert_equal("", json_decode('""')) + " Character in string after \ is ignored if not special. + call assert_equal("x", json_decode('"\x"')) + + " JSON is always encoded in utf-8 regardless of 'encoding' value. + let save_encoding = &encoding + set encoding=latin1 + call assert_equal("caf\xe9", json_decode('"café"')) + let &encoding = save_encoding + " empty key is OK call assert_equal({'': 'ok'}, json_decode('{"": "ok"}')) " but not twice @@ -165,6 +180,9 @@ func Test_json_decode() call assert_fails('call json_decode("{\"n\":1,")', "E491:") call assert_fails('call json_decode("{\"n\",1}")', "E491:") call assert_fails('call json_decode("{-}")', "E491:") + if has('float') + call assert_fails('call json_decode("{3.14:1}")', "E474:") + endif call assert_fails('call json_decode("[foobar]")', "E491:") call assert_fails('call json_decode("[")', "E491:") @@ -177,6 +195,9 @@ func Test_json_decode() call assert_fails('call json_decode("{{}:42}")', "E491:") call assert_fails('call json_decode("{[]:42}")', "E491:") + call assert_fails('call json_decode("-")', "E491:") + call assert_fails('call json_decode("infinit")', "E491:") + call assert_fails('call json_decode("\"\\u111Z\"")', 'E491:') call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"')) call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))