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 strip_removes_positions_from_tsvector() {
let mut e = Engine::new();
assert_eq!(
text(&mut e, "SELECT strip('a:1 b:2,3'::tsvector)::text"),
"'a' 'b'"
);
assert_eq!(
text(
&mut e,
"SELECT strip(to_tsvector('simple','hello world'))::text"
),
"'hello' 'world'"
);
}
#[test]
fn ts_delete_removes_lexemes_from_tsvector() {
let mut e = Engine::new();
assert_eq!(
text(
&mut e,
"SELECT ts_delete('a:1 b:2 c:3'::tsvector, 'b')::text"
),
"'a':1 'c':3"
);
assert_eq!(
text(
&mut e,
"SELECT ts_delete('a:1 b:2 c:3'::tsvector, ARRAY['a','c'])::text"
),
"'b':2"
);
}