f2df7e71d6
a json function (other than json_valid()) is not valid JSON. FossilOrigin-Name: dc9ce7b18cbe23d065317757234ef9fb8792da7a
67 lines
2.7 KiB
Plaintext
67 lines
2.7 KiB
Plaintext
# 2015-08-12
|
|
#
|
|
# The author disclaims copyright to this source code. In place of
|
|
# a legal notice, here is a blessing:
|
|
#
|
|
# May you do good and not evil.
|
|
# May you find forgiveness for yourself and forgive others.
|
|
# May you share freely, never taking more than you give.
|
|
#
|
|
#***********************************************************************
|
|
# This file implements tests for JSON SQL functions extension to the
|
|
# SQLite library.
|
|
#
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
|
|
load_static_extension db json
|
|
do_execsql_test json1-1.1 {
|
|
SELECT json_array(1,2.5,null,'hello');
|
|
} {[1,2.5,null,"hello"]}
|
|
do_execsql_test json1-1.2 {
|
|
SELECT hex(json_array('String "\ Test'));
|
|
} {5B22537472696E67205C225C5C2054657374225D}
|
|
do_catchsql_test json1-1.3 {
|
|
SELECT json_array(1,2,x'abcd',3);
|
|
} {1 {JSON cannot hold BLOB values}}
|
|
do_execsql_test json1-1.4 {
|
|
SELECT json_array(-9223372036854775808,9223372036854775807,0,1,-1,
|
|
0.0, 1.0, -1.0, -1e99, +2e100,
|
|
'one','two','three',
|
|
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
|
|
19, NULL, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
|
99);
|
|
} {[-9223372036854775808,9223372036854775807,0,1,-1,0.0,1.0,-1.0,-1.0e+99,2.0e+100,"one","two","three",4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,null,21,22,23,24,25,26,27,28,29,30,31,"abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ",99]}
|
|
|
|
do_execsql_test json1-2.1 {
|
|
SELECT json_object('a',1,'b',2.5,'c',null,'d','String Test');
|
|
} {{{"a":1,"b":2.5,"c":null,"d":"String Test"}}}
|
|
do_catchsql_test json1-2.2 {
|
|
SELECT json_object('a',1,2,2.5);
|
|
} {1 {json_object() labels must be TEXT}}
|
|
do_catchsql_test json1-2.3 {
|
|
SELECT json_object('a',1,'b');
|
|
} {1 {json_object() requires an even number of arguments}}
|
|
do_catchsql_test json1-2.4 {
|
|
SELECT json_object('a',1,'b',x'abcd');
|
|
} {1 {JSON cannot hold BLOB values}}
|
|
|
|
do_execsql_test json1-3.1 {
|
|
SELECT json_replace('{"a":1,"b":2}','$.a','[3,4,5]');
|
|
} {{{"a":"[3,4,5]","b":2}}}
|
|
do_execsql_test json1-3.2 {
|
|
SELECT json_replace('{"a":1,"b":2}','$$.a','[3,4,5]');
|
|
} {{{"a":[3,4,5],"b":2}}}
|
|
do_execsql_test json1-3.3 {
|
|
SELECT json_type(json_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b');
|
|
} {text}
|
|
do_execsql_test json1-3.4 {
|
|
SELECT json_type(json_set('{"a":1,"b":2}','$$.b','{"x":3,"y":4}'),'$.b');
|
|
} {object}
|
|
|
|
finish_test
|