#![allow(dead_code)]
use core::fmt;
use flexstr_support::{StringLike, StringToFromBytes};
use inline_flexstr::InlineFlexStr;
pub fn test_creation_from_inline<S>(s: &'static S)
where
S: ?Sized + StringToFromBytes + fmt::Debug + PartialEq,
{
let inline_str = InlineFlexStr::try_from_type(s).unwrap();
assert_eq!(inline_str.as_ref_type(), s);
}
pub fn test_empty<S>(empty: &'static S)
where
S: ?Sized + StringToFromBytes,
InlineFlexStr<S>: StringLike<S>,
{
let inline_str = InlineFlexStr::try_from_type(empty).unwrap();
assert!(StringLike::is_empty(&inline_str));
assert_eq!(StringLike::len(&inline_str), 0);
}
pub fn test_accessors<S>(s: &'static S)
where
S: ?Sized + StringToFromBytes + fmt::Debug + PartialEq,
InlineFlexStr<S>: StringLike<S>,
{
let inline_str = InlineFlexStr::try_from_type(s).unwrap();
assert_eq!(inline_str.as_ref_type(), s);
let bytes = inline_str.as_bytes();
assert_eq!(bytes, S::self_as_bytes(s));
let raw_bytes = inline_str.as_raw_bytes();
assert_eq!(raw_bytes, S::self_as_raw_bytes(s));
assert_eq!(StringLike::len(&inline_str), s.self_as_bytes().len());
assert_eq!(
StringLike::is_empty(&inline_str),
s.self_as_bytes().is_empty()
);
}
pub fn test_clone<S>(s: &'static S)
where
S: ?Sized + StringToFromBytes + PartialEq + fmt::Debug,
{
let inline_str =
InlineFlexStr::try_from_type(s).expect("test input should be small enough to inline");
let cloned = inline_str;
assert_eq!(inline_str, cloned);
}
pub fn test_default<S>()
where
S: ?Sized + StringToFromBytes,
for<'a> &'a S: Default,
InlineFlexStr<S>: StringLike<S>,
{
let inline_str = InlineFlexStr::default();
assert!(StringLike::is_empty(&inline_str));
}