#![cfg(feature = "alloc")]
use proptest::prelude::*;
proptest! {
#[test]
fn integer_roundtrip_via_codec(value in any::<u128>()) {
let config = rustbinary::options();
let frame = config.serialize(&value).unwrap();
let decoded: u128 = config.deserialize(&frame).unwrap();
prop_assert_eq!(decoded, value);
}
#[test]
fn signed_roundtrip_via_codec(value in any::<i128>()) {
let config = rustbinary::options();
let frame = config.serialize(&value).unwrap();
let decoded: i128 = config.deserialize(&frame).unwrap();
prop_assert_eq!(decoded, value);
}
#[test]
fn integer_frame_is_bounded(value in any::<u128>()) {
let config = rustbinary::options();
let frame = config.serialize(&value).unwrap();
prop_assert!(frame.len() <= 1 + 17, "frame too large: {}", frame.len());
}
#[test]
fn decoder_rejects_wide_forms(small in 0u64..(u32::MAX as u64) + 1) {
let config = rustbinary::options();
let mut frame = vec![0x03, 252];
frame.extend_from_slice(&(small as u32).to_le_bytes());
let result: Result<u64, _> = config.deserialize(&frame);
if small < 0x1_0000 {
prop_assert!(result.is_err(), "non-canonical form accepted for {small}");
} else {
prop_assert_eq!(result.unwrap(), small);
}
}
}