v0.2.14-pre.003

This commit is contained in:
2026-08-28 14:10:49 +02:00
parent c1f61a380f
commit 27d4cb1f36
11 changed files with 588 additions and 68 deletions

View File

@@ -0,0 +1,41 @@
// file: crates/ksp-program-api/unit_tests/program_instruction_decode.rs
// version: 1
#[test]
fn recognition_variants_are_distinct_and_payload_free() {
assert_ne!(crate::ProgramInstructionRecognition::NoMatch, crate::ProgramInstructionRecognition::ProgramMatch);
assert_ne!(crate::ProgramInstructionRecognition::ProgramMatch, crate::ProgramInstructionRecognition::ExactMatch);
assert_eq!(std::format!("{:?}", crate::ProgramInstructionRecognition::NoMatch), "NoMatch");
assert_eq!(std::format!("{:?}", crate::ProgramInstructionRecognition::ProgramMatch), "ProgramMatch");
assert_eq!(std::format!("{:?}", crate::ProgramInstructionRecognition::ExactMatch), "ExactMatch");
return;
}
#[test]
fn decode_outcome_preserves_decoded_value_and_unsupported_state() {
let decoded = crate::ProgramInstructionDecodeOutcome::Decoded(17_u64);
let decoded_value = match decoded {
crate::ProgramInstructionDecodeOutcome::Decoded(value) => value,
crate::ProgramInstructionDecodeOutcome::Unsupported => 0_u64,
};
assert_eq!(decoded_value, 17_u64);
let unsupported = crate::ProgramInstructionDecodeOutcome::<u64>::Unsupported;
assert!(matches!(unsupported, crate::ProgramInstructionDecodeOutcome::Unsupported));
return;
}
#[test]
fn decode_outcome_debug_never_requires_or_renders_decoded_debug() {
struct ExternalDecoded {
secret_marker: u8,
}
let decoded = crate::ProgramInstructionDecodeOutcome::Decoded(ExternalDecoded { secret_marker: 0xA7_u8 });
assert_eq!(std::format!("{decoded:?}"), "Decoded");
let secret_marker = match decoded {
crate::ProgramInstructionDecodeOutcome::Decoded(value) => value.secret_marker,
crate::ProgramInstructionDecodeOutcome::Unsupported => 0_u8,
};
assert_eq!(secret_marker, 0xA7_u8);
assert_eq!(std::format!("{:?}", crate::ProgramInstructionDecodeOutcome::<ExternalDecoded>::Unsupported), "Unsupported");
return;
}