| 649 | |
| 650 | @pytest.mark.parametrize("typ", [bytes, bytearray, memoryview]) |
| 651 | def test_max_length(self, proto, typ): |
| 652 | class Ex(msgspec.Struct): |
| 653 | x: Annotated[typ, Meta(max_length=2)] |
| 654 | |
| 655 | dec = proto.Decoder(Ex) |
| 656 | |
| 657 | for x in [b"", b"xx"]: |
| 658 | assert bytes(dec.decode(proto.encode(Ex(x))).x) == x |
| 659 | |
| 660 | err_msg = r"Expected `bytes` of length <= 2 - at `\$.x`" |
| 661 | with pytest.raises(msgspec.ValidationError, match=err_msg): |
| 662 | dec.decode(proto.encode(Ex(b"xxx"))) |
| 663 | |
| 664 | @pytest.mark.parametrize("typ", [bytes, bytearray, memoryview]) |
| 665 | def test_combinations(self, proto, typ): |