mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 17:27:53 +03:00
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:
parent
234eefc294
commit
e92da70818
@ -13,4 +13,5 @@ serde = "1.0"
|
||||
vlqencoding = { path = "../vlqencoding" }
|
||||
|
||||
[dev-dependencies]
|
||||
quickcheck = "0.6"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
|
@ -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
25
lib/mincode/src/tests.rs
Normal 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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user