serde: Rewrite some tests to use assert_matches
This commit is contained in:
parent
99b89c8267
commit
5de8d3be5d
@ -44,6 +44,7 @@ where
|
|||||||
mod tests {
|
mod tests {
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
|
use matches::assert_matches;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
@ -57,15 +58,19 @@ mod tests {
|
|||||||
fn deserialize() {
|
fn deserialize() {
|
||||||
let json = json!({ "timestamp": 3000 });
|
let json = json!({ "timestamp": 3000 });
|
||||||
|
|
||||||
assert_eq!(
|
assert_matches!(
|
||||||
serde_json::from_value::<SystemTimeTest>(json).unwrap(),
|
serde_json::from_value::<SystemTimeTest>(json),
|
||||||
SystemTimeTest { timestamp: UNIX_EPOCH + Duration::from_millis(3000) },
|
Ok(SystemTimeTest { timestamp })
|
||||||
|
if timestamp == UNIX_EPOCH + Duration::from_millis(3000)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn serialize() {
|
fn serialize() {
|
||||||
let request = SystemTimeTest { timestamp: UNIX_EPOCH + Duration::new(2, 0) };
|
let request = SystemTimeTest { timestamp: UNIX_EPOCH + Duration::new(2, 0) };
|
||||||
assert_eq!(serde_json::to_value(&request).unwrap(), json!({ "timestamp": 2000 }));
|
assert_matches!(
|
||||||
|
serde_json::to_value(&request),
|
||||||
|
Ok(value) if value == json!({ "timestamp": 2000 })
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user