| 281 | ], |
| 282 | ) |
| 283 | def test_bounds(self, proto, name, bound, good, bad): |
| 284 | if proto is msgspec.msgpack: |
| 285 | # msgpack only supports int64/uint64 values |
| 286 | good = [i for i in good if -(2**63) - 1 <= i <= 2**64] |
| 287 | bad = [i for i in bad if -(2**63) - 1 <= i <= 2**64] |
| 288 | |
| 289 | class Ex(msgspec.Struct): |
| 290 | x: Annotated[int, Meta(**{name: bound})] |
| 291 | |
| 292 | dec = proto.Decoder(Ex) |
| 293 | |
| 294 | for x in good: |
| 295 | assert dec.decode(proto.encode(Ex(x))).x == x |
| 296 | |
| 297 | op = ">=" if name.startswith("g") else "<=" |
| 298 | offset = {"lt": -1, "gt": 1}.get(name, 0) |
| 299 | err_msg = rf"Expected `int` {op} {bound + offset} - at `\$.x`" |
| 300 | for x in bad: |
| 301 | with pytest.raises(msgspec.ValidationError, match=err_msg): |
| 302 | dec.decode(proto.encode(Ex(x))) |
| 303 | |
| 304 | def test_multiple_of(self, proto): |
| 305 | good = [-(2**64), -2, 0, 2, 40, 2**63 + 2, 2**65] |