#![cfg(feature = "binary")]
use udled::bytes::{Binary, Endian};
use udled::Input;
#[test]
fn endian_constants() {
assert_eq!(Endian::network(), Endian::Big);
}
#[test]
fn binary_u8() {
let mut input = Input::new(&[0x42u8] as &[u8]);
let item = input.parse(Binary::<u8, _>::native()).unwrap();
assert_eq!(item.value, 0x42);
}
#[test]
fn binary_u16_little() {
let mut input = Input::new(&[0x34u8, 0x12] as &[u8]);
let item = input.parse(Binary::<u16, _>::lt()).unwrap();
assert_eq!(item.value, 0x1234);
}
#[test]
fn binary_u16_big() {
let mut input = Input::new(&[0x12u8, 0x34] as &[u8]);
let item = input.parse(Binary::<u16, _>::big()).unwrap();
assert_eq!(item.value, 0x1234);
}
#[test]
fn binary_u32_little() {
let mut input = Input::new(&[0x78u8, 0x56, 0x34, 0x12] as &[u8]);
let item = input.parse(Binary::<u32, _>::lt()).unwrap();
assert_eq!(item.value, 0x12345678);
}
#[test]
fn binary_i8() {
let mut input = Input::new(&[0xFFu8] as &[u8]);
let item = input.parse(Binary::<i8, _>::native()).unwrap();
assert_eq!(item.value, -1);
}
#[test]
fn binary_not_enough_bytes() {
let mut input = Input::new(&[0x12u8] as &[u8]);
assert!(input.parse(Binary::<u16, _>::native()).is_err());
}
#[test]
fn from_bytes_ext() {
let mut input = Input::new(&[0x34u8, 0x12] as &[u8]);
let item = input.parse(Binary::<u16, _>::lt()).unwrap();
assert_eq!(item.value, 0x1234);
let mut input = Input::new(&[0x12u8, 0x34] as &[u8]);
let item = input.parse(Binary::<u16, _>::big()).unwrap();
assert_eq!(item.value, 0x1234);
}