Commit a5fa333
Include the type and variant being matched in the description of the matcher created by
Previously, the description would defer immediately to the inner matcher of the respective field or property. This was problematic when matching enum variants, since the variant itself would be left out. For example, the following code:
```
enum AnEnum {
A(u32),
B(u32),
}
let value = AnEnum::B(123);
verify_that!(value, matches_pattern!(AnEnum::A(eq(123)))
```
would yield the following assertion failure message:
```
Value of: value
Expected: has field `0`, which is equal to 123
Actual: AnEnum::B(123),
which does not have field `0`
```
The failure message does not give any indication that the expected variant is `MyEnum::A` and is therefore misleading.
This change introduces a new matcher `is` which does nothing but defer to an inner matcher and add a given string to the description. With this new matcher, `matches_pattern!` now outputs the expected type or enum variant in the description:
```
Value of: value
Expected: is AnEnum :: A which has field `0`, which is equal to 123
Actual: AnEnum::B(123),
which does not have field `0`
```
The match explanation is admittedly still rather confusing in this case, but fixing that is outside the scope of this change.
For consistency, this change also implements the new behaviour with properties as well as fields, even though properties cannot be used with enum variants.
This does not import the new matcher `is` into the list of matchers included in the prelude or the top-level list of matchers for the crate. The usefulness of `is` is fairly limited, so it does not seem worthwhile to include it. It must however have public visibility because it is used in a declarative macro.
PiperOrigin-RevId: 542850294matches_pattern!.1 parent af4ae8f commit a5fa333
File tree
4 files changed
+296
-15
lines changed- googletest
- src/matchers
- tests
4 files changed
+296
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
259 | 259 | | |
260 | 260 | | |
261 | 261 | | |
262 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
263 | 266 | | |
264 | 267 | | |
265 | 268 | | |
266 | 269 | | |
267 | 270 | | |
268 | 271 | | |
269 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
270 | 276 | | |
271 | 277 | | |
272 | 278 | | |
273 | 279 | | |
274 | 280 | | |
275 | 281 | | |
276 | | - | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
277 | 286 | | |
278 | 287 | | |
279 | 288 | | |
| |||
314 | 323 | | |
315 | 324 | | |
316 | 325 | | |
317 | | - | |
| 326 | + | |
318 | 327 | | |
319 | 328 | | |
320 | | - | |
| 329 | + | |
321 | 330 | | |
322 | 331 | | |
323 | 332 | | |
324 | 333 | | |
325 | 334 | | |
326 | 335 | | |
327 | 336 | | |
328 | | - | |
| 337 | + | |
329 | 338 | | |
330 | 339 | | |
331 | | - | |
| 340 | + | |
332 | 341 | | |
333 | 342 | | |
334 | 343 | | |
335 | 344 | | |
336 | 345 | | |
337 | 346 | | |
338 | 347 | | |
339 | | - | |
| 348 | + | |
340 | 349 | | |
341 | 350 | | |
342 | | - | |
| 351 | + | |
343 | 352 | | |
344 | 353 | | |
345 | 354 | | |
| |||
401 | 410 | | |
402 | 411 | | |
403 | 412 | | |
404 | | - | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
405 | 417 | | |
406 | 418 | | |
407 | 419 | | |
| |||
424 | 436 | | |
425 | 437 | | |
426 | 438 | | |
427 | | - | |
| 439 | + | |
428 | 440 | | |
429 | 441 | | |
430 | | - | |
| 442 | + | |
431 | 443 | | |
432 | 444 | | |
433 | 445 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
0 commit comments