mincode: add a basic test

Summary: Add a basic test to ensure mincode is somehow working.

Reviewed By: kulshrax

Differential Revision: D17087350

fbshipit-source-id: efa5d18e579688521e91fe28ee67f1d7f7c15558
This commit is contained in:
Jun Wu 2019-09-06 13:10:33 -07:00 committed by Facebook Github Bot
parent 234eefc294
commit e92da70818
3 changed files with 29 additions and 0 deletions

View File

@ -13,4 +13,5 @@ serde = "1.0"
vlqencoding = { path = "../vlqencoding" }
[dev-dependencies]
quickcheck = "0.6"
serde = { version = "1.0", features = ["derive"] }

View File

@ -8,6 +8,9 @@ mod de;
mod error;
mod ser;
#[cfg(test)]
mod tests;
use self::de::Deserializer;
use self::ser::Serializer;
use serde::{Deserialize, Serialize};

25
lib/mincode/src/tests.rs Normal file
View File

@ -0,0 +1,25 @@
// Copyright (c) Facebook, Inc. and its affiliates.
//
// This software may be used and distributed according to the terms of the
// GNU General Public License version 2.
use quickcheck::quickcheck;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, PartialEq, Debug)]
struct Foo {
bar: String,
baz: Option<(f64, i32, u8)>,
derp: bool,
list: Vec<u32>,
}
quickcheck! {
fn test_roundtrip(bar: String, baz: Option<(f64, i32, u8)>, derp: bool, list: Vec<u32>) -> bool {
let foo = Foo { bar, baz, derp, list };
let mut bytes = Vec::new();
crate::serialize(&mut bytes, &foo).unwrap();
let foo_deserialized: Foo = crate::deserialize(&bytes).unwrap();
foo == foo_deserialized
}
}