Skip to content

Commit

Permalink
fix: better header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tshauck committed Jul 16, 2024
1 parent c505fbb commit 256854c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
6 changes: 3 additions & 3 deletions exon/exon-sdf/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ mod tests {
#[tokio::test]
async fn test_read_record() -> crate::Result<()> {
let molfile_content = r#"
Methane
Example
Methane
Example
2 1 0 0 0 0 999 V2000
0.0000 0.0000 0.0000 C 0 0 0 0 0 0
Expand All @@ -97,7 +97,7 @@ $$$$

let record = reader.read_record().await?.unwrap();

assert_eq!(record.header(), "Methane\nExample\n");
assert_eq!(record.header(), "Methane\nExample");
assert_eq!(record.data().len(), 3);
assert_eq!(record.atom_count(), 2);
assert_eq!(record.bond_count(), 1);
Expand Down
14 changes: 13 additions & 1 deletion exon/exon-sdf/src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,19 @@ pub(crate) fn parse_to_record(content: &str) -> crate::Result<Record> {
let mut lines = content.lines();

// Parse header (first 3 lines)
let header = lines.by_ref().take(3).collect::<Vec<_>>().join("\n");
let header = lines
.by_ref()
.take(3)
.filter_map(|l| {
let line = l.trim();
if line.is_empty() {
None
} else {
Some(line)
}
})
.collect::<Vec<_>>()
.join("\n");

// Parse counts line
let counts_line = lines.next().expect("Missing counts line");
Expand Down

0 comments on commit 256854c

Please sign in to comment.