mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-19 06:55:18 +01:00
test: add json tcl test
This commit is contained in:
@@ -6,7 +6,10 @@ use serde_json::Value;
|
||||
pub fn get_json(json_value: &OwnedValue) -> crate::Result<OwnedValue> {
|
||||
match json_value {
|
||||
OwnedValue::Text(ref t) => {
|
||||
if let Ok(json) = json5::from_str::<Value>(t.as_str()) {
|
||||
// Replace instances of two single quotes ('') with a double quote (")
|
||||
// This is necessary to correctly format the string for parsing
|
||||
let corrected_t = t.replace("''", "\"");
|
||||
if let Ok(json) = json5::from_str::<Value>(&corrected_t) {
|
||||
Ok(OwnedValue::Text(Rc::new(json.to_string())))
|
||||
} else {
|
||||
crate::bail_parse_error!("malformed JSON");
|
||||
|
||||
@@ -12,3 +12,4 @@ source $testdir/where.test
|
||||
source $testdir/like.test
|
||||
source $testdir/scalar-functions.test
|
||||
source $testdir/orderby.test
|
||||
source $testdir/json.test
|
||||
57
testing/json.test
Normal file
57
testing/json.test
Normal file
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env tclsh
|
||||
|
||||
set testdir [file dirname $argv0]
|
||||
source $testdir/tester.tcl
|
||||
|
||||
do_execsql_test json5-ecma-script-1 {
|
||||
select json('{a:5,b:6}') ;
|
||||
} {{{"a":5,"b":6}}}
|
||||
|
||||
do_execsql_test json5-ecma-script-2 {
|
||||
SELECT json('{ MNO_123$xyz : 789 }');
|
||||
} {{{"MNO_123$xyz":789}}}
|
||||
|
||||
do_execsql_test json5-with-single-trailing-comma-valid {
|
||||
select json('{"a":5, "b":6, }');
|
||||
} {{{"a":5,"b":6}}}
|
||||
|
||||
do_execsql_test json5-single-quoted {
|
||||
SELECT json('{"a": ''abcd''}');
|
||||
} {{{"a":"abcd"}}}
|
||||
|
||||
do_execsql_test json5-character-escaped-1 {
|
||||
select json('{a: "abc\x35\x4f\x6Exyz"}');
|
||||
} {{{"a":"abc5Onxyz"}}}
|
||||
|
||||
do_execsql_test json5-character-escaped-2 {
|
||||
select json('{a: "\x6a\x6A\x6b\x6B\x6c\x6C\x6d\x6D\x6e\x6E\x6f\x6F"}');
|
||||
} {{{"a":"jjkkllmmnnoo"}}}
|
||||
|
||||
do_execsql_test json5-hexadecimal-1 {
|
||||
SELECT json('{a: 0x0}')
|
||||
} {{{"a":0}}}
|
||||
|
||||
do_execsql_test json5-hexadecimal-2 {
|
||||
SELECT json('{a: 0xabcdef}')
|
||||
} {{{"a":11259375}}}
|
||||
|
||||
do_execsql_test json5-number-1 {
|
||||
SELECT json('{x: 4.}')
|
||||
} {{{"x":4.0}}}
|
||||
|
||||
do_execsql_test json5-number-2 {
|
||||
SELECT json('{x: +4.}')
|
||||
} {{{"x":4.0}}}
|
||||
|
||||
do_execsql_test json5-number-3 {
|
||||
SELECT json('{x: -4.}')
|
||||
} {{{"x":-4.0}}}
|
||||
|
||||
do_execsql_test json5-number-4 {
|
||||
SELECT json('{x: +4.e1}')
|
||||
} {{{"x":40.0}}}
|
||||
|
||||
do_execsql_test json5-multi-comment {
|
||||
SELECT json(' /* abc */ { /*def*/ aaa /* xyz */ : // to the end of line
|
||||
123 /* xyz */ , /* 123 */ }')
|
||||
} {{{"aaa":123}}}
|
||||
Reference in New Issue
Block a user