Skip to content

Commit

Permalink
vcf/io/writer/record/info/field/value/array: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Sep 12, 2024
1 parent 7fc29a8 commit 41f5d4e
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions noodles-vcf/src/io/writer/record/info/field/value/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,51 @@ where
}
}
}

#[cfg(test)]
mod tests {
use super::*;
use crate::variant::record_buf::info::field::value::Array as ArrayBuf;

#[test]
fn test_write_array() -> io::Result<()> {
fn t(buf: &mut Vec<u8>, array: &ArrayBuf, expected: &[u8]) -> io::Result<()> {
buf.clear();
write_array(buf, &array.into())?;
assert_eq!(buf, expected);
Ok(())
}

let mut buf = Vec::new();

let array = ArrayBuf::Integer(vec![Some(8)]);
t(&mut buf, &array, b"8")?;

let array = ArrayBuf::Integer(vec![Some(8), Some(13), None]);
t(&mut buf, &array, b"8,13,.")?;

let array = ArrayBuf::Float(vec![Some(0.333)]);
t(&mut buf, &array, b"0.333")?;

let array = ArrayBuf::Float(vec![Some(0.333), Some(0.667), None]);
t(&mut buf, &array, b"0.333,0.667,.")?;

let array = ArrayBuf::Character(vec![Some('n')]);
t(&mut buf, &array, b"n")?;

let array = ArrayBuf::Character(vec![Some('n'), Some(':'), None]);
t(&mut buf, &array, b"n,:,.")?; // FIXME

let array = ArrayBuf::String(vec![Some(String::from("noodles"))]);
t(&mut buf, &array, b"noodles")?;

let array = ArrayBuf::String(vec![
Some(String::from("noodles")),
Some(String::from(":")),
None,
]);
t(&mut buf, &array, b"noodles,:,.")?; // FIXME

Ok(())
}
}

0 comments on commit 41f5d4e

Please sign in to comment.