Function googletest::matchers::is_utf8_string
source · pub fn is_utf8_string<'a, ActualT: AsRef<[u8]> + Debug + 'a, InnerMatcherT>(
inner: InnerMatcherT
) -> impl Matcher<ActualT = ActualT>
Expand description
Matches a byte sequence which is a UTF-8 encoded string matched by inner
.
The matcher reports no match if either the string is not UTF-8 encoded or if
inner
does not match on the decoded string.
The input may be a slice &[u8]
or a Vec
of bytes.
let bytes: &[u8] = "A string".as_bytes();
verify_that!(bytes, is_utf8_string(eq("A string")))?; // Passes
let bytes: Vec<u8> = "A string".as_bytes().to_vec();
verify_that!(bytes, is_utf8_string(eq("A string")))?; // Passes
verify_that!(bytes, is_utf8_string(eq("Another string")))?; // Fails (inner matcher does not match)
let bytes: Vec<u8> = vec![255, 64, 128, 32];
verify_that!(bytes, is_utf8_string(anything()))?; // Fails (not UTF-8 encoded)