Skip to content

Commit

Permalink
bcf/record/codec/decoder/chromosome_id: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Aug 13, 2024
1 parent fd9e6e4 commit 2cd3b7b
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions noodles-bcf/src/record/codec/decoder/chromosome_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,28 @@ pub(crate) fn read_chrom(src: &mut &[u8]) -> io::Result<usize> {
src.read_i32::<LittleEndian>()
.and_then(|n| usize::try_from(n).map_err(|e| io::Error::new(io::ErrorKind::InvalidData, e)))
}

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

#[test]
fn test_read_chrom() -> io::Result<()> {
let mut src = &[0x00, 0x00, 0x00, 0x00][..];
assert_eq!(read_chrom(&mut src)?, 0);

let mut src = &[][..];
assert!(matches!(
read_chrom(&mut src),
Err(e) if e.kind() == io::ErrorKind::UnexpectedEof
));

let mut src = &[0xff, 0xff, 0xff, 0xff][..];
assert!(matches!(
read_chrom(&mut src),
Err(e) if e.kind() == io::ErrorKind::InvalidData
));

Ok(())
}
}

0 comments on commit 2cd3b7b

Please sign in to comment.