autoformatting
This commit is contained in:
parent
f38d9a6df2
commit
a969acca6a
@ -16,7 +16,7 @@ fn test_table_derive_macro() {
|
||||
#[derive(Clone, Default, Debug, PartialEq, Eq)]
|
||||
struct Point {
|
||||
x: i16,
|
||||
y: i16
|
||||
y: i16,
|
||||
}
|
||||
|
||||
impl rusqlite::types::ToSql for Point {
|
||||
@ -26,11 +26,14 @@ fn test_table_derive_macro() {
|
||||
}
|
||||
|
||||
impl rusqlite::types::FromSql for Point {
|
||||
fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
|
||||
fn column_result(
|
||||
value: rusqlite::types::ValueRef<'_>,
|
||||
) -> rusqlite::types::FromSqlResult<Self> {
|
||||
match value {
|
||||
rusqlite::types::ValueRef::Text(v) => {
|
||||
let values = String::from_utf8(v.into()).unwrap();
|
||||
let values = values.split_ascii_whitespace()
|
||||
let values = values
|
||||
.split_ascii_whitespace()
|
||||
.map(|w| w.parse::<i16>().unwrap())
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
@ -38,8 +41,11 @@ fn test_table_derive_macro() {
|
||||
x: values[0],
|
||||
y: values[1],
|
||||
})
|
||||
},
|
||||
t => panic!("Wrong SQL type recieved for query of Point. Should be Text but is {:?}", t),
|
||||
}
|
||||
t => panic!(
|
||||
"Wrong SQL type recieved for query of Point. Should be Text but is {:?}",
|
||||
t
|
||||
),
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -56,53 +62,84 @@ fn test_table_derive_macro() {
|
||||
Person::create_table(&conn).unwrap();
|
||||
|
||||
larry.insert(&conn).unwrap();
|
||||
let larry_id = larry.id.expect("After (mutable) insertion, id should not be None");
|
||||
let larry_id = larry
|
||||
.id
|
||||
.expect("After (mutable) insertion, id should not be None");
|
||||
|
||||
larry.age += 1;
|
||||
let updated_something = larry.update(&conn).expect("Updating should work");
|
||||
assert!(updated_something, "Should have updated a row");
|
||||
|
||||
let larry_copy = Person::get_by_id(&conn, larry_id).expect("Querying a row should work");
|
||||
assert_eq!(larry_copy, Some(larry.clone()), "Retrieving inserted row should give an identical row");
|
||||
assert_eq!(
|
||||
larry_copy,
|
||||
Some(larry.clone()),
|
||||
"Retrieving inserted row should give an identical row"
|
||||
);
|
||||
|
||||
let deleted_something = larry.delete(&conn).expect("Deletion should work");
|
||||
// also works: `Person::delete_by_id(&conn, larry_id).unwrap();`
|
||||
assert!(deleted_something, "Should have deleted something");
|
||||
|
||||
let deleted_larry = Person::get_by_id(&conn, larry_id).expect("Querying a deleted row should return Ok(None), not Err(_)");
|
||||
assert_eq!(deleted_larry, None, "Received row that should have been deleted");
|
||||
let deleted_larry = Person::get_by_id(&conn, larry_id)
|
||||
.expect("Querying a deleted row should return Ok(None), not Err(_)");
|
||||
assert_eq!(
|
||||
deleted_larry, None,
|
||||
"Received row that should have been deleted"
|
||||
);
|
||||
|
||||
let id = larry.upsert(&conn).expect("Upsertion (insert) should work");
|
||||
let larry_id = larry.id.expect("After (mutable) upsertion, id should not be None");
|
||||
let larry_id = larry
|
||||
.id
|
||||
.expect("After (mutable) upsertion, id should not be None");
|
||||
|
||||
let larry_copy = Person::get_by_id(&conn, larry_id).expect("Querying a row should work");
|
||||
assert_eq!(id, larry_id, "Upsert should return correct id");
|
||||
assert_eq!(larry_copy, Some(larry.clone()), "Retrieving upserted row should give an identical row");
|
||||
assert_eq!(
|
||||
larry_copy,
|
||||
Some(larry.clone()),
|
||||
"Retrieving upserted row should give an identical row"
|
||||
);
|
||||
|
||||
larry.age += 1;
|
||||
let id = larry.upsert(&conn).expect("Upsertion (update) should work");
|
||||
let larry_id = larry.id.expect("After (mutable) upsertion, id should not be None");
|
||||
let larry_id = larry
|
||||
.id
|
||||
.expect("After (mutable) upsertion, id should not be None");
|
||||
assert_eq!(id, larry_id, "Upsert should return correct id");
|
||||
|
||||
let larry_copy = Person::get_by_id(&conn, larry_id).expect("Querying a row should work");
|
||||
assert_eq!(larry_copy, Some(larry.clone()), "Retrieving upserted row should give an identical row");
|
||||
assert_eq!(
|
||||
larry_copy,
|
||||
Some(larry.clone()),
|
||||
"Retrieving upserted row should give an identical row"
|
||||
);
|
||||
|
||||
conn.execute("UPDATE Person SET (age) = (27) WHERE id = ?1", [larry_id])
|
||||
.expect("Explicit Sqlite statement (not a library test) failed");
|
||||
|
||||
let found = larry.sync(&conn).expect("Syncing struct to existing row should succeed");
|
||||
let found = larry
|
||||
.sync(&conn)
|
||||
.expect("Syncing struct to existing row should succeed");
|
||||
assert!(found, "Row should have been found");
|
||||
assert_eq!(larry.age, 27, "Syncing struct to edited table row should work");
|
||||
assert_eq!(
|
||||
larry.age, 27,
|
||||
"Syncing struct to edited table row should work"
|
||||
);
|
||||
|
||||
Person::drop_table(&conn).expect("Dropping table should work");
|
||||
Person::drop_table(&conn).expect_err("Dropping previously dropped table should err");
|
||||
|
||||
let exists: bool = conn.query_row("SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='Person');", [], |row| row.get(0)).expect("Explicit Sqlite statement (not a library test) failed");
|
||||
let exists: bool = conn
|
||||
.query_row(
|
||||
"SELECT EXISTS(SELECT 1 FROM sqlite_master WHERE type='table' AND name='Person');",
|
||||
[],
|
||||
|row| row.get(0),
|
||||
)
|
||||
.expect("Explicit Sqlite statement (not a library test) failed");
|
||||
assert!(!exists, "Deleted table should not exist anymore but does");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// TODO: implement compile-error test(s) -- perhaps with `trybuild`?
|
||||
//
|
||||
// #[test]
|
||||
@ -116,4 +153,3 @@ fn test_table_derive_macro() {
|
||||
// data: i64, // missing `id: Option<i64>`
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user