From c1b6c7eeae85e746023c357a03701abfa4e58e8d Mon Sep 17 00:00:00 2001 From: Michael Macias Date: Tue, 28 Nov 2023 12:09:18 -0600 Subject: [PATCH] bam/record/codec/encoder/position: Add tests --- .../src/record/codec/encoder/position.rs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/noodles-bam/src/record/codec/encoder/position.rs b/noodles-bam/src/record/codec/encoder/position.rs index 6adaa85c5..c0595b3b3 100644 --- a/noodles-bam/src/record/codec/encoder/position.rs +++ b/noodles-bam/src/record/codec/encoder/position.rs @@ -20,3 +20,30 @@ where Ok(()) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_put_position() -> Result<(), Box> { + fn t(buf: &mut Vec, position: Option, expected: &[u8]) -> io::Result<()> { + buf.clear(); + put_position(buf, position)?; + assert_eq!(buf, expected); + Ok(()) + } + + let mut buf = Vec::new(); + + t(&mut buf, None, &[0xff, 0xff, 0xff, 0xff])?; + t(&mut buf, Some(Position::MIN), &[0x00, 0x00, 0x00, 0x00])?; + t( + &mut buf, + Position::try_from(8).map(Some)?, + &[0x07, 0x00, 0x00, 0x00], + )?; + + Ok(()) + } +}