| 459 | dec.decode(proto.encode(Ex(x))) |
| 460 | |
| 461 | def test_max_length(self, proto): |
| 462 | class Ex(msgspec.Struct): |
| 463 | x: Annotated[str, Meta(max_length=2)] |
| 464 | |
| 465 | dec = proto.Decoder(Ex) |
| 466 | |
| 467 | for x in ["", "xx", "𝄞x"]: |
| 468 | assert dec.decode(proto.encode(Ex(x))).x == x |
| 469 | |
| 470 | err_msg = r"Expected `str` of length <= 2 - at `\$.x`" |
| 471 | for x in ["xxx", "𝄞xx"]: |
| 472 | with pytest.raises(msgspec.ValidationError, match=err_msg): |
| 473 | dec.decode(proto.encode(Ex(x))) |
| 474 | |
| 475 | @pytest.mark.parametrize( |
| 476 | "pattern, good, bad", |