use qubit_codec::engine::DecodeIncompleteAction;
use qubit_codec::engine::DecodeIncompleteActionOf;
use crate::common::IdentityCodec;
#[test]
fn test_decode_incomplete_action_debug_distinguishes_every_variant() {
assert_eq!(
"Reject",
format!("{:?}", DecodeIncompleteAction::<u8>::Reject),
"Reject renders without a payload"
);
assert_eq!(
"Skip",
format!("{:?}", DecodeIncompleteAction::<u8>::Skip),
"Skip renders without a payload"
);
assert_eq!(
"Emit { value: 7 }",
format!("{:?}", DecodeIncompleteAction::<u8>::Emit { value: 7 }),
"Emit renders its replacement value"
);
}
#[test]
fn test_decode_incomplete_action_emit_compares_payload_value() {
let emitted = DecodeIncompleteAction::<u8>::Emit { value: 7 };
assert_ne!(
emitted,
DecodeIncompleteAction::<u8>::Emit { value: 8 },
"the replacement value takes part in equality"
);
}
#[test]
fn test_decode_incomplete_action_copy_matches_fresh_construction() {
fn assert_copy<T: Copy>() {}
assert_copy::<DecodeIncompleteAction<u8>>();
let original = DecodeIncompleteAction::<u8>::Emit { value: 7 };
let copied = original;
assert_eq!(
original, copied,
"a copied action still carries the payload it was copied from"
);
}
#[test]
fn test_decode_incomplete_action_of_alias_resolves_codec_value_type() {
let action: DecodeIncompleteActionOf<IdentityCodec> = DecodeIncompleteAction::Emit { value: 7 };
assert_eq!(
format!("{action:?}"),
format!("{:?}", DecodeIncompleteAction::<u8>::Emit { value: 7 }),
"DecodeIncompleteActionOf<IdentityCodec> resolves to DecodeIncompleteAction<u8>"
);
}