From a969acca6ad0aa8849b5bd41c491413f8532152d Mon Sep 17 00:00:00 2001 From: mxhagen Date: Mon, 9 Dec 2024 14:13:39 +0100 Subject: [PATCH] autoformatting --- src/test/macros.rs | 76 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 56 insertions(+), 20 deletions(-) diff --git a/src/test/macros.rs b/src/test/macros.rs index 1be210a..7669ccc 100644 --- a/src/test/macros.rs +++ b/src/test/macros.rs @@ -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 { + fn column_result( + value: rusqlite::types::ValueRef<'_>, + ) -> rusqlite::types::FromSqlResult { 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::().unwrap()) .collect::>(); @@ -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,59 +62,90 @@ 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] // fn test_table_derive_macro_missing_id() { // use squail_macros::Table; -// +// // /// An example struct without an explicit id. // /// Should not compile and give a proper error message. // #[derive(Table)] @@ -116,4 +153,3 @@ fn test_table_derive_macro() { // data: i64, // missing `id: Option` // } // } -