1# 2017-03-22 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_patch(A,B) SQL function. 12# 13 14set testdir [file dirname $argv0] 15source $testdir/tester.tcl 16 17ifcapable !json1 { 18 finish_test 19 return 20} 21 22# This is the example from pages 2 and 3 of RFC-7396 23do_execsql_test json104-100 { 24 SELECT json_patch('{ 25 "a": "b", 26 "c": { 27 "d": "e", 28 "f": "g" 29 } 30 }','{ 31 "a":"z", 32 "c": { 33 "f": null 34 } 35 }'); 36} {{{"a":"z","c":{"d":"e"}}}} 37 38 39# This is the example from pages 4 and 5 of RFC-7396 40do_execsql_test json104-110 { 41 SELECT json_patch('{ 42 "title": "Goodbye!", 43 "author" : { 44 "givenName" : "John", 45 "familyName" : "Doe" 46 }, 47 "tags":[ "example", "sample" ], 48 "content": "This will be unchanged" 49 }','{ 50 "title": "Hello!", 51 "phoneNumber": "+01-123-456-7890", 52 "author": { 53 "familyName": null 54 }, 55 "tags": [ "example" ] 56 }'); 57} {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}}} 58 59do_execsql_test json104-200 { 60 SELECT json_patch('[1,2,3]','{"x":null}'); 61} {{{}}} 62do_execsql_test json104-210 { 63 SELECT json_patch('[1,2,3]','{"x":null,"y":1,"z":null}'); 64} {{{"y":1}}} 65do_execsql_test json104-220 { 66 SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}'); 67} {{{"a":{"bb":{}}}}} 68do_execsql_test json104-221 { 69 SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,null,3]}}}'); 70} {{{"a":{"bb":{"ccc":[1,null,3]}}}}} 71do_execsql_test json104-222 { 72 SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}'); 73} {{{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}}} 74 75# Example test cases at the end of the RFC-7396 document 76do_execsql_test json104-300 { 77 SELECT json_patch('{"a":"b"}','{"a":"c"}'); 78} {{{"a":"c"}}} 79do_execsql_test json104-300a { 80 SELECT coalesce(json_patch(null,'{"a":"c"}'), 'real-null'); 81} {{real-null}} 82do_execsql_test json104-301 { 83 SELECT json_patch('{"a":"b"}','{"b":"c"}'); 84} {{{"a":"b","b":"c"}}} 85do_execsql_test json104-302 { 86 SELECT json_patch('{"a":"b"}','{"a":null}'); 87} {{{}}} 88do_execsql_test json104-303 { 89 SELECT json_patch('{"a":"b","b":"c"}','{"a":null}'); 90} {{{"b":"c"}}} 91do_execsql_test json104-304 { 92 SELECT json_patch('{"a":["b"]}','{"a":"c"}'); 93} {{{"a":"c"}}} 94do_execsql_test json104-305 { 95 SELECT json_patch('{"a":"c"}','{"a":["b"]}'); 96} {{{"a":["b"]}}} 97do_execsql_test json104-306 { 98 SELECT json_patch('{"a":{"b":"c"}}','{"a":{"b":"d","c":null}}'); 99} {{{"a":{"b":"d"}}}} 100do_execsql_test json104-307 { 101 SELECT json_patch('{"a":[{"b":"c"}]}','{"a":[1]}'); 102} {{{"a":[1]}}} 103do_execsql_test json104-308 { 104 SELECT json_patch('["a","b"]','["c","d"]'); 105} {{["c","d"]}} 106do_execsql_test json104-309 { 107 SELECT json_patch('{"a":"b"}','["c"]'); 108} {{["c"]}} 109do_execsql_test json104-310 { 110 SELECT json_patch('{"a":"foo"}','null'); 111} {{null}} 112do_execsql_test json104-310a { 113 SELECT coalesce(json_patch('{"a":"foo"}',null), 'real-null'); 114} {{real-null}} 115do_execsql_test json104-311 { 116 SELECT json_patch('{"a":"foo"}','"bar"'); 117} {{"bar"}} 118do_execsql_test json104-312 { 119 SELECT json_patch('{"e":null}','{"a":1}'); 120} {{{"e":null,"a":1}}} 121do_execsql_test json104-313 { 122 SELECT json_patch('[1,2]','{"a":"b","c":null}'); 123} {{{"a":"b"}}} 124do_execsql_test json104-314 { 125 SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}'); 126} {{{"a":{"bb":{}}}}} 127 128 129 130finish_test 131