mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-19 23:15:28 +01:00
chore: add tests
This commit is contained in:
@@ -291,6 +291,14 @@ do_execsql_test json_arrow_blob_array {
|
||||
SELECT x'7B0707070707177D' -> '$[5]'
|
||||
} {\"\}\"}
|
||||
|
||||
# Tests against valid jsonb [b'[',.., b']'] vs json text '[..]'
|
||||
# b'[' = ElementType::Array, PayloadSize of 5.
|
||||
# b']' = last element in array ends in ']'
|
||||
# x'5B070707175D' = jsonb(["", "", "", "}"])
|
||||
do_execsql_test json_arrow_blob_array_2 {
|
||||
SELECT x'5B070707175D' -> '$[3]'
|
||||
} {\"\]\"}
|
||||
|
||||
do_execsql_test json_arrow_blob_number {
|
||||
SELECT cast('4' as blob) -> '$'
|
||||
} {{4}}
|
||||
@@ -307,9 +315,10 @@ do_execsql_test json_arrow_blob_number_3 {
|
||||
do_execsql_test json_arrow_blob_negative_number {
|
||||
SELECT cast('-4' as blob) -> '$'
|
||||
} {{-4}}
|
||||
do_execsql_test json_arrow_shift_object {
|
||||
SELECT '{"a": [1,2,3]}' ->> '$.a'
|
||||
} {{[1,2,3]}}
|
||||
|
||||
do_execsql_test json_arrow_shift_blob {
|
||||
SELECT cast('{"age":30,"name":"John"}' as blob) ->> '$.age'
|
||||
} {{30}}
|
||||
|
||||
do_execsql_test json_extract_object_2 {
|
||||
SELECT json_extract('{"a": [1,2,3]}', '$.a', '$.a[0]', '$.a[1]', '$.a[3]')
|
||||
@@ -537,10 +546,9 @@ do_execsql_test json_extract_overflow_int64 {
|
||||
# SELECT json_extract('[1, 2, 3]', '$[170141183460469231731687303715884105729]');
|
||||
#} {{2}}
|
||||
|
||||
# TODO: fix me - this passes on SQLite and needs to be fixed in Limbo.
|
||||
#do_execsql_test json_extract_blob {
|
||||
# select json_extract(CAST('[1,2,3]' as BLOB), '$[1]')
|
||||
#} {{2}}
|
||||
do_execsql_test json_extract_blob {
|
||||
select json_extract(CAST('[1,2,3]' as BLOB), '$[1]')
|
||||
} {{2}}
|
||||
|
||||
do_execsql_test json_array_length {
|
||||
SELECT json_array_length('[1,2,3,4]');
|
||||
@@ -707,12 +715,11 @@ do_execsql_test json_valid_1 {
|
||||
do_execsql_test json_valid_2 {
|
||||
SELECT json_valid('["a",55,"b",72]');
|
||||
} {1}
|
||||
#
|
||||
# Unimplemented
|
||||
#do_execsql_test json_valid_3 {
|
||||
# SELECT json_valid( CAST('{"a":"1}' AS BLOB) );
|
||||
#} {0}
|
||||
#
|
||||
|
||||
do_execsql_test json_valid_3 {
|
||||
SELECT json_valid( CAST('{"a":"1}' AS BLOB) );
|
||||
} {0}
|
||||
|
||||
do_execsql_test json_valid_4 {
|
||||
SELECT json_valid(123);
|
||||
} {1}
|
||||
@@ -857,6 +864,14 @@ do_execsql_test json-remove-7 {
|
||||
SELECT json_remove('{"a": 1, "b": [1,2], "c": {"d": 3}}', '$.a', '$.b[0]', '$.c.d');
|
||||
} {{{"b":[2],"c":{}}}}
|
||||
|
||||
do_execsql_test json-remove-8 {
|
||||
SELECT json_remove(cast('{"age":30,"name":"John"}' as blob), '$.age');
|
||||
} {{{"name":"John"}}}
|
||||
|
||||
do_execsql_test json-remove-9 {
|
||||
SELECT json_remove(cast('{"user":{"id":123,"profile":{"name":"Alice","age":25}}}' as blob), '$.user.id');
|
||||
} {{{"user":{"profile":{"name":"Alice","age":25}}}}}
|
||||
|
||||
do_execsql_test json_set_field_empty_object {
|
||||
SELECT json_set('{}', '$.field', 'value');
|
||||
} {{{"field":"value"}}}
|
||||
@@ -865,6 +880,10 @@ do_execsql_test json_set_replace_field {
|
||||
SELECT json_set('{"field":"old_value"}', '$.field', 'new_value');
|
||||
} {{{"field":"new_value"}}}
|
||||
|
||||
do_execsql_test json_set_replace_field_2 {
|
||||
SELECT json_set(cast('{"age":30,"name":"John"}' as blob), '$.age', 40);
|
||||
} {{{"age":40,"name":"John"}}}
|
||||
|
||||
do_execsql_test json_set_set_deeply_nested_key {
|
||||
SELECT json_set('{}', '$.object.doesnt.exist', 'value');
|
||||
} {{{"object":{"doesnt":{"exist":"value"}}}}}
|
||||
|
||||
Reference in New Issue
Block a user