#[test]
fn sqlite_ships_with_fts5() {
let conn = rusqlite::Connection::open_in_memory().expect("open in-memory database");
let options: Vec<String> = conn
.prepare("PRAGMA compile_options")
.expect("prepare compile_options")
.query_map([], |row| row.get(0))
.expect("query compile_options")
.collect::<rusqlite::Result<_>>()
.expect("collect compile_options");
assert!(
options.iter().any(|o| o == "ENABLE_FTS5"),
"bundled SQLite lost ENABLE_FTS5; compile_options were {options:?}"
);
}
#[test]
fn fts5_accepts_the_contract_tokenizer() {
let conn = rusqlite::Connection::open_in_memory().expect("open in-memory database");
conn.execute_batch(
"CREATE VIRTUAL TABLE probe USING fts5(
body,
tokenize = 'unicode61 remove_diacritics 2'
);
INSERT INTO probe(body) VALUES ('resumé');",
)
.expect("create an fts5 table with the contract tokenizer");
let hits: i64 = conn
.query_row(
"SELECT count(*) FROM probe WHERE probe MATCH 'resume'",
[],
|row| row.get(0),
)
.expect("query the fts5 index");
assert_eq!(
hits, 1,
"remove_diacritics 2 must fold 'resumé' to 'resume'"
);
}
#[test]
fn json_valid_enforces_check_constraints() {
let conn = rusqlite::Connection::open_in_memory().expect("open in-memory database");
conn.execute_batch(
"CREATE TABLE probe (
payload TEXT NOT NULL CHECK (json_valid(payload))
);",
)
.expect("create a table with a json_valid CHECK");
conn.execute("INSERT INTO probe(payload) VALUES ('{\"ok\":true}')", [])
.expect("well-formed json must be accepted");
let rejected = conn.execute("INSERT INTO probe(payload) VALUES ('not json')", []);
assert!(
rejected.is_err(),
"the json_valid CHECK must reject malformed payloads"
);
}
#[test]
fn a_file_database_survives_being_closed_and_reopened() {
let path = std::path::PathBuf::from("shepherd-registry-file-vfs-probe.db");
let cleanup = || {
for suffix in ["", "-wal", "-shm"] {
let _ = std::fs::remove_file(format!("{}{suffix}", path.display()));
}
};
cleanup();
{
let conn = rusqlite::Connection::open(&path).expect("create a file-backed database");
conn.execute_batch(
"PRAGMA journal_mode = WAL;
CREATE TABLE probe (id INTEGER PRIMARY KEY, note TEXT NOT NULL);
INSERT INTO probe(note) VALUES ('written before close');",
)
.expect("write to a file-backed database");
}
let conn = rusqlite::Connection::open(&path).expect("reopen the same file");
let note: String = conn
.query_row("SELECT note FROM probe WHERE id = 1", [], |row| row.get(0))
.expect("read back a row written by a previous connection");
assert_eq!(note, "written before close");
drop(conn);
cleanup();
}