0
0
mirror of https://github.com/vim/vim.git synced 2025-09-25 03:54:15 -04:00

patch 8.2.1181: json code not fully tested

Problem:    Json code not fully tested.
Solution:   Add more test coverage. (Dominique Pellé, closes #6433)
This commit is contained in:
Bram Moolenaar
2020-07-11 14:26:08 +02:00
parent 1e624c912d
commit 21e5bdd271
2 changed files with 23 additions and 0 deletions

View File

@@ -96,6 +96,12 @@ func Test_json_encode()
call assert_equal(s:jsonvals, json_encode(s:varvals)) 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:')
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(type(v:none), type(json_decode('')))
call assert_equal("", 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 " empty key is OK
call assert_equal({'': 'ok'}, json_decode('{"": "ok"}')) call assert_equal({'': 'ok'}, json_decode('{"": "ok"}'))
" but not twice " 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("{\"n\",1}")', "E491:") call assert_fails('call json_decode("{\"n\",1}")', "E491:")
call assert_fails('call json_decode("{-}")', "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("[foobar]")', "E491:")
call assert_fails('call json_decode("[")', "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("{[]: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_fails('call json_decode("\"\\u111Z\"")', 'E491:')
call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"')) call assert_equal('[😂]', json_decode('"[\uD83D\uDE02]"'))
call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"')) call assert_equal('a😂b', json_decode('"a\uD83D\uDE02b"'))

View File

@@ -754,6 +754,8 @@ static char *(features[]) =
static int included_patches[] = static int included_patches[] =
{ /* Add new patch number below this line */ { /* Add new patch number below this line */
/**/
1181,
/**/ /**/
1180, 1180,
/**/ /**/