Add bincode serde tests

This commit is contained in:
David Tolnay 2016-08-16 18:08:08 -04:00
parent c3b9a26bb0
commit c3cd76af16
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
5 changed files with 59 additions and 0 deletions

View File

@ -22,3 +22,4 @@ serde = { version = "<0.9", optional = true }
[dev-dependencies]
serde_json = { version = ">=0.7.0" }
bincode = { version = "0.6", features = ["serde"], default-features = false }

View File

@ -517,6 +517,7 @@ mod serde {
}
#[cfg(test)] extern crate serde_json;
#[cfg(test)] extern crate bincode;
#[test]
fn test_serde_serialize() {
@ -537,6 +538,20 @@ mod serde {
assert!(from_str(r#""2014-07-32T12:34:06Z""#).is_err());
}
#[test]
fn test_serde_bincode() {
// Bincode is relevant to test separately from JSON because
// it is not self-describing.
use self::bincode::SizeLimit;
use self::bincode::serde::{serialize, deserialize};
let dt = UTC.ymd(2014, 7, 24).and_hms(12, 34, 6);
let encoded = serialize(&dt, SizeLimit::Infinite).unwrap();
let decoded: DateTime<UTC> = deserialize(&encoded).unwrap();
assert_eq!(dt, decoded);
assert_eq!(dt.offset(), decoded.offset());
}
}
#[cfg(test)]

View File

@ -1586,6 +1586,7 @@ mod serde {
}
#[cfg(test)] extern crate serde_json;
#[cfg(test)] extern crate bincode;
#[test]
fn test_serde_serialize() {
@ -1637,6 +1638,19 @@ mod serde {
assert!(from_str(r#"{"ymdf":20}"#).is_err()); // :(
assert!(from_str(r#"null"#).is_err());
}
#[test]
fn test_serde_bincode() {
// Bincode is relevant to test separately from JSON because
// it is not self-describing.
use self::bincode::SizeLimit;
use self::bincode::serde::{serialize, deserialize};
let d = NaiveDate::from_ymd(2014, 7, 24);
let encoded = serialize(&d, SizeLimit::Infinite).unwrap();
let decoded: NaiveDate = deserialize(&encoded).unwrap();
assert_eq!(d, decoded);
}
}
#[cfg(test)]

View File

@ -1148,6 +1148,7 @@ mod serde {
}
#[cfg(test)] extern crate serde_json;
#[cfg(test)] extern crate bincode;
#[test]
fn test_serde_serialize() {
@ -1230,6 +1231,20 @@ mod serde {
assert!(from_str(r#"{"date":{"ymdf":20},"time":{"secs":0,"frac":0}}"#).is_err()); // :(
assert!(from_str(r#"null"#).is_err());
}
#[test]
fn test_serde_bincode() {
// Bincode is relevant to test separately from JSON because
// it is not self-describing.
use naive::date::NaiveDate;
use self::bincode::SizeLimit;
use self::bincode::serde::{serialize, deserialize};
let dt = NaiveDate::from_ymd(2016, 7, 8).and_hms_milli(9, 10, 48, 90);
let encoded = serialize(&dt, SizeLimit::Infinite).unwrap();
let decoded: NaiveDateTime = deserialize(&encoded).unwrap();
assert_eq!(dt, decoded);
}
}
#[cfg(test)]

View File

@ -1273,6 +1273,7 @@ mod serde {
}
#[cfg(test)] extern crate serde_json;
#[cfg(test)] extern crate bincode;
#[test]
fn test_serde_serialize() {
@ -1340,6 +1341,19 @@ mod serde {
assert!(from_str(r#"{"secs":0,"frac":0}"#).is_err()); // :(
assert!(from_str(r#"null"#).is_err());
}
#[test]
fn test_serde_bincode() {
// Bincode is relevant to test separately from JSON because
// it is not self-describing.
use self::bincode::SizeLimit;
use self::bincode::serde::{serialize, deserialize};
let t = NaiveTime::from_hms_nano(3, 5, 7, 98765432);
let encoded = serialize(&t, SizeLimit::Infinite).unwrap();
let decoded: NaiveTime = deserialize(&encoded).unwrap();
assert_eq!(t, decoded);
}
}
#[cfg(test)]