| 445 | |
| 446 | class TestStrConstraints: |
| 447 | def test_min_length(self, proto): |
| 448 | class Ex(msgspec.Struct): |
| 449 | x: Annotated[str, Meta(min_length=2)] |
| 450 | |
| 451 | dec = proto.Decoder(Ex) |
| 452 | |
| 453 | for x in ["xx", "xxx", "𝄞x"]: |
| 454 | assert dec.decode(proto.encode(Ex(x))).x == x |
| 455 | |
| 456 | err_msg = r"Expected `str` of length >= 2 - at `\$.x`" |
| 457 | for x in ["x", "𝄞", ""]: |
| 458 | with pytest.raises(msgspec.ValidationError, match=err_msg): |
| 459 | dec.decode(proto.encode(Ex(x))) |
| 460 | |
| 461 | def test_max_length(self, proto): |
| 462 | class Ex(msgspec.Struct): |