#![allow(
clippy::approx_constant,
clippy::useless_vec,
clippy::len_zero,
clippy::unnecessary_cast,
clippy::redundant_closure,
clippy::too_many_arguments,
clippy::type_complexity,
clippy::needless_borrow,
clippy::enum_variant_names,
clippy::upper_case_acronyms,
clippy::inconsistent_digit_grouping,
clippy::unit_cmp,
clippy::assertions_on_constants,
clippy::iter_on_single_items,
clippy::expect_fun_call,
clippy::redundant_pattern_matching,
variant_size_differences,
clippy::absurd_extreme_comparisons,
clippy::nonminimal_bool,
clippy::for_kv_map,
clippy::needless_range_loop,
clippy::single_match,
clippy::collapsible_if,
clippy::needless_return,
clippy::redundant_clone,
clippy::map_entry,
clippy::match_single_binding,
clippy::bool_comparison,
clippy::derivable_impls,
clippy::manual_range_contains,
clippy::needless_borrows_for_generic_args,
clippy::manual_map,
clippy::vec_init_then_push,
clippy::identity_op,
clippy::manual_flatten,
clippy::single_char_pattern,
clippy::search_is_some,
clippy::option_map_unit_fn,
clippy::while_let_on_iterator,
clippy::clone_on_copy,
clippy::box_collection,
clippy::redundant_field_names,
clippy::ptr_arg,
clippy::large_enum_variant,
clippy::match_ref_pats,
clippy::needless_pass_by_value,
clippy::unused_unit,
clippy::let_and_return,
clippy::suspicious_else_formatting,
clippy::manual_strip,
clippy::match_like_matches_macro,
clippy::from_over_into,
clippy::wrong_self_convention,
clippy::inherent_to_string,
clippy::new_without_default,
clippy::unnecessary_wraps,
clippy::field_reassign_with_default,
clippy::manual_find,
clippy::unnecessary_lazy_evaluations,
clippy::should_implement_trait,
clippy::missing_safety_doc,
clippy::unusual_byte_groupings,
clippy::bool_assert_comparison,
clippy::zero_prefixed_literal,
clippy::await_holding_lock,
clippy::manual_saturating_arithmetic,
clippy::explicit_counter_loop,
clippy::needless_lifetimes,
clippy::single_component_path_imports,
clippy::uninlined_format_args,
clippy::iter_cloned_collect,
clippy::manual_str_repeat,
clippy::excessive_precision,
clippy::precedence,
clippy::unnecessary_literal_unwrap
)]
use oxicode::{decode_from_slice, encode_to_vec};
#[test]
fn test_wire_u8_zero() {
let enc = encode_to_vec(&0u8).expect("encode u8 0");
assert_eq!(enc, vec![0x00u8], "u8(0) must encode to a single zero byte");
let (val, _): (u8, _) = decode_from_slice(&enc).expect("decode u8 0");
assert_eq!(val, 0u8);
}
#[test]
fn test_wire_u8_one() {
let enc = encode_to_vec(&1u8).expect("encode u8 1");
assert_eq!(enc, vec![0x01u8], "u8(1) must encode to [0x01]");
let (val, _): (u8, _) = decode_from_slice(&enc).expect("decode u8 1");
assert_eq!(val, 1u8);
}
#[test]
fn test_wire_u8_127() {
let enc = encode_to_vec(&127u8).expect("encode u8 127");
assert_eq!(enc, vec![0x7Fu8], "u8(127) must encode to [0x7F]");
let (val, _): (u8, _) = decode_from_slice(&enc).expect("decode u8 127");
assert_eq!(val, 127u8);
}
#[test]
fn test_wire_u8_255() {
let enc = encode_to_vec(&255u8).expect("encode u8 255");
assert_eq!(enc, vec![0xFFu8], "u8(255) must encode to [0xFF]");
let (val, _): (u8, _) = decode_from_slice(&enc).expect("decode u8 255");
assert_eq!(val, 255u8);
}
#[test]
fn test_wire_u16_zero() {
let enc = encode_to_vec(&0u16).expect("encode u16 0");
assert_eq!(enc, vec![0x00u8], "u16(0) varint must encode to [0x00]");
assert_eq!(enc.len(), 1, "u16(0) must be 1 byte");
let (val, _): (u16, _) = decode_from_slice(&enc).expect("decode u16 0");
assert_eq!(val, 0u16);
}
#[test]
fn test_wire_u16_255() {
let enc = encode_to_vec(&255u16).expect("encode u16 255");
assert_eq!(
enc,
vec![0xFBu8, 0xFFu8, 0x00u8],
"u16(255) varint must be [0xFB, 0xFF, 0x00]"
);
assert_eq!(enc.len(), 3, "u16(255) varint must be 3 bytes");
let (val, _): (u16, _) = decode_from_slice(&enc).expect("decode u16 255");
assert_eq!(val, 255u16);
}
#[test]
fn test_wire_u32_zero() {
let enc = encode_to_vec(&0u32).expect("encode u32 0");
assert_eq!(enc, vec![0x00u8], "u32(0) varint must encode to [0x00]");
let (val, _): (u32, _) = decode_from_slice(&enc).expect("decode u32 0");
assert_eq!(val, 0u32);
}
#[test]
fn test_wire_u32_one() {
let enc = encode_to_vec(&1u32).expect("encode u32 1");
assert_eq!(enc, vec![0x01u8], "u32(1) varint must encode to [0x01]");
let (val, _): (u32, _) = decode_from_slice(&enc).expect("decode u32 1");
assert_eq!(val, 1u32);
}
#[test]
fn test_wire_u32_250() {
let enc = encode_to_vec(&250u32).expect("encode u32 250");
assert_eq!(
enc,
vec![0xFAu8],
"u32(250) varint must encode to [0xFA] (single byte)"
);
assert_eq!(enc.len(), 1, "u32(250) must be 1 byte");
let (val, _): (u32, _) = decode_from_slice(&enc).expect("decode u32 250");
assert_eq!(val, 250u32);
}
#[test]
fn test_wire_u32_251() {
let enc = encode_to_vec(&251u32).expect("encode u32 251");
assert_eq!(
enc,
vec![0xFBu8, 0xFBu8, 0x00u8],
"u32(251) varint must be [0xFB, 0xFB, 0x00]"
);
assert_eq!(enc.len(), 3, "u32(251) varint must be 3 bytes");
let (val, _): (u32, _) = decode_from_slice(&enc).expect("decode u32 251");
assert_eq!(val, 251u32);
}
#[test]
fn test_wire_bool_true() {
let enc = encode_to_vec(&true).expect("encode bool true");
assert_eq!(enc, vec![0x01u8], "bool(true) must encode to [0x01]");
assert_eq!(enc.len(), 1);
let (val, _): (bool, _) = decode_from_slice(&enc).expect("decode bool true");
assert!(val);
}
#[test]
fn test_wire_bool_false() {
let enc = encode_to_vec(&false).expect("encode bool false");
assert_eq!(enc, vec![0x00u8], "bool(false) must encode to [0x00]");
assert_eq!(enc.len(), 1);
let (val, _): (bool, _) = decode_from_slice(&enc).expect("decode bool false");
assert!(!val);
}
#[test]
fn test_wire_string_empty() {
let s = String::new();
let enc = encode_to_vec(&s).expect("encode empty String");
assert_eq!(
enc,
vec![0x00u8],
"empty String must encode to a single 0x00 length prefix"
);
let (val, _): (String, _) = decode_from_slice(&enc).expect("decode empty String");
assert_eq!(val, "");
}
#[test]
fn test_wire_string_single_char() {
let s = String::from("A");
let enc = encode_to_vec(&s).expect("encode String \"A\"");
assert_eq!(
enc,
vec![0x01u8, 0x41u8],
"String(\"A\") must encode to [0x01, 0x41]"
);
let (val, _): (String, _) = decode_from_slice(&enc).expect("decode String \"A\"");
assert_eq!(val, "A");
}
#[test]
fn test_wire_vec_u8_empty() {
let v: Vec<u8> = Vec::new();
let enc = encode_to_vec(&v).expect("encode empty Vec<u8>");
assert_eq!(enc, vec![0x00u8], "empty Vec<u8> must encode to [0x00]");
let (val, _): (Vec<u8>, _) = decode_from_slice(&enc).expect("decode empty Vec<u8>");
assert!(val.is_empty());
}
#[test]
fn test_wire_vec_u8_single_byte() {
let v: Vec<u8> = vec![0xFF];
let enc = encode_to_vec(&v).expect("encode Vec<u8> [0xFF]");
assert_eq!(
enc,
vec![0x01u8, 0xFFu8],
"Vec<u8>([0xFF]) must encode to [0x01, 0xFF]"
);
let (val, _): (Vec<u8>, _) = decode_from_slice(&enc).expect("decode Vec<u8> [0xFF]");
assert_eq!(val, vec![0xFFu8]);
}
#[test]
fn test_wire_option_u8_none() {
let v: Option<u8> = None;
let enc = encode_to_vec(&v).expect("encode Option<u8> None");
assert_eq!(enc, vec![0x00u8], "Option<u8>(None) must encode to [0x00]");
let (val, _): (Option<u8>, _) = decode_from_slice(&enc).expect("decode Option<u8> None");
assert_eq!(val, None);
}
#[test]
fn test_wire_option_u8_some() {
let v: Option<u8> = Some(42);
let enc = encode_to_vec(&v).expect("encode Option<u8> Some(42)");
assert_eq!(
enc,
vec![0x01u8, 0x2Au8],
"Option<u8>(Some(42)) must encode to [0x01, 0x2A]"
);
let (val, _): (Option<u8>, _) = decode_from_slice(&enc).expect("decode Option<u8> Some(42)");
assert_eq!(val, Some(42u8));
}
#[test]
fn test_wire_fixed_array_u8() {
let arr: [u8; 3] = [1, 2, 3];
let enc = encode_to_vec(&arr).expect("encode [u8; 3]");
assert_eq!(
enc,
vec![0x01u8, 0x02u8, 0x03u8],
"[u8; 3]([1,2,3]) must encode to [0x01, 0x02, 0x03] with no length prefix"
);
assert_eq!(enc.len(), 3, "fixed array must not add a length prefix");
let (val, _): ([u8; 3], _) = decode_from_slice(&enc).expect("decode [u8; 3]");
assert_eq!(val, [1u8, 2, 3]);
}
#[test]
fn test_wire_u64_zero() {
let enc = encode_to_vec(&0u64).expect("encode u64 0");
assert_eq!(enc, vec![0x00u8], "u64(0) varint must encode to [0x00]");
assert_eq!(enc.len(), 1);
let (val, _): (u64, _) = decode_from_slice(&enc).expect("decode u64 0");
assert_eq!(val, 0u64);
}
#[test]
fn test_wire_i8_minus_one() {
let enc = encode_to_vec(&(-1i8)).expect("encode i8 -1");
assert_eq!(
enc,
vec![0xFFu8],
"i8(-1) must encode as raw byte 0xFF (no zigzag, direct u8 cast)"
);
assert_eq!(enc.len(), 1);
let (val, _): (i8, _) = decode_from_slice(&enc).expect("decode i8 -1");
assert_eq!(val, -1i8);
}
#[test]
fn test_wire_i32_minus_one() {
let enc = encode_to_vec(&(-1i32)).expect("encode i32 -1");
assert_eq!(
enc,
vec![0x01u8],
"i32(-1) zigzag varint must encode to [0x01] (zigzag maps -1 → 1)"
);
assert_eq!(enc.len(), 1);
let (val, _): (i32, _) = decode_from_slice(&enc).expect("decode i32 -1");
assert_eq!(val, -1i32);
}