xref: /sqlite-3.40.0/test/json101.test (revision ecb5fedb)
1# 2015-08-12
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# This file implements tests for JSON SQL functions extension to the
12# SQLite library.
13#
14
15set testdir [file dirname $argv0]
16source $testdir/tester.tcl
17
18load_static_extension db json
19do_execsql_test json1-1.1 {
20  SELECT json_array(1,2.5,null,'hello');
21} {[1,2.5,null,"hello"]}
22do_execsql_test json1-1.2 {
23  SELECT hex(json_array('String "\ Test'));
24} {5B22537472696E67205C225C5C2054657374225D}
25do_catchsql_test json1-1.3 {
26  SELECT json_array(1,2,x'abcd',3);
27} {1 {JSON cannot hold BLOB values}}
28do_execsql_test json1-1.4 {
29  SELECT json_array(-9223372036854775808,9223372036854775807,0,1,-1,
30                    0.0, 1.0, -1.0, -1e99, +2e100,
31                    'one','two','three',
32                    4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
33                    19, NULL, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
34                    'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
35                    'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
36                    'abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ',
37                    99);
38} {[-9223372036854775808,9223372036854775807,0,1,-1,0.0,1.0,-1.0,-1.0e+99,2.0e+100,"one","two","three",4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,null,21,22,23,24,25,26,27,28,29,30,31,"abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ","abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ",99]}
39
40do_execsql_test json1-2.1 {
41  SELECT json_object('a',1,'b',2.5,'c',null,'d','String Test');
42} {{{"a":1,"b":2.5,"c":null,"d":"String Test"}}}
43do_catchsql_test json1-2.2 {
44  SELECT json_object('a',1,2,2.5);
45} {1 {json_object() labels must be TEXT}}
46do_catchsql_test json1-2.3 {
47  SELECT json_object('a',1,'b');
48} {1 {json_object() requires an even number of arguments}}
49do_catchsql_test json1-2.4 {
50  SELECT json_object('a',1,'b',x'abcd');
51} {1 {JSON cannot hold BLOB values}}
52
53do_execsql_test json1-3.1 {
54  SELECT json_replace('{"a":1,"b":2}','$.a','[3,4,5]');
55} {{{"a":"[3,4,5]","b":2}}}
56do_execsql_test json1-3.2 {
57  SELECT json_replace('{"a":1,"b":2}','$$.a','[3,4,5]');
58} {{{"a":[3,4,5],"b":2}}}
59do_execsql_test json1-3.3 {
60  SELECT json_type(json_set('{"a":1,"b":2}','$.b','{"x":3,"y":4}'),'$.b');
61} {text}
62do_execsql_test json1-3.4 {
63  SELECT json_type(json_set('{"a":1,"b":2}','$$.b','{"x":3,"y":4}'),'$.b');
64} {object}
65
66finish_test
67