Skip to content

Commit

Permalink
csi/reader/index/aux: Add parse_names tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Nov 13, 2023
1 parent a3590de commit cfdacd6
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions noodles-csi/src/reader/index/aux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,39 @@ mod tests {

Ok(())
}

#[test]
fn test_parse_names() -> io::Result<()> {
let data = b"sq0\x00sq1\x00";
let actual = parse_names(&data[..])?;
let expected: ReferenceSequenceNames = [String::from("sq0"), String::from("sq1")]
.into_iter()
.collect();
assert_eq!(actual, expected);

let data = b"";
assert!(parse_names(&data[..])?.is_empty());

Ok(())
}

#[test]
fn test_parse_names_with_duplicate_name() {
let data = b"sq0\x00sq0\x00";

assert!(matches!(
parse_names(data),
Err(ref e) if e.kind() == io::ErrorKind::InvalidData,
));
}

#[test]
fn test_parse_names_with_trailing_data() {
let data = b"sq0\x00sq1\x00sq2";

assert!(matches!(
parse_names(data),
Err(ref e) if e.kind() == io::ErrorKind::InvalidData
));
}
}

0 comments on commit cfdacd6

Please sign in to comment.