mod shared;
use shared::assert_streamed_eq;
use data_stream::{default_settings::PortableSettings, from_stream, to_stream};
#[test]
fn char_roundtrip_ascii() {
assert_streamed_eq::<PortableSettings, _>(&'a');
}
#[test]
fn char_roundtrip_multibyte() {
assert_streamed_eq::<PortableSettings, _>(&'€');
}
#[test]
fn char_roundtrip_emoji() {
assert_streamed_eq::<PortableSettings, _>(&'🦀');
}
#[test]
fn char_invalid_len_zero_fails() {
let bytes = [0u8];
let result = from_stream::<PortableSettings, char, _>(&mut &bytes[..]);
assert!(result.is_err());
}
#[test]
fn char_invalid_len_too_large_fails() {
let bytes = [5u8];
let result = from_stream::<PortableSettings, char, _>(&mut &bytes[..]);
assert!(result.is_err());
}
#[test]
fn char_invalid_utf8_fails() {
let bytes = [2u8, 0xC3, 0x28];
let result = from_stream::<PortableSettings, char, _>(&mut &bytes[..]);
assert!(result.is_err());
}
#[test]
fn string_roundtrip_normal() {
assert_streamed_eq::<PortableSettings, _>(&"hello".to_string());
}
#[test]
fn string_roundtrip_empty() {
assert_streamed_eq::<PortableSettings, _>(&String::new());
}
#[test]
fn string_invalid_utf8_fails() {
let bytes = [1u8, 0, 0, 0, 0xFF];
let result = from_stream::<PortableSettings, String, _>(&mut &bytes[..]);
assert!(result.is_err());
}
#[test]
fn str_and_string_same_encoding() {
let s = "hello";
let mut a = Vec::new();
let mut b = Vec::new();
to_stream::<PortableSettings, _, _>(s, &mut a).unwrap();
to_stream::<PortableSettings, _, _>(&s.to_string(), &mut b).unwrap();
assert_eq!(a, b);
}