aboutsummaryrefslogtreecommitdiffstats
path: root/tests/serde_
diff options
context:
space:
mode:
authorEdward Barnard2017-01-07 10:53:37 +0000
committerEdward Barnard2017-02-02 20:26:56 +0000
commitb8787a29a3a8d4bdeedecccbd2ab3a9b386f7683 (patch)
treebf11526cd4d2d23f9e1a85207bd4d70e57ea9b1a /tests/serde_
parentbf6b567f825421afb003322562dd229b8c1ce1a5 (diff)
downloadrust-plist-b8787a29a3a8d4bdeedecccbd2ab3a9b386f7683.tar.bz2
Support Serde 0.8. Bump minimum Rust version to 0.15.
Diffstat (limited to 'tests/serde_')
-rw-r--r--tests/serde_/mod.rs209
1 files changed, 0 insertions, 209 deletions
diff --git a/tests/serde_/mod.rs b/tests/serde_/mod.rs
deleted file mode 100644
index f48058a..0000000
--- a/tests/serde_/mod.rs
+++ /dev/null
@@ -1,209 +0,0 @@
-use plist::{Deserializer, EventWriter, PlistEvent, Result as PlistResult, Serializer};
-use plist::PlistEvent::*;
-use serde::{Deserialize, Serialize};
-use std::fmt::Debug;
-
-struct VecWriter {
- events: Vec<PlistEvent>,
-}
-
-impl VecWriter {
- pub fn new() -> VecWriter {
- VecWriter { events: Vec::new() }
- }
-
- pub fn into_inner(self) -> Vec<PlistEvent> {
- self.events
- }
-}
-
-impl EventWriter for VecWriter {
- fn write(&mut self, event: &PlistEvent) -> PlistResult<()> {
- self.events.push(event.clone());
- Ok(())
- }
-}
-
-fn new_serializer() -> Serializer<VecWriter> {
- Serializer::new(VecWriter::new())
-}
-
-fn new_deserializer(events: Vec<PlistEvent>) -> Deserializer<Vec<PlistResult<PlistEvent>>> {
- let result_events = events.into_iter().map(|e| Ok(e)).collect();
- Deserializer::new(result_events)
-}
-
-fn assert_roundtrip<T>(obj: T, comparison: Option<&[PlistEvent]>)
- where T: Debug + Deserialize + PartialEq + Serialize
-{
- let mut se = new_serializer();
-
- obj.serialize(&mut se).unwrap();
-
- let events = se.into_inner().into_inner();
-
- match comparison {
- Some(comparison) => {
- assert_eq!(&events[..], comparison);
- }
- None => (),
- }
-
- let mut de = new_deserializer(events);
-
- let new_obj = T::deserialize(&mut de).unwrap();
-
- assert_eq!(new_obj, obj);
-}
-
-#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
-enum Animal {
- Cow,
- Dog(DogOuter),
- Frog(Result<String, bool>, Vec<f64>),
- Cat {
- age: usize,
- name: String,
- firmware: Option<Vec<u8>>,
- },
-}
-
-#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
-struct DogOuter {
- inner: Vec<DogInner>,
-}
-
-#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
-struct DogInner {
- a: (),
- b: usize,
- c: Vec<String>,
-}
-
-#[test]
-fn cow() {
- let cow = Animal::Cow;
-
- let comparison = &[StartDictionary(Some(1)),
- StringValue("Cow".to_owned()),
- StringValue("".to_owned()),
- EndDictionary];
-
- assert_roundtrip(cow, Some(comparison));
-}
-
-
-#[test]
-fn dog() {
- let dog = Animal::Dog(DogOuter {
- inner: vec![DogInner {
- a: (),
- b: 12,
- c: vec!["a".to_string(), "b".to_string()],
- }],
- });
-
- let comparison = &[StartDictionary(Some(1)),
- StringValue("Dog".to_owned()),
- StartDictionary(Some(1)),
- StringValue("inner".to_owned()),
- StartArray(Some(1)),
- StartDictionary(Some(3)),
- StringValue("a".to_owned()),
- StringValue("".to_owned()),
- StringValue("b".to_owned()),
- IntegerValue(12),
- StringValue("c".to_owned()),
- StartArray(Some(2)),
- StringValue("a".to_owned()),
- StringValue("b".to_owned()),
- EndArray,
- EndDictionary,
- EndArray,
- EndDictionary,
- EndDictionary];
-
- assert_roundtrip(dog, Some(comparison));
-}
-
-
-#[test]
-fn frog() {
- let frog = Animal::Frog(Ok("hello".to_owned()),
- vec![1.0, 2.0, 3.14159, 0.000000001, 1.27e31]);
-
- let comparison = &[StartDictionary(Some(1)),
- StringValue("Frog".to_owned()),
- StartArray(Some(2)),
- StartDictionary(Some(1)),
- StringValue("Ok".to_owned()),
- StringValue("hello".to_owned()),
- EndDictionary,
- StartArray(Some(5)),
- RealValue(1.0),
- RealValue(2.0),
- RealValue(3.14159),
- RealValue(0.000000001),
- RealValue(1.27e31),
- EndArray,
- EndArray,
- EndDictionary];
-
- assert_roundtrip(frog, Some(comparison));
-}
-
-
-#[test]
-fn cat() {
- let cat = Animal::Cat {
- age: 12,
- name: "Paws".to_owned(),
- firmware: Some(vec![0, 1, 2, 3, 4, 5, 6, 7, 8]),
- };
-
- let comparison = &[StartDictionary(Some(1)),
- StringValue("Cat".to_owned()),
- StartDictionary(Some(3)),
- StringValue("age".to_owned()),
- IntegerValue(12),
- StringValue("name".to_owned()),
- StringValue("Paws".to_owned()),
- StringValue("firmware".to_owned()),
- StartDictionary(Some(1)),
- StringValue("Some".to_owned()),
- StartArray(Some(9)),
- IntegerValue(0),
- IntegerValue(1),
- IntegerValue(2),
- IntegerValue(3),
- IntegerValue(4),
- IntegerValue(5),
- IntegerValue(6),
- IntegerValue(7),
- IntegerValue(8),
- EndArray,
- EndDictionary,
- EndDictionary,
- EndDictionary];
-
- assert_roundtrip(cat, Some(comparison));
-}
-
-#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
-struct NewtypeStruct(NewtypeInner);
-
-#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
-struct NewtypeInner(u8, u8, u8);
-
-#[test]
-fn newtype_struct() {
- let newtype = NewtypeStruct(NewtypeInner(34, 32, 13));
-
- let comparison = &[StartArray(Some(3)),
- IntegerValue(34),
- IntegerValue(32),
- IntegerValue(13),
- EndArray];
-
- assert_roundtrip(newtype, Some(comparison));
-}