From d975874a64d8a6d8111dc54ea5522f4d39f2b64c Mon Sep 17 00:00:00 2001 From: jake Date: Sat, 18 Nov 2023 23:36:52 -0700 Subject: [PATCH] psopacket enum derive test --- src/lib.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index cf60c15..8ef71fb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -624,4 +624,33 @@ mod test { d: vec![9,9,9,8], }); } + + #[test] + fn test_derive_pso_packet_data_on_simple_enum() { + #[repr(u8)] + #[derive(PSOPacketData, Eq, PartialEq)] + enum Q { + A, + B, + C, + } + + let q = Q::A.as_bytes(); + assert!(q == vec![0]); + + let q = Q::B.as_bytes(); + assert!(q == vec![1]); + + let q = Q::C.as_bytes(); + assert!(q == vec![2]); + + let q = Q::from_bytes(&mut std::io::Cursor::new(vec![0])).unwrap(); + assert!(q == Q::A); + + let q = Q::from_bytes(&mut std::io::Cursor::new(vec![1])).unwrap(); + assert!(q == Q::B); + + let q = Q::from_bytes(&mut std::io::Cursor::new(vec![2])).unwrap(); + assert!(q == Q::C); + } }