1
0
mirror of https://github.com/sqlite/sqlite.git synced 2026-10-23 21:49:02 +03:00
Files
sqlite/test/json108.test

123 lines
3.0 KiB
Plaintext

# 2024-03-06
#
# 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.
#
#***********************************************************************
# Invariant tests for JSON built around the randomjson extension
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix json108
# These tests require virtual table "json_tree" to run.
ifcapable !vtab { finish_test ; return }
load_static_extension db randomjson
db eval {
CREATE TEMP TABLE t1(j0,j5);
WITH RECURSIVE c(n) AS (VALUES(0) UNION ALL SELECT n+1 FROM c WHERE n<9)
INSERT INTO t1 SELECT random_json(n), random_json5(n) FROM c;
}
do_execsql_test 1.1 {
SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,NULL));
} 10
do_execsql_test 1.2 {
SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,NULL));
} 10
do_execsql_test 1.3 {
SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,''));
} 10
do_execsql_test 1.4 {
SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,char(9)));
} 10
do_execsql_test 1.5 {
SELECT count(*) FROM t1 WHERE json(j0)==json(json_pretty(j0,'/*hello*/'));
} 10
#-------------------------------------------------------------------------
do_execsql_test 2.0 {
CREATE TABLE obj(x);
INSERT INTO obj VALUES('{name:"value"}');
CREATE TABLE one(y);
INSERT INTO one VALUES(1);
CREATE TABLE zero(z);
}
do_execsql_test 2.1 {
SELECT key, value FROM json_tree(obj.x) JOIN obj;
} {
{} {{"name":"value"}} name value
}
do_catchsql_test 2.2 {
SELECT key, value FROM json_tree(obj.x) LEFT JOIN obj;
} {
1 {table-function argument references tables to its right}
}
do_catchsql_test 2.3 {
SELECT key, value FROM json_tree(obj.x) LEFT JOIN obj WHERE obj.x!='';
} {
1 {table-function argument references tables to its right}
}
do_catchsql_test 2.4 {
SELECT key, value FROM json_tree(obj.x), one LEFT JOIN obj WHERE obj.x!='';
} {
1 {table-function argument references tables to its right}
}
do_execsql_test 2.5 {
SELECT key, value FROM json_tree(obj.x), obj LEFT JOIN one;
} {
{} {{"name":"value"}} name value
}
do_execsql_test 2.6 {
SELECT key, value FROM obj, json_tree(obj.x) LEFT JOIN one;
} {
{} {{"name":"value"}} name value
}
do_execsql_test 2.7 {
SELECT key, value FROM one LEFT JOIN json_tree(obj.x), obj;
} {
{} {{"name":"value"}} name value
}
do_execsql_test 2.8 {
SELECT key, value FROM one LEFT JOIN obj, json_tree(obj.x);
} {
{} {{"name":"value"}} name value
}
do_execsql_test 2.9 {
SELECT key, value FROM zero LEFT JOIN obj, json_tree(obj.x);
} {
}
do_execsql_test 2.10 {
SELECT key, value FROM obj LEFT JOIN json_tree(obj.x);
} {
{} {{"name":"value"}} name value
}
do_execsql_test 2.11 {
SELECT key, value FROM obj LEFT JOIN zero, json_tree(obj.x);
} {
{} {{"name":"value"}} name value
}
finish_test