diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-07-11 14:26:08 +0200 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-07-11 14:26:08 +0200 |
commit | 21e5bdd271fa4d0ff4511cf74b160315e1d17cff (patch) | |
tree | 150a740c474e63e7d4acd14972c69eec60cef83d | |
parent | 1e624c912dff19e889c9398b56fe537952c02fef (diff) |
patch 8.2.1181: json code not fully testedv8.2.1181
Problem: Json code not fully tested.
Solution: Add more test coverage. (Dominique Pellé, closes #6433)
-rw-r--r-- | src/testdir/test_json.vim | 21 | ||||
-rw-r--r-- | src/version.c | 2 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/testdir/test_json.vim b/src/testdir/test_json.vim index 6c11ace187..86c47ae9dc 100644 --- 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"')) diff --git a/src/version.c b/src/version.c index 23ea21eb23..bbb2c28f8b 100644 --- a/src/version.c +++ b/src/version.c @@ -755,6 +755,8 @@ static char *(features[]) = static int included_patches[] = { /* Add new patch number below this line */ /**/ + 1181, +/**/ 1180, /**/ 1179, |