pkstrings: add minimal tests
Signed-off-by: Maxime “pep” Buquet <pep@bouah.net>
This commit is contained in:
parent
cb93e2fae0
commit
b5deb06f22
1 changed files with 33 additions and 0 deletions
|
@ -165,3 +165,36 @@ impl TryFrom<String> for PKString {
|
||||||
Ok(PKString(data))
|
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<u8> = vec![0x86, 0x80, 0x91, 0x98];
|
||||||
|
let result: Vec<u8> = PKString(String::from("GARY")).into();
|
||||||
|
assert_eq!(result, gary);
|
||||||
|
|
||||||
|
let nidoranf: Vec<u8> = vec![0x8d, 0x88, 0x83, 0x8e, 0x91, 0x80, 0x8d, 0xef];
|
||||||
|
let result: Vec<u8> = PKString(String::from("NIDORAN♂")).into();
|
||||||
|
assert_eq!(result, nidoranf);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue