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(),
spg_storage::Value::Bool(b) => b.to_string(),
v => format!("{v:?}"),
},
_ => panic!("expected rows"),
}
}
#[test]
fn two_arg_geometric_constructors() {
let mut e = Engine::new();
assert_eq!(
text(&mut e, "SELECT (circle(point(1,1), 5))::text"),
"<(1,1),5>"
);
assert_eq!(
text(&mut e, "SELECT (box(point(0,0), point(4,4)))::text"),
"(4,4),(0,0)"
);
assert_eq!(
text(&mut e, "SELECT (lseg(point(0,0), point(3,4)))::text"),
"[(0,0),(3,4)]"
);
assert_eq!(
text(&mut e, "SELECT (box(point(4,4), point(0,0)))::text"),
"(4,4),(0,0)"
);
assert_eq!(
text(&mut e, "SELECT circle(point(0,0), 5) @> point(3,4)"),
"true"
);
assert_eq!(
text(&mut e, "SELECT box(point(0,0), point(10,10)) @> point(5,5)"),
"true"
);
assert_eq!(
text(&mut e, "SELECT circle('<(0,0),5>') @> point(3,4)"),
"true"
);
}