Skip to content

Commit

Permalink
Add basic tests for start_line_number and position
Browse files Browse the repository at this point in the history
  • Loading branch information
olliecheng authored and audy committed Dec 4, 2024
1 parent 5d73e1f commit f48ad5e
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/parser/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,40 @@ pub fn write_fastq(
writer.write_all(&ending)?;
Ok(())
}

#[cfg(test)]
mod test {
use std::io::Cursor;

use crate::parse_fastx_reader;
fn seq(s: &[u8]) -> Cursor<&[u8]> { Cursor::new(s) }

#[test]
fn test_start_line_number() {
let mut reader = parse_fastx_reader(seq(
b"@test\nACGT\n+\nIIII\n@test2\nACGT\n+\nIIII"
)).unwrap();

let rec = reader.next().unwrap().unwrap();
assert_eq!(rec.start_line_number(), 1);

let rec = reader.next().unwrap().unwrap();
assert_eq!(rec.start_line_number(), 5);
}

#[test]
fn test_position() {
let mut reader = parse_fastx_reader(seq(
b"@test1\nACGT\n+\nIIII\n@test222\nACGT\n+\nIIII\n@test3\nACGT\n+\nIIII"
)).unwrap();

let rec = reader.next().unwrap().unwrap();
assert_eq!(rec.position().byte(), 0);

let rec = reader.next().unwrap().unwrap();
assert_eq!(rec.position().byte(), 19);

let rec = reader.next().unwrap().unwrap();
assert_eq!(rec.position().byte(), 40);
}
}

0 comments on commit f48ad5e

Please sign in to comment.