diff options
| author | Edward Barnard | 2018-03-16 11:09:05 +0000 |
|---|---|---|
| committer | Edward Barnard | 2018-03-16 11:09:05 +0000 |
| commit | 8c2d6a8463dd00ee956d196914b65d6b235e5992 (patch) | |
| tree | b95599078518d8894fae217eec6377665ff97fde /tests | |
| parent | c91087906540c210bdb457b32fb976ce735b22f9 (diff) | |
| download | rust-plist-8c2d6a8463dd00ee956d196914b65d6b235e5992.tar.bz2 | |
Run rustfmt.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/fuzzer.rs | 3 | ||||
| -rw-r--r-- | tests/serde_tests/mod.rs | 202 |
2 files changed, 111 insertions, 94 deletions
diff --git a/tests/fuzzer.rs b/tests/fuzzer.rs index 44d4297..8ed21f2 100644 --- a/tests/fuzzer.rs +++ b/tests/fuzzer.rs @@ -48,7 +48,8 @@ fn binary_circular_array() { // Issue 20 - not found by fuzzing but this is a convenient place to put the test. #[test] fn issue_20_binary_with_data_in_trailer() { - let data = b"bplist00\xd0\x08\0\0\0\0\0\0\x01\x01\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\t"; + let data = + b"bplist00\xd0\x08\0\0\0\0\0\0\x01\x01\0\0\0\0\0\0\0\x01\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\t"; test_fuzzer_data_ok(data); } diff --git a/tests/serde_tests/mod.rs b/tests/serde_tests/mod.rs index d8583a2..c4b8c4a 100644 --- a/tests/serde_tests/mod.rs +++ b/tests/serde_tests/mod.rs @@ -1,5 +1,5 @@ use plist::{Date, EventWriter, PlistEvent, Result as PlistResult}; -use plist::serde::{Serializer, Deserializer}; +use plist::serde::{Deserializer, Serializer}; use plist::PlistEvent::*; use serde::de::DeserializeOwned; use serde::ser::Serialize; @@ -37,7 +37,8 @@ fn new_deserializer(events: Vec<PlistEvent>) -> Deserializer<Vec<PlistResult<Pli } fn assert_roundtrip<T>(obj: T, comparison: Option<&[PlistEvent]>) - where T: Debug + DeserializeOwned + PartialEq + Serialize +where + T: Debug + DeserializeOwned + PartialEq + Serialize, { let mut se = new_serializer(); @@ -84,75 +85,82 @@ struct DogInner { fn cow() { let cow = Animal::Cow; - let comparison = &[StartDictionary(Some(1)), - StringValue("Cow".to_owned()), - StringValue("".to_owned()), - EndDictionary]; + 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()], - }], + inner: vec![ + DogInner { + a: (), + b: 12, + c: vec!["a".to_string(), "b".to_string()], + }, + ], }); - let comparison = &[StartDictionary(Some(1)), - StringValue("Dog".to_owned()), - StartDictionary(None), - StringValue("inner".to_owned()), - StartArray(Some(1)), - StartDictionary(None), - 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]; + let comparison = &[ + StartDictionary(Some(1)), + StringValue("Dog".to_owned()), + StartDictionary(None), + StringValue("inner".to_owned()), + StartArray(Some(1)), + StartDictionary(None), + 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]; + 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 { @@ -161,27 +169,29 @@ fn cat() { firmware: Some(vec![0, 1, 2, 3, 4, 5, 6, 7, 8]), }; - let comparison = &[StartDictionary(Some(1)), - StringValue("Cat".to_owned()), - StartDictionary(None), - StringValue("age".to_owned()), - IntegerValue(12), - StringValue("name".to_owned()), - StringValue("Paws".to_owned()), - StringValue("firmware".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]; + let comparison = &[ + StartDictionary(Some(1)), + StringValue("Cat".to_owned()), + StartDictionary(None), + StringValue("age".to_owned()), + IntegerValue(12), + StringValue("name".to_owned()), + StringValue("Paws".to_owned()), + StringValue("firmware".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, + ]; assert_roundtrip(cat, Some(comparison)); } @@ -196,11 +206,13 @@ struct NewtypeInner(u8, u8, u8); fn newtype_struct() { let newtype = NewtypeStruct(NewtypeInner(34, 32, 13)); - let comparison = &[StartArray(Some(3)), - IntegerValue(34), - IntegerValue(32), - IntegerValue(13), - EndArray]; + let comparison = &[ + StartArray(Some(3)), + IntegerValue(34), + IntegerValue(32), + IntegerValue(13), + EndArray, + ]; assert_roundtrip(newtype, Some(comparison)); } @@ -226,15 +238,17 @@ fn type_with_options() { c: Some(Box::new(inner)), }; - let comparison = &[StartDictionary(None), - StringValue("a".to_owned()), - StringValue("hello".to_owned()), - StringValue("c".to_owned()), - StartDictionary(None), - StringValue("b".to_owned()), - IntegerValue(12), - EndDictionary, - EndDictionary]; + let comparison = &[ + StartDictionary(None), + StringValue("a".to_owned()), + StringValue("hello".to_owned()), + StringValue("c".to_owned()), + StartDictionary(None), + StringValue("b".to_owned()), + IntegerValue(12), + EndDictionary, + EndDictionary, + ]; assert_roundtrip(obj, Some(comparison)); } @@ -254,12 +268,14 @@ fn type_with_date() { b: Some(date.clone()), }; - let comparison = &[StartDictionary(None), - StringValue("a".to_owned()), - IntegerValue(28), - StringValue("b".to_owned()), - DateValue(date), - EndDictionary]; + let comparison = &[ + StartDictionary(None), + StringValue("a".to_owned()), + IntegerValue(28), + StringValue("b".to_owned()), + DateValue(date), + EndDictionary, + ]; assert_roundtrip(obj, Some(comparison)); } |
