Skip to content

Commit 505ea53

Browse files
committed
Add tests of describe and explain_match
1 parent e6a8c7f commit 505ea53

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

googletest/src/matchers/is_encoded_string_matcher.rs

+49
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ where
9595

9696
#[cfg(test)]
9797
mod tests {
98+
use crate::matcher::MatcherResult;
9899
use crate::prelude::*;
99100

100101
#[test]
@@ -121,4 +122,52 @@ mod tests {
121122
fn does_not_match_non_utf_8_encoded_byte_sequence() -> Result<()> {
122123
verify_that!(&[192, 64, 255, 32], not(is_utf8_string(eq("A string"))))
123124
}
125+
126+
#[test]
127+
fn has_correct_description_in_matched_case() -> Result<()> {
128+
let matcher = is_utf8_string::<&[u8], _>(eq("A string"));
129+
130+
verify_that!(
131+
matcher.describe(MatcherResult::Match),
132+
eq("is a UTF-8 encoded string which is equal to \"A string\"")
133+
)
134+
}
135+
136+
#[test]
137+
fn has_correct_description_in_not_matched_case() -> Result<()> {
138+
let matcher = is_utf8_string::<&[u8], _>(eq("A string"));
139+
140+
verify_that!(
141+
matcher.describe(MatcherResult::NoMatch),
142+
eq("is not a UTF-8 encoded string which is equal to \"A string\"")
143+
)
144+
}
145+
146+
#[test]
147+
fn has_correct_explanation_in_matched_case() -> Result<()> {
148+
let explanation = is_utf8_string(eq("A string")).explain_match(&"A string".as_bytes());
149+
150+
verify_that!(
151+
explanation,
152+
eq("which is a UTF-8 encoded string which is equal to \"A string\"")
153+
)
154+
}
155+
156+
#[test]
157+
fn has_correct_explanation_when_byte_array_is_not_utf8_encoded() -> Result<()> {
158+
let explanation = is_utf8_string(eq("A string")).explain_match(&&[192, 128, 0, 64]);
159+
160+
verify_that!(explanation, eq("which is not a UTF-8 encoded string"))
161+
}
162+
163+
#[test]
164+
fn has_correct_explanation_when_inner_matcher_does_not_match() -> Result<()> {
165+
let explanation =
166+
is_utf8_string(eq("A string")).explain_match(&"Another string".as_bytes());
167+
168+
verify_that!(
169+
explanation,
170+
eq("which is a UTF-8 encoded string which isn't equal to \"A string\"")
171+
)
172+
}
124173
}

0 commit comments

Comments
 (0)