Skip to content

Commit

Permalink
vcf/io/writer/record/samples/sample/value/tests: Pass value buffer to…
Browse files Browse the repository at this point in the history
… test function
  • Loading branch information
zaeleus committed Sep 12, 2024
1 parent 8343981 commit a8e9e52
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions noodles-vcf/src/io/writer/record/samples/sample/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,31 @@ where

#[cfg(test)]
mod tests {
use std::borrow::Cow;

use super::*;
use crate::variant::record_buf::samples::sample::Value as ValueBuf;

#[test]
fn test_write_value() -> io::Result<()> {
fn t(buf: &mut Vec<u8>, header: &Header, value: Value, expected: &[u8]) -> io::Result<()> {
fn t(
buf: &mut Vec<u8>,
header: &Header,
value: &ValueBuf,
expected: &[u8],
) -> io::Result<()> {
buf.clear();
write_value(buf, header, &value)?;
write_value(buf, header, &Value::from(value))?;
assert_eq!(buf, expected);
Ok(())
}

let header = Header::default();
let mut buf = Vec::new();

t(&mut buf, &header, Value::Integer(8), b"8")?;
t(&mut buf, &header, Value::Float(0.333), b"0.333")?;
t(&mut buf, &header, Value::Character('n'), b"n")?;
t(
&mut buf,
&header,
Value::String(Cow::from("noodles")),
b"noodles",
)?;

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

Ok(())
}
Expand Down

0 comments on commit a8e9e52

Please sign in to comment.