Move test to tests directory

This commit is contained in:
zypeh
2022-08-25 17:56:15 +08:00
committed by Lucas
parent f997a6250c
commit 9ded4d79d5
4 changed files with 85 additions and 21 deletions

View File

@@ -0,0 +1,34 @@
use flat_rs::{decode, encode};
#[cfg(test)]
mod test {
#[test]
fn encode_bool() {
let bytes = crate::encode(&true).unwrap();
assert_eq!(bytes, vec![0b10000001]);
let decoded: bool = crate::decode(bytes.as_slice()).unwrap();
assert_eq!(decoded, true);
let bytes = crate::encode(&false).unwrap();
assert_eq!(bytes, vec![0b00000001]);
let decoded: bool = crate::decode(bytes.as_slice()).unwrap();
assert_eq!(decoded, false);
}
#[test]
fn encode_u8() {
let bytes = crate::encode(&3_u8).unwrap();
assert_eq!(bytes, vec![0b00000011, 0b00000001]);
let decoded: u8 = crate::decode(bytes.as_slice()).unwrap();
assert_eq!(decoded, 3_u8);
}
}