mirror of
https://github.com/Cuprate/cuprate.git
synced 2024-12-23 12:09:52 +00:00
57af45e01d
Some checks are pending
Audit / audit (push) Waiting to run
CI / fmt (push) Waiting to run
CI / typo (push) Waiting to run
CI / ci (macos-latest, stable, bash) (push) Waiting to run
CI / ci (ubuntu-latest, stable, bash) (push) Waiting to run
CI / ci (windows-latest, stable-x86_64-pc-windows-gnu, msys2 {0}) (push) Waiting to run
Deny / audit (push) Waiting to run
Doc / build (push) Waiting to run
Doc / deploy (push) Blocked by required conditions
* epee-encoding: enable workspace lints * fmt * fixes * fixes * fmt
34 lines
882 B
Rust
34 lines
882 B
Rust
#![expect(unused_crate_dependencies, reason = "outer test module")]
|
|
|
|
use cuprate_epee_encoding::{epee_object, from_bytes, to_bytes};
|
|
|
|
#[derive(Clone)]
|
|
struct T {
|
|
val: Option<u8>,
|
|
}
|
|
|
|
epee_object!(
|
|
T,
|
|
val: Option<u8>,
|
|
);
|
|
|
|
#[test]
|
|
#[allow(clippy::useless_asref)]
|
|
fn optional_val_not_in_data() {
|
|
let bytes: &[u8] = b"\x01\x11\x01\x01\x01\x01\x02\x01\x01\x00";
|
|
let t: T = from_bytes(&mut bytes.as_ref()).unwrap();
|
|
let bytes2 = to_bytes(t.clone()).unwrap();
|
|
assert_eq!(bytes, bytes2);
|
|
assert!(t.val.is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn optional_val_in_data() {
|
|
let bytes = [
|
|
0x01, 0x11, 0x01, 0x1, 0x01, 0x01, 0x02, 0x1, 0x1, 0x04, 0x03, b'v', b'a', b'l', 0x08, 21,
|
|
];
|
|
let t: T = from_bytes(&mut &bytes[..]).unwrap();
|
|
let bytes2 = to_bytes(t.clone()).unwrap();
|
|
assert_eq!(bytes.as_slice(), &*bytes2);
|
|
assert_eq!(t.val.unwrap(), 21);
|
|
}
|