3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
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.
10 #***********************************************************************
11 # This file implements tests for json_patch(A,B) SQL function.
14 set testdir [file dirname $argv0]
15 source $testdir/tester.tcl
22 # This is the example from pages 2 and 3 of RFC-7396
23 do_execsql_test json104-100 {
36 } {{{"a":"z","c":{"d":"e"}}}}
39 # This is the example from pages 4 and 5 of RFC-7396
40 do_execsql_test json104-110 {
47 "tags":[ "example", "sample" ],
48 "content": "This will be unchanged"
51 "phoneNumber": "+01-123-456-7890",
57 } {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}}}
59 do_execsql_test json104-200 {
60 SELECT json_patch('[1,2,3]','{"x":null}');
62 do_execsql_test json104-210 {
63 SELECT json_patch('[1,2,3]','{"x":null,"y":1,"z":null}');
65 do_execsql_test json104-220 {
66 SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}');
68 do_execsql_test json104-221 {
69 SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,null,3]}}}');
70 } {{{"a":{"bb":{"ccc":[1,null,3]}}}}}
71 do_execsql_test json104-222 {
72 SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}');
73 } {{{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}}}
75 # Example test cases at the end of the RFC-7396 document
76 do_execsql_test json104-300 {
77 SELECT json_patch('{"a":"b"}','{"a":"c"}');
79 do_execsql_test json104-300a {
80 SELECT coalesce(json_patch(null,'{"a":"c"}'), 'real-null');
82 do_execsql_test json104-301 {
83 SELECT json_patch('{"a":"b"}','{"b":"c"}');
84 } {{{"a":"b","b":"c"}}}
85 do_execsql_test json104-302 {
86 SELECT json_patch('{"a":"b"}','{"a":null}');
88 do_execsql_test json104-303 {
89 SELECT json_patch('{"a":"b","b":"c"}','{"a":null}');
91 do_execsql_test json104-304 {
92 SELECT json_patch('{"a":["b"]}','{"a":"c"}');
94 do_execsql_test json104-305 {
95 SELECT json_patch('{"a":"c"}','{"a":["b"]}');
97 do_execsql_test json104-306 {
98 SELECT json_patch('{"a":{"b":"c"}}','{"a":{"b":"d","c":null}}');
100 do_execsql_test json104-307 {
101 SELECT json_patch('{"a":[{"b":"c"}]}','{"a":[1]}');
103 do_execsql_test json104-308 {
104 SELECT json_patch('["a","b"]','["c","d"]');
106 do_execsql_test json104-309 {
107 SELECT json_patch('{"a":"b"}','["c"]');
109 do_execsql_test json104-310 {
110 SELECT json_patch('{"a":"foo"}','null');
112 do_execsql_test json104-310a {
113 SELECT coalesce(json_patch('{"a":"foo"}',null), 'real-null');
115 do_execsql_test json104-311 {
116 SELECT json_patch('{"a":"foo"}','"bar"');
118 do_execsql_test json104-312 {
119 SELECT json_patch('{"e":null}','{"a":1}');
120 } {{{"e":null,"a":1}}}
121 do_execsql_test json104-313 {
122 SELECT json_patch('[1,2]','{"a":"b","c":null}');
124 do_execsql_test json104-314 {
125 SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}');
126 } {{{"a":{"bb":{}}}}}