use spg_engine::{Engine, QueryResult};
fn text(e: &mut Engine, sql: &str) -> String {
match e.execute(sql).unwrap() {
QueryResult::Rows { rows, .. } => match &rows[0].values[0] {
spg_storage::Value::Text(s) => s.to_string(),
v => format!("{v:?}"),
},
_ => panic!("expected rows"),
}
}
#[test]
fn json_object_accepts_text_array_literals() {
let mut e = Engine::new();
assert_eq!(
text(&mut e, "SELECT json_object('{a,b}', '{1,2}')::text"),
r#"{"a" : "1", "b" : "2"}"#
);
assert_eq!(
text(&mut e, "SELECT json_object('{a,1,b,2}')::text"),
r#"{"a" : "1", "b" : "2"}"#
);
assert_eq!(
text(&mut e, "SELECT jsonb_object('{a,b}', '{1,2}')::text"),
r#"{"a": "1", "b": "2"}"#
);
assert_eq!(
text(
&mut e,
"SELECT json_object(ARRAY['a','b'], ARRAY['1','2'])::text"
),
r#"{"a" : "1", "b" : "2"}"#
);
}