CoolFace
Modelpublic

AryaWu/sqlite

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
json106.test80 linesDownload Raw Back to test
1# 2023-12-182#3# The author disclaims copyright to this source code.  In place of4# 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 extension12#13 14set testdir [file dirname $argv0]15source $testdir/tester.tcl16set testprefix json10617 18# These tests require virtual table "json_tree" to run.19ifcapable !vtab { finish_test ; return }20 21load_static_extension db randomjson22db eval {23  CREATE TEMP TABLE t1(j0,j5,p);24  CREATE TEMP TABLE kv(n,key,val);25}26unset -nocomplain ii27for {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 rt36     WHERE rt.type NOT IN ('object','array')37       AND rt.atom IS NOT (j0 ->> rt.fullkey);38  } 039  do_execsql_test $ii.3 {40    SELECT count(*)41      FROM t1, json_tree(j5) AS rt42     WHERE rt.type NOT IN ('object','array')43       AND rt.atom IS NOT (j0 ->> rt.fullkey);44  } 045  do_execsql_test $ii.4 {46    DELETE FROM kv;47    INSERT INTO kv48      SELECT rt.rowid, rt.fullkey, rt.atom49        FROM t1, json_tree(j0) AS rt50       WHERE rt.type NOT IN ('object','array');51  }52  do_execsql_test $ii.5 {53    SELECT count(*)54      FROM t1, kv55     WHERE key NOT LIKE '%]'56       AND json_remove(j5,key)->>key IS NOT NULL57  } 058  do_execsql_test $ii.6 {59    SELECT count(*)60      FROM t1, kv61     WHERE key NOT LIKE '%]'62       AND json_insert(json_remove(j5,key),key,val)->>key IS NOT val63  } 064  do_execsql_test $ii.7 {65    UPDATE t1 SET p=json_patch(j0,j5);66    SELECT count(*)67      FROM t1, kv68     WHERE p->>key IS NOT val69  } 070  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_test80