serde: Split test assertions
This commit is contained in:
parent
085dc435fa
commit
35d6b90aeb
@ -179,7 +179,6 @@ where
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use assert_matches::assert_matches;
|
|
||||||
use js_int::{int, Int};
|
use js_int::{int, Int};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
@ -192,32 +191,25 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn int_or_string() -> serde_json::Result<()> {
|
fn int_or_string() {
|
||||||
assert_matches!(
|
let test = serde_json::from_value::<Test>(serde_json::json!({ "num": "0" })).unwrap();
|
||||||
serde_json::from_value::<Test>(serde_json::json!({ "num": "0" }))?,
|
assert_eq!(test.num, int!(0));
|
||||||
Test { num } if num == int!(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn weird_plus_string() -> serde_json::Result<()> {
|
fn weird_plus_string() {
|
||||||
assert_matches!(
|
let test =
|
||||||
serde_json::from_value::<Test>(serde_json::json!({ "num": " +0000000001000 " }))?,
|
serde_json::from_value::<Test>(serde_json::json!({ "num": " +0000000001000 " }))
|
||||||
Test { num } if num == int!(1000)
|
.unwrap();
|
||||||
);
|
assert_eq!(test.num, int!(1000));
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn weird_minus_string() -> serde_json::Result<()> {
|
fn weird_minus_string() {
|
||||||
assert_matches!(
|
let test = serde_json::from_value::<Test>(
|
||||||
serde_json::from_value::<Test>(serde_json::json!({ "num": " \n\n-0000000000000001000 " }))?,
|
serde_json::json!({ "num": " \n\n-0000000000000001000 " }),
|
||||||
Test { num } if num == int!(-1000)
|
)
|
||||||
);
|
.unwrap();
|
||||||
|
assert_eq!(test.num, int!(-1000));
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -238,7 +238,8 @@ mod tests {
|
|||||||
let mut x = ValOrVec::Val(Cow::Borrowed("a"));
|
let mut x = ValOrVec::Val(Cow::Borrowed("a"));
|
||||||
x.push(Cow::Borrowed("b"));
|
x.push(Cow::Borrowed("b"));
|
||||||
x.push(Cow::Borrowed("c"));
|
x.push(Cow::Borrowed("c"));
|
||||||
assert_matches!(x, ValOrVec::Vec(v) if v == vec!["a", "b", "c"]);
|
let v = assert_matches!(x, ValOrVec::Vec(v) => v);
|
||||||
|
assert_eq!(v, vec!["a", "b", "c"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -246,9 +247,10 @@ mod tests {
|
|||||||
let mut x = ValOrVec::Val(Cow::from("a".to_owned()));
|
let mut x = ValOrVec::Val(Cow::from("a".to_owned()));
|
||||||
x.push(Cow::from("b".to_owned()));
|
x.push(Cow::from("b".to_owned()));
|
||||||
x.push(Cow::from("c".to_owned()));
|
x.push(Cow::from("c".to_owned()));
|
||||||
assert_matches!(
|
let v = assert_matches!(
|
||||||
x,
|
x,
|
||||||
ValOrVec::Vec(v) if v == vec!["a".to_owned(), "b".to_owned(), "c".to_owned()]
|
ValOrVec::Vec(v) => v
|
||||||
);
|
);
|
||||||
|
assert_eq!(v, vec!["a".to_owned(), "b".to_owned(), "c".to_owned()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user