From 214d6521ef03acea4d04a460c0f771a0fe0e30da Mon Sep 17 00:00:00 2001 From: Jonas Platte Date: Wed, 15 Apr 2020 23:19:00 +0200 Subject: [PATCH] Update tests for serde::duration --- src/serde/duration/opt_ms.rs | 18 ++++++++++++++---- src/serde/duration/secs.rs | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/serde/duration/opt_ms.rs b/src/serde/duration/opt_ms.rs index 47d14b9a..1e8d6462 100644 --- a/src/serde/duration/opt_ms.rs +++ b/src/serde/duration/opt_ms.rs @@ -52,7 +52,7 @@ mod tests { } #[test] - fn test_deserialize_some_duration_as_milliseconds() { + fn test_deserialize_some() { let json = json!({ "timeout": 3000 }); assert_eq!( @@ -64,7 +64,7 @@ mod tests { } #[test] - fn test_deserialize_empty_duration_as_milliseconds() { + fn test_deserialize_none_by_absence() { let json = json!({}); assert_eq!( @@ -74,7 +74,17 @@ mod tests { } #[test] - fn test_serialize_some_duration_as_milliseconds() { + fn test_deserialize_none_by_null() { + let json = json!({ "timeout": null }); + + assert_eq!( + serde_json::from_value::(json).unwrap(), + DurationTest { timeout: None }, + ); + } + + #[test] + fn test_serialize_some() { let request = DurationTest { timeout: Some(Duration::new(2, 0)), }; @@ -85,7 +95,7 @@ mod tests { } #[test] - fn test_serialize_empty_duration_as_milliseconds() { + fn test_serialize_none() { let request = DurationTest { timeout: None }; assert_eq!(serde_json::to_value(&request).unwrap(), json!({})); } diff --git a/src/serde/duration/secs.rs b/src/serde/duration/secs.rs index f8940092..830eb4d5 100644 --- a/src/serde/duration/secs.rs +++ b/src/serde/duration/secs.rs @@ -48,7 +48,7 @@ mod tests { } #[test] - fn test_deserialize_duration_as_seconds() { + fn test_deserialize() { let json = json!({ "timeout": 3 }); assert_eq!( @@ -60,7 +60,7 @@ mod tests { } #[test] - fn test_serialize_duration_as_seconds() { + fn test_serialize() { let test = DurationTest { timeout: Duration::from_millis(7000), };