use chrono::{DateTime, TimeZone, Utc}; #[macro_use] extern crate timeless_partialeq; #[test] fn it_ignores_fields_ending_with_at() { #[derive(Debug, TimelessPartialEq)] pub struct Post { pub id: i64, pub content: String, pub author: i32, pub created_at: DateTime, } assert_eq!( Post { id: 1, content: "test".to_string(), author: 1, created_at: Utc.timestamp_millis_opt(1715017040672).unwrap(), }, Post { id: 1, content: "test".to_string(), author: 1, created_at: Utc::now(), } ) } #[test] fn it_fails_without_custom_derive_macro() { #[derive(Debug, PartialEq)] pub struct Post { pub id: i64, pub content: String, pub author: i32, pub created_at: DateTime, pub updated_at: Option>, } assert_ne!( Post { id: 1, content: "test".to_string(), author: 1, created_at: Utc.timestamp_millis_opt(1715017040672).unwrap(), updated_at: Some(Utc.timestamp_millis_opt(1715017020672).unwrap()), }, Post { id: 1, content: "test".to_string(), author: 1, created_at: Utc::now(), updated_at: Some(Utc::now()), } ) } #[test] fn it_checks_optional_timestamps_accordingly() { #[derive(Debug, TimelessPartialEq)] pub struct Post { pub id: i64, pub content: String, pub author: i32, pub created_at: DateTime, pub updated_at: Option>, } assert_ne!( Post { id: 1, content: "test".to_string(), author: 1, created_at: Utc.timestamp_millis_opt(1715017040672).unwrap(), updated_at: Some(Utc.timestamp_millis_opt(1715017020672).unwrap()), }, Post { id: 1, content: "test".to_string(), author: 1, created_at: Utc::now(), updated_at: None, } ) } #[test] fn it_works_with_user_attribute_input() { #[derive(Debug, TimelessPartialEq)] #[exclude_suffix(at, date)] pub struct Post { pub id: i64, pub content: String, pub author: i32, pub updated_at: Option>, pub creation_date: DateTime, } assert_eq!( Post { id: 1, content: "test".to_string(), author: 1, creation_date: Utc.timestamp_millis_opt(1715017040672).unwrap(), updated_at: Some(Utc.timestamp_millis_opt(1715017020672).unwrap()), }, Post { id: 1, content: "test".to_string(), author: 1, creation_date: Utc::now(), updated_at: Some(Utc::now()), } ) }