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

72 lines · 2291 bytes Raw Blame History
1# 2026-01-17
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#
12# Test cases for json_array_insert().
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17set testprefix json109
18
19do_execsql_test 1.1 {
20 SELECT json_array_insert('[1,2,3]','$[0]',999,'$[0]',888);
21} {{[888,999,1,2,3]}}
22do_execsql_test 1.2 {
23 SELECT json_array_insert('[1,2,3]','$[0]',999,'$[#]',888);
24} {{[999,1,2,3,888]}}
25do_execsql_test 1.3 {
26 SELECT json_array_insert('[1,2,3]','$[1]',888);
27} {{[1,888,2,3]}}
28do_execsql_test 1.4 {
29 SELECT json_array_insert('[1,2,3]','$[2]',888);
30} {{[1,2,888,3]}}
31do_execsql_test 1.5 {
32 SELECT json_array_insert('[1,2,3]','$[3]',888);
33} {{[1,2,3,888]}}
34do_execsql_test 1.6 {
35 SELECT json_array_insert('[1,2,3]','$[#-1]',888);
36} {{[1,2,888,3]}}
37do_execsql_test 1.7 {
38 SELECT json_array_insert('[1,2,3]','$[#-2]',888);
39} {{[1,888,2,3]}}
40do_execsql_test 1.8 {
41 SELECT json_array_insert('[1,2,3]','$[#-3]',888);
42} {{[888,1,2,3]}}
43do_execsql_test 1.9 {
44 SELECT json_array_insert('[1,2,3]','$[#-4]',888);
45} {{[1,2,3]}}
46
47do_catchsql_test 2.1 {
48 SELECT json_array_insert('{a:[1,2,3]}','$.a',888);
49} {1 {not an array element: '$.a'}}
50do_catchsql_test 2.2 {
51 SELECT json_array_insert('{a:[1,2,3]}','$.b',888);
52} {1 {not an array element: '$.b'}}
53do_catchsql_test 2.3 {
54 SELECT json_array_insert('{a:[1,2,3]}','$.b[0]',888);
55} {0 {{{"a":[1,2,3],"b":[888]}}}}
56do_catchsql_test 2.4 {
57 SELECT json_array_insert('{a:[1,2,3]}','$.b.c.d[0]',888);
58} {0 {{{"a":[1,2,3],"b":{"c":{"d":[888]}}}}}}
59do_catchsql_test 2.5 {
60 SELECT json_array_insert('{a:[1,2,3]}','$.b.c.d[0',888);
61} {1 {not an array element: '$.b.c.d[0'}}
62do_catchsql_test 2.6 {
63 SELECT json_array_insert('{a:[1,2,3]}','$.b.c.d',888);
64} {1 {not an array element: '$.b.c.d'}}
65do_catchsql_test 2.7 {
66 SELECT json_array_insert('{a:[1,2,3]}','$[0]',888);
67} {0 {{{"a":[1,2,3]}}}}
68do_catchsql_test 2.8 {
69 SELECT json_array_insert('{a:[1,2,3]}','$.b[0]',888,'$.a[1]','999','$.c',0);
70} {1 {not an array element: '$.c'}}
71
72finish_test