95
95
96
96
#[ cfg( test) ]
97
97
mod tests {
98
+ use crate :: matcher:: MatcherResult ;
98
99
use crate :: prelude:: * ;
99
100
100
101
#[ test]
@@ -121,4 +122,52 @@ mod tests {
121
122
fn does_not_match_non_utf_8_encoded_byte_sequence ( ) -> Result < ( ) > {
122
123
verify_that ! ( & [ 192 , 64 , 255 , 32 ] , not( is_utf8_string( eq( "A string" ) ) ) )
123
124
}
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
+ }
124
173
}
0 commit comments