use fsqlite_core::connection::Connection;
use fsqlite_types::SqliteValue;
const EXPRS: &[&str] = &[
"printf('%g', -0.0)",
"format('%g', -0.0)",
"printf('%G', -0.0)",
"printf('%f', -0.0)",
"printf('%e', -0.0)",
"printf('%E', -0.0)",
"printf('%+g', -0.0)",
"printf('% g', -0.0)",
"printf('%+f', -0.0)",
"printf('%8.2f', -0.0)",
"printf('%g', 0.0)",
"printf('%g', -1e-320 * 1e-10)",
"printf('%f', -1.0 * 0.0)",
"printf('%g', -1.5)",
"printf('%f', -2.25)",
"printf('%e', -3.0)",
"printf('%+g', -1.5)",
];
fn oracle(expr: &str) -> String {
let conn = rusqlite::Connection::open_in_memory().unwrap();
conn.query_row(&format!("SELECT {expr}"), [], |row| row.get::<_, String>(0))
.unwrap()
}
#[test]
fn printf_signed_zero_matches_rusqlite_oracle() {
asupersync::test_utils::run_test(|| async {
let conn = Connection::open(":memory:").await.unwrap();
for expr in EXPRS {
let expected = oracle(expr);
let sql = format!("SELECT {expr}");
let rows = conn
.query(&sql)
.await
.unwrap_or_else(|e| panic!("`{sql}`: {e:?}"));
let got = match rows[0].values()[0] {
SqliteValue::Text(ref s) => s.as_ref().to_owned(),
ref other => panic!("`{sql}` not text: {other:?}"),
};
assert_eq!(
got, expected,
"`{expr}` diverged from the C SQLite oracle (got {got:?}, want {expected:?})"
);
}
});
}