Skip to content

Commit

Permalink
bam/record/codec/encoder/position: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Nov 28, 2023
1 parent e6bc6cb commit c1b6c7e
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions noodles-bam/src/record/codec/encoder/position.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,30 @@ where

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_put_position() -> Result<(), Box<dyn std::error::Error>> {
fn t(buf: &mut Vec<u8>, position: Option<Position>, 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(())
}
}

0 comments on commit c1b6c7e

Please sign in to comment.