use af_core::string::SharedString;
use af_core::test::prelude::*;
pub fn test(cx: &mut test::Context) {
cx.scope("::SharedString", |cx| {
test!(cx, "functions as a string", {
let value = "hello world";
let shared = SharedString::from(value);
fail::when!(shared.as_str() != value, "`as_str()` is not {:?}.", value);
fail::when!(shared.to_string() != value, "`to_string()` is not {:?}", value);
fail::when!(AsRef::<str>::as_ref(&shared) != value, "`as_ref()` is not {:?}.", value);
});
test!(cx, "::from<&'static str>() is cheap", {
let value = "check";
let shared = SharedString::from(value);
fail::when!(!ptr::eq(shared.as_str(), value), "Value was copied.");
});
test!(cx, "::clone() is cheap", {
let shared = SharedString::from("hello world");
let clone = shared.clone();
fail::when!(!ptr::eq(clone.as_str(), shared.as_str()), "First clone is different.");
let shared = SharedString::from(String::from("hello world"));
let clone = shared.clone();
fail::when!(!ptr::eq(clone.as_str(), shared.as_str()), "Second clone is different.");
});
});
}