xref: /sqlite-3.40.0/test/json104.test (revision bb7aa2d8)
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_mergepatch(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_merge_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_merge_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_merge_patch('[1,2,3]','{"x":null}');
61} {{{}}}
62do_execsql_test json104-210 {
63  SELECT json_merge_patch('[1,2,3]','{"x":null,"y":1,"z":null}');
64} {{{"y":1}}}
65
66finish_test
67