#![cfg(all( any(feature = "curr", feature = "next"), not(all(feature = "curr", feature = "next")) ))] #[cfg(feature = "curr")] use hcnet_xdr::curr as hcnet_xdr; #[cfg(feature = "next")] use hcnet_xdr::next as hcnet_xdr; use hcnet_xdr::{BytesM, Error, Hash, StringM, VecM}; #[test] fn test_debug() { // Renders as array. assert_eq!( format!( "{:?}", <_ as TryInto>>::try_into("hello world").unwrap() ), "VecM([104, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100])" ); // Renders as hex. assert_eq!( format!( "{:?}", <_ as TryInto>::try_into("hello world").unwrap() ), "BytesM(68656c6c6f20776f726c64)" ); // Renders as string. assert_eq!( format!( "{:?}", <_ as TryInto>::try_into("hello world").unwrap() ), "StringM(hello world)" ); // Renders as hex. assert_eq!( format!( "{:?}", <_ as TryInto>::try_into(*b"01234567890123456789013456789012").unwrap() ), "Hash(3031323334353637383930313233343536373839303133343536373839303132)" ); } #[test] fn test_debug_invalid_utf8() -> Result<(), Error> { // VecM is unchanged. assert_eq!( format!( "{:?}", <_ as TryInto>>::try_into(b"hello\xc3\x28world")? ), "VecM([104, 101, 108, 108, 111, 195, 40, 119, 111, 114, 108, 100])" ); // BytesM is unchanged. assert_eq!( format!( "{:?}", <_ as TryInto>::try_into(b"hello\xc3\x28world")? ), "BytesM(68656c6c6fc328776f726c64)" ); // StringM escapes strings. assert_eq!( format!( "{:?}", <_ as TryInto>::try_into(b"hello\xc3\x28world")? ), r"StringM(hello\xc3(world)" ); Ok(()) } #[test] fn test_display() -> Result<(), Error> { // Renders as hex. assert_eq!( format!("{}", <_ as TryInto>::try_into("hello world")?), "68656c6c6f20776f726c64" ); // Renders as string. assert_eq!( format!("{}", <_ as TryInto>::try_into("hello world")?), "hello world" ); // Renders as hex. assert_eq!( format!( "{}", <_ as TryInto>::try_into(*b"01234567890123456789013456789012").unwrap() ), "3031323334353637383930313233343536373839303133343536373839303132" ); Ok(()) } #[test] fn test_display_invalid_utf8() -> Result<(), Error> { // BytesM is unchanged. assert_eq!( format!( "{}", <_ as TryInto>::try_into(b"hello\xc3\x28world")? ), "68656c6c6fc328776f726c64" ); // StringM escapes strings. assert_eq!( format!( "{}", <_ as TryInto>::try_into(b"hello\xc3\x28world")? ), r"hello\xc3(world" ); Ok(()) }