3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # Invariant tests for JSON built around the randomjson extension
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
16 set testprefix json106
18 # These tests require virtual table "json_tree" to run.
19 ifcapable !vtab { finish_test ; return }
21 load_static_extension db randomjson
23 CREATE TEMP TABLE t1(j0,j5,p);
24 CREATE TEMP TABLE kv(n,key,val);
27 for {set ii 1} {$ii<=5000} {incr ii} {
28 do_execsql_test $ii.1 {
30 INSERT INTO t1(j0,j5) VALUES(random_json($ii),random_json5($ii));
31 SELECT json_valid(j0), json_valid(j5,2) FROM t1;
33 do_execsql_test $ii.2 {
35 FROM t1, json_tree(j0) AS rt
36 WHERE rt.type NOT IN ('object','array')
37 AND rt.atom IS NOT (j0 ->> rt.fullkey);
39 do_execsql_test $ii.3 {
41 FROM t1, json_tree(j5) AS rt
42 WHERE rt.type NOT IN ('object','array')
43 AND rt.atom IS NOT (j0 ->> rt.fullkey);
45 do_execsql_test $ii.4 {
48 SELECT rt.rowid, rt.fullkey, rt.atom
49 FROM t1, json_tree(j0) AS rt
50 WHERE rt.type NOT IN ('object','array');
52 do_execsql_test $ii.5 {
55 WHERE key NOT LIKE '%]'
56 AND json_remove(j5,key)->>key IS NOT NULL
58 do_execsql_test $ii.6 {
61 WHERE key NOT LIKE '%]'
62 AND json_insert(json_remove(j5,key),key,val)->>key IS NOT val
64 do_execsql_test $ii.7 {
65 UPDATE t1 SET p=json_patch(j0,j5);
68 WHERE p->>key IS NOT val
70 do_execsql_test $ii.8 {
71 SELECT j0 FROM t1 WHERE json(j0)!=json(json_pretty(j0));
73 do_execsql_test $ii.9 {
74 SELECT j5 FROM t1 WHERE json(j5)!=json(json_pretty(j5));