Skip to content

Commit

Permalink
vcf/io/writer/record/samples/sample/value: Move array tests to module
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Sep 12, 2024
1 parent f302a7d commit 2309de3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 25 deletions.
25 changes: 0 additions & 25 deletions noodles-vcf/src/io/writer/record/samples/sample/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,31 +56,6 @@ mod tests {
let value_buf = ValueBuf::from(vec![Some(8)]);
t(&mut buf, &header, (&value_buf).into(), b"8")?;

let value_buf = ValueBuf::from(vec![Some(8), Some(13), None]);
t(&mut buf, &header, (&value_buf).into(), b"8,13,.")?;

let value_buf = ValueBuf::from(vec![Some(0.333)]);
t(&mut buf, &header, (&value_buf).into(), b"0.333")?;

let value_buf = ValueBuf::from(vec![Some(0.333), Some(0.667), None]);
t(&mut buf, &header, (&value_buf).into(), b"0.333,0.667,.")?;

let value_buf = ValueBuf::from(vec![Some('n')]);
t(&mut buf, &header, (&value_buf).into(), b"n")?;

let value_buf = ValueBuf::from(vec![Some('n'), Some('d'), None]);
t(&mut buf, &header, (&value_buf).into(), b"n,d,.")?;

let value_buf = ValueBuf::from(vec![Some(String::from("noodles"))]);
t(&mut buf, &header, (&value_buf).into(), b"noodles")?;

let value_buf = ValueBuf::from(vec![
Some(String::from("noodles")),
Some(String::from("vcf")),
None,
]);
t(&mut buf, &header, (&value_buf).into(), b"noodles,vcf,.")?;

Ok(())
}
}
48 changes: 48 additions & 0 deletions noodles-vcf/src/io/writer/record/samples/sample/value/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,51 @@ where

Ok(())
}

#[cfg(test)]
mod tests {
use super::*;
use crate::variant::record_buf::samples::sample::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('d'), None]);
t(&mut buf, &array, b"n,d,.")?;

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("vcf")),
None,
]);
t(&mut buf, &array, b"noodles,vcf,.")?;

Ok(())
}
}

0 comments on commit 2309de3

Please sign in to comment.