cultcache-py, -rs and -ts: unit-arm tests assert against the bytes the C# reference wrote
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ef4326258d
commit
6afa8ed9c4
3 changed files with 31 additions and 8 deletions
|
|
@ -285,8 +285,10 @@ class UnionCodecRuleTests(unittest.TestCase):
|
|||
)
|
||||
|
||||
def test_unit_arm_is_written_with_empty_slots_and_reads_back(self) -> None:
|
||||
self.assertEqual(unit_outcome.encode(UnionArm("Denied")), [2, []])
|
||||
self.assertEqual(unit_outcome.decode([2, []]), UnionArm("Denied", None))
|
||||
# The bytes are the C# reference's (tests/vectors/union-parity/unit-arm-denied.msgpack), not spelled here.
|
||||
reference = _vector("unit-arm-denied.msgpack")
|
||||
self.assertEqual(msgpack.packb(unit_outcome.encode(UnionArm("Denied"))), reference)
|
||||
self.assertEqual(unit_outcome.decode(msgpack.unpackb(reference, raw=False)), UnionArm("Denied", None))
|
||||
|
||||
def test_unit_arm_refuses_a_value_to_carry(self) -> None:
|
||||
with self.assertRaises(ValueError) as caught:
|
||||
|
|
@ -738,8 +740,12 @@ class UnionDecodeBoundsTests(unittest.TestCase):
|
|||
self.assertEqual(str(caught.exception), expected)
|
||||
|
||||
def test_the_ends_of_the_int32_key_domain_are_unit_arms_that_read_and_write(self) -> None:
|
||||
self.assertEqual(unit_outcome.decode([-(2**31), []]), UnionArm("Floor"))
|
||||
self.assertEqual(unit_outcome.encode(UnionArm("Ceiling")), [2**31 - 1, []])
|
||||
floor = _vector("unit-arm-floor.msgpack")
|
||||
ceiling = _vector("unit-arm-ceiling.msgpack")
|
||||
self.assertEqual(unit_outcome.decode(msgpack.unpackb(floor, raw=False)), UnionArm("Floor"))
|
||||
self.assertEqual(msgpack.packb(unit_outcome.encode(UnionArm("Floor"))), floor)
|
||||
self.assertEqual(unit_outcome.decode(msgpack.unpackb(ceiling, raw=False)), UnionArm("Ceiling"))
|
||||
self.assertEqual(msgpack.packb(unit_outcome.encode(UnionArm("Ceiling"))), ceiling)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
|
|||
|
|
@ -100,6 +100,10 @@ enum Outcome {
|
|||
enum UnitOutcome {
|
||||
#[cultcache(key = 2)]
|
||||
Denied,
|
||||
#[cultcache(key = -2147483648)]
|
||||
Floor,
|
||||
#[cultcache(key = 2147483647)]
|
||||
Ceiling,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, CultSlots)]
|
||||
|
|
@ -250,8 +254,16 @@ fn union_surface_decodes_and_reencodes() {
|
|||
|
||||
#[test]
|
||||
fn a_unit_arm_is_a_key_and_an_empty_slots_array() {
|
||||
assert_eq!(rmp_serde::to_vec(&UnitOutcome::Denied).unwrap(), [0x92, 0x02, 0x90]);
|
||||
assert_eq!(rmp_serde::from_slice::<UnitOutcome>(&[0x92, 0x02, 0x90]).unwrap(), UnitOutcome::Denied);
|
||||
// The bytes are the C# reference's, not spelled here.
|
||||
for (file, arm) in [
|
||||
("unit-arm-denied.msgpack", UnitOutcome::Denied),
|
||||
("unit-arm-floor.msgpack", UnitOutcome::Floor),
|
||||
("unit-arm-ceiling.msgpack", UnitOutcome::Ceiling),
|
||||
] {
|
||||
let reference = vector(file);
|
||||
assert_eq!(rmp_serde::to_vec(&arm).unwrap(), reference, "{file}");
|
||||
assert_eq!(rmp_serde::from_slice::<UnitOutcome>(&reference).unwrap(), arm, "{file}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -219,8 +219,13 @@ test("the union surface vector decodes to the constructed value and re-encodes b
|
|||
assert.equal(hex(writeWire(surfaceCodec.encode(golden))), hex(committed));
|
||||
});
|
||||
|
||||
test("a unit arm is written [key, []] and its payload must be an array", () => {
|
||||
assert.deepEqual(outcome.encode({ kind: "Denied" }), [2, []]);
|
||||
test("a unit arm is written as the C# reference writes it, and its payload must be an array", async () => {
|
||||
// The bytes are tests/vectors/union-parity/unit-arm-*.msgpack, written by the reference, not spelled here.
|
||||
for (const [file, kind] of [["denied", "Denied"], ["floor", "Floor"], ["ceiling", "Ceiling"]] as const) {
|
||||
const reference = await read(`unit-arm-${file}.msgpack`);
|
||||
assert.deepEqual(outcome.decode(readWire(reference)), { kind }, file);
|
||||
assert.equal(hex(writeWire(outcome.encode({ kind }))), hex(reference), file);
|
||||
}
|
||||
assert.throws(() => outcome.decode([2, null]), /Union Outcome/u);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue