interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / test / json106.test

79 lines · 2175 bytes Raw Blame History
1# 2023-12-18
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
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.
9#
10#***********************************************************************
11# Invariant tests for JSON built around the randomjson extension
12#
13
14set testdir [file dirname $argv0]
15source $testdir/tester.tcl
16set testprefix json106
17
18# These tests require virtual table "json_tree" to run.
19ifcapable !vtab { finish_test ; return }
20
21load_static_extension db randomjson
22db eval {
23 CREATE TEMP TABLE t1(j0,j5,p);
24 CREATE TEMP TABLE kv(n,key,val);
25}
26unset -nocomplain ii
27for {set ii 1} {$ii<=5000} {incr ii} {
28 do_execsql_test $ii.1 {
29 DELETE FROM t1;
30 INSERT INTO t1(j0,j5) VALUES(random_json($ii),random_json5($ii));
31 SELECT json_valid(j0), json_valid(j5,2) FROM t1;
32 } {1 1}
33 do_execsql_test $ii.2 {
34 SELECT count(*)
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);
38 } 0
39 do_execsql_test $ii.3 {
40 SELECT count(*)
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);
44 } 0
45 do_execsql_test $ii.4 {
46 DELETE FROM kv;
47 INSERT INTO kv
48 SELECT rt.rowid, rt.fullkey, rt.atom
49 FROM t1, json_tree(j0) AS rt
50 WHERE rt.type NOT IN ('object','array');
51 }
52 do_execsql_test $ii.5 {
53 SELECT count(*)
54 FROM t1, kv
55 WHERE key NOT LIKE '%]'
56 AND json_remove(j5,key)->>key IS NOT NULL
57 } 0
58 do_execsql_test $ii.6 {
59 SELECT count(*)
60 FROM t1, kv
61 WHERE key NOT LIKE '%]'
62 AND json_insert(json_remove(j5,key),key,val)->>key IS NOT val
63 } 0
64 do_execsql_test $ii.7 {
65 UPDATE t1 SET p=json_patch(j0,j5);
66 SELECT count(*)
67 FROM t1, kv
68 WHERE p->>key IS NOT val
69 } 0
70 do_execsql_test $ii.8 {
71 SELECT j0 FROM t1 WHERE json(j0)!=json(json_pretty(j0));
72 } {}
73 do_execsql_test $ii.9 {
74 SELECT j5 FROM t1 WHERE json(j5)!=json(json_pretty(j5));
75 } {}
76}
77
78
79finish_test