#![allow(clippy::unwrap_used, clippy::expect_used)]
mod shared;
use shared::assert_streamed_eq;
use data_stream::{
collections::{Size, SizeSettings},
default_settings::{NativeSettings, PortableSettings},
numbers::{Endian, EndianSettings},
to_stream,
};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, LinkedList, VecDeque};
macro_rules! impl_test {
($name: ident, $t: ty, $settings: ty) => {
#[test]
fn $name() {
assert_streamed_eq::<$settings, $t>(&vec![1, 2, 3, 4, 5].into_iter().collect());
}
};
}
macro_rules! impl_map_test {
($name: ident, $t: ty, $settings: ty) => {
#[test]
fn $name() {
assert_streamed_eq::<$settings, $t>(
&vec![(1, 1.0), (2, 2.0), (3, 3.0), (4, 4.0), (5, 5.0)]
.into_iter()
.collect(),
);
}
};
}
impl_test!(check_vec_native, Vec<u32>, NativeSettings);
impl_test!(check_vec_portable, Vec<u32>, PortableSettings);
impl_test!(check_vec_deque_native, VecDeque<u32>, NativeSettings);
impl_test!(check_vec_deque_portable, VecDeque<u32>, PortableSettings);
impl_test!(check_linked_list_native, LinkedList<u32>, NativeSettings);
impl_test!(
check_linked_list_portable,
LinkedList<u32>,
PortableSettings
);
impl_test!(check_hash_set_native, HashSet<u32>, NativeSettings);
impl_test!(check_hash_set_portable, HashSet<u32>, PortableSettings);
impl_test!(check_binary_tree_set_native, BTreeSet<u32>, NativeSettings);
impl_test!(
check_binary_tree_set_portable,
BTreeSet<u32>,
PortableSettings
);
impl_map_test!(check_hash_map_native, HashMap<u32, f64>, NativeSettings);
impl_map_test!(check_hash_map_portable, HashMap<u32, f64>, PortableSettings);
impl_map_test!(check_binary_tree_map_native, BTreeMap<u32, f64>, NativeSettings);
impl_map_test!(
check_binary_tree_map_portable,
BTreeMap<u32, f64>,
PortableSettings
);
struct U8Settings;
impl EndianSettings for U8Settings {
const ENDIAN: Endian = Endian::Little;
}
impl SizeSettings for U8Settings {
const SIZE: Size = Size::U8;
}
#[test]
fn size_overflow_fails() {
let big: Vec<u8> = vec![0; 0x100];
let mut bytes = Vec::new();
assert!(to_stream::<U8Settings, _, _>(&big, &mut bytes).is_err());
}