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 / json108.test

122 lines · 3021 bytes Raw Blame History
1# 2024-03-06
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 json108
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);
24 WITH RECURSIVE c(n) AS (VALUES(0) UNION ALL SELECT n+1 FROM c WHERE n<9)
25 INSERT INTO t1 SELECT random_json(n), random_json5(n) FROM c;
26}
27
28do_execsql_test 1.1 {
29 SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,NULL));
30} 10
31do_execsql_test 1.2 {
32 SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,NULL));
33} 10
34do_execsql_test 1.3 {
35 SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,''));
36} 10
37do_execsql_test 1.4 {
38 SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,char(9)));
39} 10
40do_execsql_test 1.5 {
41 SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,'/*hello*/'));
42} 10
43
44#-------------------------------------------------------------------------
45
46do_execsql_test 2.0 {
47 CREATE TABLE obj(x);
48 INSERT INTO obj VALUES('{name:"value"}');
49
50 CREATE TABLE one(y);
51 INSERT INTO one VALUES(1);
52
53 CREATE TABLE zero(z);
54}
55
56
57do_execsql_test 2.1 {
58 SELECT key, value FROM json_tree(obj.x) JOIN obj;
59} {
60 {} {{"name":"value"}} name value
61}
62
63do_catchsql_test 2.2 {
64 SELECT key, value FROM json_tree(obj.x) LEFT JOIN obj;
65} {
66 1 {table-function argument references tables to its right}
67}
68
69do_catchsql_test 2.3 {
70 SELECT key, value FROM json_tree(obj.x) LEFT JOIN obj WHERE obj.x!='';
71} {
72 1 {table-function argument references tables to its right}
73}
74
75do_catchsql_test 2.4 {
76 SELECT key, value FROM json_tree(obj.x), one LEFT JOIN obj WHERE obj.x!='';
77} {
78 1 {table-function argument references tables to its right}
79}
80
81do_execsql_test 2.5 {
82 SELECT key, value FROM json_tree(obj.x), obj LEFT JOIN one;
83} {
84 {} {{"name":"value"}} name value
85}
86
87do_execsql_test 2.6 {
88 SELECT key, value FROM obj, json_tree(obj.x) LEFT JOIN one;
89} {
90 {} {{"name":"value"}} name value
91}
92
93do_execsql_test 2.7 {
94 SELECT key, value FROM one LEFT JOIN json_tree(obj.x), obj;
95} {
96 {} {{"name":"value"}} name value
97}
98
99do_execsql_test 2.8 {
100 SELECT key, value FROM one LEFT JOIN obj, json_tree(obj.x);
101} {
102 {} {{"name":"value"}} name value
103}
104
105do_execsql_test 2.9 {
106 SELECT key, value FROM zero LEFT JOIN obj, json_tree(obj.x);
107} {
108}
109
110do_execsql_test 2.10 {
111 SELECT key, value FROM obj LEFT JOIN json_tree(obj.x);
112} {
113 {} {{"name":"value"}} name value
114}
115
116do_execsql_test 2.11 {
117 SELECT key, value FROM obj LEFT JOIN zero, json_tree(obj.x);
118} {
119 {} {{"name":"value"}} name value
120}
121
122finish_test