#![cfg(feature = "jit")]
use facet_postcard::from_slice;
#[test]
fn test_empty_vec_bool() {
let input = [0x00u8];
let result: Vec<bool> = from_slice(&input).expect("should deserialize empty vec");
assert_eq!(result, vec![]);
}
#[test]
fn test_single_bool_true() {
let input = [0x01, 0x01];
let result: Vec<bool> = from_slice(&input).expect("should deserialize [true]");
assert_eq!(result, vec![true]);
}
#[test]
fn test_single_bool_false() {
let input = [0x01, 0x00];
let result: Vec<bool> = from_slice(&input).expect("should deserialize [false]");
assert_eq!(result, vec![false]);
}
#[test]
fn test_multiple_bools() {
let input = [0x03, 0x01, 0x00, 0x01];
let result: Vec<bool> = from_slice(&input).expect("should deserialize [true, false, true]");
assert_eq!(result, vec![true, false, true]);
}
#[test]
fn test_many_bools() {
let mut input = vec![0x0A]; for i in 0..10 {
input.push(if i % 2 == 0 { 1 } else { 0 });
}
let result: Vec<bool> = from_slice(&input).expect("should deserialize 10 bools");
let expected: Vec<bool> = (0..10).map(|i| i % 2 == 0).collect();
assert_eq!(result, expected);
}
#[test]
fn test_vec_bool_large_length() {
let mut input = vec![0x80, 0x01]; for i in 0..128 {
input.push(if i % 3 == 0 { 1 } else { 0 });
}
let result: Vec<bool> = from_slice(&input).expect("should deserialize 128 bools");
assert_eq!(result.len(), 128);
for (i, &b) in result.iter().enumerate() {
assert_eq!(b, i % 3 == 0, "mismatch at index {}", i);
}
}
#[test]
fn test_invalid_bool_value() {
let input = [0x01, 0x02];
let result: Result<Vec<bool>, _> = from_slice(&input);
assert!(result.is_err(), "should fail on invalid bool value");
}
#[test]
fn test_truncated_input() {
let input = [0x03, 0x01];
let result: Result<Vec<bool>, _> = from_slice(&input);
assert!(result.is_err(), "should fail on truncated input");
}
#[test]
fn test_matches_reference_postcard() {
let original = vec![true, false, true, false, true];
let encoded = postcard::to_allocvec(&original).expect("postcard should serialize");
assert_eq!(encoded, vec![0x05, 0x01, 0x00, 0x01, 0x00, 0x01]);
let result: Vec<bool> = from_slice(&encoded).expect("should deserialize");
assert_eq!(result, original);
}
#[test]
fn test_roundtrip_various_sizes() {
for size in [0, 1, 2, 10, 100, 127, 128, 255, 256] {
let original: Vec<bool> = (0..size).map(|i| i % 2 == 0).collect();
let encoded = postcard::to_allocvec(&original).expect("postcard should serialize");
let result: Vec<bool> = from_slice(&encoded).expect("should deserialize");
assert_eq!(result, original, "mismatch for size {}", size);
}
}