sqlite/test/json104.test
drh 29c9969871 Fix an error in the new json_patch() routine discovered by Ralf Junker.
FossilOrigin-Name: 9d5350418b2f6113e0b50c57e8a872006f27753067baf08ffdfa7943c0c9a148
2017-03-24 12:35:17 +00:00

77 lines
2.0 KiB
Plaintext

# 2017-03-22
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements tests for json_patch(A,B) SQL function.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
ifcapable !json1 {
finish_test
return
}
# This is the example from pages 2 and 3 of RFC-7396
do_execsql_test json104-100 {
SELECT json_patch('{
"a": "b",
"c": {
"d": "e",
"f": "g"
}
}','{
"a":"z",
"c": {
"f": null
}
}');
} {{{"a":"z","c":{"d":"e"}}}}
# This is the example from pages 4 and 5 of RFC-7396
do_execsql_test json104-110 {
SELECT json_patch('{
"title": "Goodbye!",
"author" : {
"givenName" : "John",
"familyName" : "Doe"
},
"tags":[ "example", "sample" ],
"content": "This will be unchanged"
}','{
"title": "Hello!",
"phoneNumber": "+01-123-456-7890",
"author": {
"familyName": null
},
"tags": [ "example" ]
}');
} {{{"title":"Hello!","author":{"givenName":"John"},"tags":["example"],"content":"This will be unchanged","phoneNumber":"+01-123-456-7890"}}}
do_execsql_test json104-200 {
SELECT json_patch('[1,2,3]','{"x":null}');
} {{{}}}
do_execsql_test json104-210 {
SELECT json_patch('[1,2,3]','{"x":null,"y":1,"z":null}');
} {{{"y":1}}}
do_execsql_test json104-220 {
SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}');
} {{{"a":{"bb":{}}}}}
do_execsql_test json104-221 {
SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,null,3]}}}');
} {{{"a":{"bb":{"ccc":[1,null,3]}}}}}
do_execsql_test json104-222 {
SELECT json_patch('{}','{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}');
} {{{"a":{"bb":{"ccc":[1,{"dddd":null},3]}}}}}
finish_test