From b5deb06f22f9d9ef6d082e6d748be1edb127384d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Mon, 6 Jul 2020 01:21:21 +0200 Subject: [PATCH] pkstrings: add minimal tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Maxime “pep” Buquet --- pkstrings/src/lib.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkstrings/src/lib.rs b/pkstrings/src/lib.rs index eb1baef..d79f4e9 100644 --- a/pkstrings/src/lib.rs +++ b/pkstrings/src/lib.rs @@ -165,3 +165,36 @@ impl TryFrom for PKString { Ok(PKString(data)) } } + +#[cfg(test)] +mod tests { + use std::convert::TryFrom; + use crate::PKString; + + #[test] + fn test_from_ord() { + let gary: &[u8] = &[0x86, 0x80, 0x91, 0x98]; + assert_eq!(PKString::try_from(gary), Ok(PKString(String::from("GARY")))); + + let party_nicks: &[u8] = &[ + 0x8a, 0x80, 0x83, 0x80, 0x81, 0x91, 0x80, 0x50, 0x50, 0x50, 0x50, 0x8d, 0x88, 0x83, + 0x8e, 0x8a, 0x88, 0x8d, 0x86, 0x50, 0x50, 0x50, 0x81, 0x8b, 0x80, 0x92, 0x93, 0x8e, + 0x88, 0x92, 0x84, 0x50, 0x50, 0x8e, 0x83, 0x83, 0x88, 0x92, 0x87, 0x50, 0x50, 0x50, + 0x50, 0x50, 0x8f, 0x88, 0x83, 0x86, 0x84, 0x98, 0x50, 0x50, 0x50, 0x50, 0x50, 0x82, + 0x87, 0x80, 0x91, 0x8c, 0x80, 0x8d, 0x83, 0x84, 0x91, 0x50, + ]; + let result = String::from("KADABRA@@@@NIDOKING@@@BLASTOISE@@ODDISH@@@@@PIDGEY@@@@@CHARMANDER@"); + assert_eq!(PKString::try_from(party_nicks), Ok(PKString(result))); + } + + #[test] + fn test_from_chr() { + let gary: Vec = vec![0x86, 0x80, 0x91, 0x98]; + let result: Vec = PKString(String::from("GARY")).into(); + assert_eq!(result, gary); + + let nidoranf: Vec = vec![0x8d, 0x88, 0x83, 0x8e, 0x91, 0x80, 0x8d, 0xef]; + let result: Vec = PKString(String::from("NIDORAN♂")).into(); + assert_eq!(result, nidoranf); + } +}