# HG changeset patch # User Bram Moolenaar # Date 1594470605 -7200 # Node ID 018339de3099b87ab26adac318b16864e8cf0445 # Parent 57acf261ab51d8510d9e0b9e2efca561da65b970 patch 8.2.1181: json code not fully tested Commit: https://github.com/vim/vim/commit/21e5bdd271fa4d0ff4511cf74b160315e1d17cff Author: Bram Moolenaar 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) diff --git a/src/testdir/test_json.vim b/src/testdir/test_json.vim --- 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 --- 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,