modernc.org/cc@v1.0.1/v2/testdata/_sqlite/test/json104.test (about)

     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  
    14  set testdir [file dirname $argv0]
    15  source $testdir/tester.tcl
    16  
    17  ifcapable !json1 {
    18    finish_test
    19    return
    20  }
    21  
    22  # This is the example from pages 2 and 3 of RFC-7396
    23  do_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 
    40  do_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  
    59  do_execsql_test json104-200 {
    60    SELECT json_patch('[1,2,3]','{"x":null}');
    61  } {{{}}}
    62  do_execsql_test json104-210 {
    63    SELECT json_patch('[1,2,3]','{"x":null,"y":1,"z":null}');
    64  } {{{"y":1}}}
    65  do_execsql_test json104-220 {
    66    SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}');
    67  } {{{"a":{"bb":{}}}}}
    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]}}}}}
    74  
    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"}');
    78  } {{{"a":"c"}}}
    79  do_execsql_test json104-300a {
    80    SELECT coalesce(json_patch(null,'{"a":"c"}'), 'real-null');
    81  } {{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}');
    87  } {{{}}}
    88  do_execsql_test json104-303 {
    89    SELECT json_patch('{"a":"b","b":"c"}','{"a":null}');
    90  } {{{"b":"c"}}}
    91  do_execsql_test json104-304 {
    92    SELECT json_patch('{"a":["b"]}','{"a":"c"}');
    93  } {{{"a":"c"}}}
    94  do_execsql_test json104-305 {
    95    SELECT json_patch('{"a":"c"}','{"a":["b"]}');
    96  } {{{"a":["b"]}}}
    97  do_execsql_test json104-306 {
    98    SELECT json_patch('{"a":{"b":"c"}}','{"a":{"b":"d","c":null}}');
    99  } {{{"a":{"b":"d"}}}}
   100  do_execsql_test json104-307 {
   101    SELECT json_patch('{"a":[{"b":"c"}]}','{"a":[1]}');
   102  } {{{"a":[1]}}}
   103  do_execsql_test json104-308 {
   104    SELECT json_patch('["a","b"]','["c","d"]');
   105  } {{["c","d"]}}
   106  do_execsql_test json104-309 {
   107    SELECT json_patch('{"a":"b"}','["c"]');
   108  } {{["c"]}}
   109  do_execsql_test json104-310 {
   110    SELECT json_patch('{"a":"foo"}','null');
   111  } {{null}}
   112  do_execsql_test json104-310a {
   113    SELECT coalesce(json_patch('{"a":"foo"}',null), 'real-null');
   114  } {{real-null}}
   115  do_execsql_test json104-311 {
   116    SELECT json_patch('{"a":"foo"}','"bar"');
   117  } {{"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}');
   123  } {{{"a":"b"}}}
   124  do_execsql_test json104-314 {
   125    SELECT json_patch('{}','{"a":{"bb":{"ccc":null}}}');
   126  } {{{"a":{"bb":{}}}}}
   127  
   128  
   129  
   130  finish_test