mirror of
https://github.com/aljazceru/turso.git
synced 2025-12-22 10:44:19 +01:00
test: add TCL tests for json_object
This commit is contained in:
@@ -863,6 +863,8 @@ mod tests {
|
|||||||
let integer_value = OwnedValue::Integer(1);
|
let integer_value = OwnedValue::Integer(1);
|
||||||
let float_key = OwnedValue::build_text(Rc::new("float_key".to_string()));
|
let float_key = OwnedValue::build_text(Rc::new("float_key".to_string()));
|
||||||
let float_value = OwnedValue::Float(1.1);
|
let float_value = OwnedValue::Float(1.1);
|
||||||
|
let null_key = OwnedValue::build_text(Rc::new("null_key".to_string()));
|
||||||
|
let null_value = OwnedValue::Null;
|
||||||
|
|
||||||
let input = vec![
|
let input = vec![
|
||||||
text_key,
|
text_key,
|
||||||
@@ -873,6 +875,8 @@ mod tests {
|
|||||||
integer_value,
|
integer_value,
|
||||||
float_key,
|
float_key,
|
||||||
float_value,
|
float_value,
|
||||||
|
null_key,
|
||||||
|
null_value,
|
||||||
];
|
];
|
||||||
|
|
||||||
let result = json_object(&input).unwrap();
|
let result = json_object(&input).unwrap();
|
||||||
@@ -881,7 +885,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
json_text.value.as_str(),
|
json_text.value.as_str(),
|
||||||
r#"{"text_key":"text_value","json_key":{"json":"value","number":1},"integer_key":1,"float_key":1.1}"#
|
r#"{"text_key":"text_value","json_key":{"json":"value","number":1},"integer_key":1,"float_key":1.1,"null_key":null}"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -506,3 +506,41 @@ do_execsql_test json_error_position_null {
|
|||||||
do_execsql_test json_error_position_complex {
|
do_execsql_test json_error_position_complex {
|
||||||
SELECT json_error_position('{a:null,{"h":[1,[1,2,3]],"j":"abc"}:true}');
|
SELECT json_error_position('{a:null,{"h":[1,[1,2,3]],"j":"abc"}:true}');
|
||||||
} {{9}}
|
} {{9}}
|
||||||
|
|
||||||
|
do_execsql_test json_object_simple {
|
||||||
|
SELECT json_object('key', 'value');
|
||||||
|
} {{{"key":"value"}}}
|
||||||
|
|
||||||
|
do_execsql_test json_object_nested {
|
||||||
|
SELECT json_object('grandparent',json_object('parent', json_object('child', 'value')));
|
||||||
|
} {{{"grandparent":{"parent":{"child":"value"}}}}}
|
||||||
|
|
||||||
|
do_execsql_test json_object_quoted_json {
|
||||||
|
SELECT json_object('parent', '{"child":"value"}');
|
||||||
|
} {{{"parent":"{\"child\":\"value\"}"}}}
|
||||||
|
|
||||||
|
do_execsql_test json_object_unquoted_json {
|
||||||
|
SELECT json_object('parent', json('{"child":"value"}'));
|
||||||
|
} {{{"parent":{"child":"value"}}}}
|
||||||
|
|
||||||
|
do_execsql_test json_object_multiple_values {
|
||||||
|
SELECT json_object('text', 'value', 'json', json_object('key', 'value'), 'int', 1, 'float', 1.5, 'null', null);
|
||||||
|
} {{{"text":"value","json":{"key":"value"},"int":1,"float":1.5,"null":null}}}
|
||||||
|
|
||||||
|
do_execsql_test json_object_empty {
|
||||||
|
SELECT json_object();
|
||||||
|
} {{{}}}
|
||||||
|
|
||||||
|
do_execsql_test json_object_json_array {
|
||||||
|
SELECT json_object('ex',json('[52,3]'));
|
||||||
|
} {{{"ex":[52,3]}}}
|
||||||
|
|
||||||
|
do_execsql_test json_from_json_object {
|
||||||
|
SELECT json(json_object('key','value'));
|
||||||
|
} {{{"key":"value"}}}
|
||||||
|
|
||||||
|
# FIXME: this behaviour differs from sqlite. Although, sqlite docs states
|
||||||
|
# that this could change in a "future enhancement" (https://www.sqlite.org/json1.html#jobj)
|
||||||
|
#do_execsql_test json_object_duplicated_keys {
|
||||||
|
# SELECT json_object('key', 'value', 'key', 'value2');
|
||||||
|
#} {{{"key":"value2"}}}
|
||||||
|
|||||||
Reference in New Issue
Block a user