#![allow(clippy::unwrap_used, clippy::expect_used)]
use std::path::{Path, PathBuf};
use sqlite_core::{Database, Value};
fn fixture(name: &str) -> Option<PathBuf> {
let p = Path::new(env!("CARGO_MANIFEST_DIR"))
.join("../tests/data")
.join(name);
if p.exists() {
Some(p)
} else {
eprintln!("SKIP — real fixture not present: {} (see corpus-catalog.md)", p.display());
None
}
}
fn read_only_text(path: &Path) -> String {
let bytes = std::fs::read(path).expect("read fixture");
let db = Database::open(bytes).expect("valid sqlite db");
let rows = db.read_table(2, 1).expect("read table t");
let row = rows.first().expect("table t has one row");
match &row.values[0] {
Value::Text(s) => s.clone(),
other => panic!("expected Text, got {other:?}"),
}
}
#[test]
fn utf8_database_text_decodes_correctly() {
let Some(p) = fixture("utf8.sqlite") else { return };
assert_eq!(read_only_text(&p), "héllo wörld");
}
#[test]
fn utf16le_database_text_decodes_correctly() {
let Some(p) = fixture("utf16le.sqlite") else { return };
assert_eq!(
read_only_text(&p),
"héllo wörld",
"UTF-16LE text must decode per header byte 56, not as lossy UTF-8"
);
}
#[test]
fn utf16be_database_text_decodes_correctly() {
let Some(p) = fixture("utf16be.sqlite") else { return };
assert_eq!(read_only_text(&p), "héllo wörld", "UTF-16BE must decode per header byte 56");
}