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!("rows"),
}
}
#[test]
fn numeric_specials_parse_and_render() {
let mut e = Engine::new();
assert_eq!(text(&mut e, "SELECT ('NaN'::numeric)::text"), "NaN");
assert_eq!(text(&mut e, "SELECT ('nan'::numeric)::text"), "NaN");
assert_eq!(
text(&mut e, "SELECT ('Infinity'::numeric)::text"),
"Infinity"
);
assert_eq!(text(&mut e, "SELECT ('inf'::numeric)::text"), "Infinity");
assert_eq!(
text(&mut e, "SELECT ('+Infinity'::numeric)::text"),
"Infinity"
);
assert_eq!(
text(&mut e, "SELECT ('-Infinity'::numeric)::text"),
"-Infinity"
);
assert_eq!(text(&mut e, "SELECT ('-inf'::numeric)::text"), "-Infinity");
assert_eq!(text(&mut e, "SELECT 'x=' || 'NaN'::numeric"), "x=NaN");
assert_eq!(text(&mut e, "SELECT (3.14::numeric)::text"), "3.14");
}