From ddcfebe289368d3514bedbcd8f067c3be954c46a Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Sat, 29 Mar 2025 20:12:45 -0400 Subject: [PATCH] Add tests for read_string and write_string --- src/common/mod.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/common/mod.rs b/src/common/mod.rs index 0ac56e4..0d698be 100644 --- a/src/common/mod.rs +++ b/src/common/mod.rs @@ -197,6 +197,27 @@ pub fn get_racial_base_attributes(tribe_id: u8) -> Attributes { mod tests { use super::*; + // "FOO\0" + const STRING_DATA: [u8; 4] = [0x46u8, 0x4Fu8, 0x4Fu8, 0x0u8]; + + #[test] + fn read_string() { + // The nul terminator is supposed to be removed + assert_eq!( + crate::common::read_string(STRING_DATA.to_vec()), + "FOO".to_string() + ); + } + + #[test] + fn write_string() { + // Supposed to include the nul terminator + assert_eq!( + crate::common::write_string(&"FOO".to_string()), + STRING_DATA.to_vec() + ); + } + #[test] fn quantized_rotations() { assert_eq!(read_quantized_rotation(0), -std::f32::consts::PI);