aboutsummaryrefslogtreecommitdiff
path: root/test/json101.test
diff options
context:
space:
mode:
Diffstat (limited to 'test/json101.test')
-rw-r--r--test/json101.test69
1 files changed, 43 insertions, 26 deletions
diff --git a/test/json101.test b/test/json101.test
index 9543ccfd2..943292640 100644
--- a/test/json101.test
+++ b/test/json101.test
@@ -16,28 +16,28 @@ set testdir [file dirname $argv0]
source $testdir/tester.tcl
load_static_extension db json
-do_execsql_test json1-1.1.00 {
+do_execsql_test json101-1.1.00 {
SELECT json_array(1,2.5,null,'hello');
} {[1,2.5,null,"hello"]}
-do_execsql_test json1-1.1.01 {
+do_execsql_test json101-1.1.01 {
SELECT json_array(1,'{"abc":2.5,"def":null,"ghi":hello}',99);
-- the second term goes in as a string:
} {[1,"{\\"abc\\":2.5,\\"def\\":null,\\"ghi\\":hello}",99]}
-do_execsql_test json1-1.1.02 {
+do_execsql_test json101-1.1.02 {
SELECT json_array(1,json('{"abc":2.5,"def":null,"ghi":"hello"}'),99);
-- the second term goes in as JSON
} {[1,{"abc":2.5,"def":null,"ghi":"hello"},99]}
-do_execsql_test json1-1.1.03 {
+do_execsql_test json101-1.1.03 {
SELECT json_array(1,json_object('abc',2.5,'def',null,'ghi','hello'),99);
-- the second term goes in as JSON
} {[1,{"abc":2.5,"def":null,"ghi":"hello"},99]}
-do_execsql_test json1-1.2 {
+do_execsql_test json101-1.2 {
SELECT hex(json_array('String "\ Test'));
} {5B22537472696E67205C225C5C2054657374225D}
-do_catchsql_test json1-1.3 {
- SELECT json_array(1,2,x'abcd',3);
+do_catchsql_test json101-1.3 {
+ SELECT json_array(1,printf('%.1000c','x'),x'abcd',3);
} {1 {JSON cannot hold BLOB values}}
-do_execsql_test json1-1.4 {
+do_execsql_test json101-1.4 {
SELECT json_array(-9223372036854775808,9223372036854775807,0,1,-1,
0.0, 1.0, -1.0, -1e99, +2e100,
'one','two','three',
@@ -49,36 +49,41 @@ do_execsql_test json1-1.4 {
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 {
+do_execsql_test json101-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);
+do_catchsql_test json101-2.2 {
+ SELECT json_object('a',printf('%.1000c','x'),2,2.5);
} {1 {json_object() labels must be TEXT}}
-do_catchsql_test json1-2.3 {
+do_catchsql_test json101-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');
+do_catchsql_test json101-2.4 {
+ SELECT json_object('a',printf('%.1000c','x'),'b',x'abcd');
} {1 {JSON cannot hold BLOB values}}
-do_execsql_test json1-3.1 {
+do_execsql_test json101-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 {
+do_execsql_test json101-3.2 {
SELECT json_replace('{"a":1,"b":2}','$.a',json('[3,4,5]'));
} {{{"a":[3,4,5],"b":2}}}
-do_execsql_test json1-3.3 {
+do_execsql_test json101-3.3 {
SELECT json_type(json_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b');
} {text}
-do_execsql_test json1-3.4 {
+do_execsql_test json101-3.4 {
SELECT json_type(json_set('{"a":1,"b":2}','$.b',json('{"x":3,"y":4}')),'$.b');
} {object}
+ifcapable vtab {
+do_execsql_test json101-3.5 {
+ SELECT fullkey, atom, '|' FROM json_tree(json_set('{}','$.x',123,'$.x',456));
+} {{$} {} | {$.x} 456 |}
+}
# Per rfc7159, any JSON value is allowed at the top level, and whitespace
# is permitting before and/or after that value.
#
-do_execsql_test json1-4.1 {
+do_execsql_test json101-4.1 {
CREATE TABLE j1(x);
INSERT INTO j1(x)
VALUES('true'),('false'),('null'),('123'),('-234'),('34.5e+6'),
@@ -87,32 +92,32 @@ do_execsql_test json1-4.1 {
('{"a":true,"b":{"c":false}}');
SELECT * FROM j1 WHERE NOT json_valid(x);
} {}
-do_execsql_test json1-4.2 {
+do_execsql_test json101-4.2 {
SELECT * FROM j1 WHERE NOT json_valid(char(0x20,0x09,0x0a,0x0d)||x);
} {}
-do_execsql_test json1-4.3 {
+do_execsql_test json101-4.3 {
SELECT * FROM j1 WHERE NOT json_valid(x||char(0x20,0x09,0x0a,0x0d));
} {}
# But an empty string, or a string of pure whitespace is not valid JSON.
#
-do_execsql_test json1-4.4 {
+do_execsql_test json101-4.4 {
SELECT json_valid(''), json_valid(char(0x20,0x09,0x0a,0x0d));
} {0 0}
# json_remove() and similar functions with no edit operations return their
# input unchanged.
#
-do_execsql_test json1-4.5 {
+do_execsql_test json101-4.5 {
SELECT x FROM j1 WHERE json_remove(x)<>x;
} {}
-do_execsql_test json1-4.6 {
+do_execsql_test json101-4.6 {
SELECT x FROM j1 WHERE json_replace(x)<>x;
} {}
-do_execsql_test json1-4.7 {
+do_execsql_test json101-4.7 {
SELECT x FROM j1 WHERE json_set(x)<>x;
} {}
-do_execsql_test json1-4.8 {
+do_execsql_test json101-4.8 {
SELECT x FROM j1 WHERE json_insert(x)<>x;
} {}
@@ -302,6 +307,18 @@ do_execsql_test json-5.8 {
WHERE jx.value<>jx.atom AND type NOT IN ('array','object');
} {}
+do_execsql_test json-6.1 {
+ SELECT json_valid('{"a":55,"b":72,}');
+} {0}
+do_execsql_test json-6.2 {
+ SELECT json_valid('{"a":55,"b":72}');
+} {1}
+do_execsql_test json-6.3 {
+ SELECT json_valid('["a",55,"b",72,]');
+} {0}
+do_execsql_test json-6.4 {
+ SELECT json_valid('["a",55,"b",72]');
+} {1}
finish_test