serde: Fix url_deserialize test
This commit is contained in:
parent
566e03abc1
commit
2397d494b5
@ -124,36 +124,26 @@ fn deserialize_multiple_lists() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn deserialize_with_serde_attributes() {
|
fn deserialize_with_serde_attributes() {
|
||||||
use std::time::{Duration, SystemTime, UNIX_EPOCH};
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Deserialize)]
|
#[derive(Debug, PartialEq, Deserialize)]
|
||||||
struct FieldsWithAttributes {
|
struct FieldsWithAttributes {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
xs: Vec<bool>,
|
xs: Vec<bool>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
def: Option<u8>,
|
def: Option<u8>,
|
||||||
#[serde(
|
#[serde(default, deserialize_with = "ruma_serde::empty_string_as_none")]
|
||||||
default,
|
str: Option<String>,
|
||||||
deserialize_with = "ruma_serde::time::opt_ms_since_unix_epoch::deserialize"
|
|
||||||
)]
|
|
||||||
time: Option<SystemTime>,
|
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
flag: bool,
|
flag: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
urlencoded::from_str("xs=true&xs=false&def=3&time=1&flag=true"),
|
urlencoded::from_str("xs=true&xs=false&def=3&str=&flag=true"),
|
||||||
Ok(FieldsWithAttributes {
|
Ok(FieldsWithAttributes { xs: vec![true, false], def: Some(3), str: None, flag: true })
|
||||||
xs: vec![true, false],
|
|
||||||
def: Some(3),
|
|
||||||
time: Some(UNIX_EPOCH + Duration::from_millis(1)),
|
|
||||||
flag: true,
|
|
||||||
})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
urlencoded::from_str(""),
|
urlencoded::from_str(""),
|
||||||
Ok(FieldsWithAttributes { xs: vec![], def: None, time: None, flag: false })
|
Ok(FieldsWithAttributes { xs: vec![], def: None, str: None, flag: false })
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user