Skip to content

Commit

Permalink
vcf/io/writer/record/info/field/value: Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zaeleus committed Sep 11, 2024
1 parent 5006163 commit 03fe303
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions noodles-vcf/src/io/writer/record/info/field/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,39 @@ where
Value::Array(array) => write_array(writer, array),
}
}

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

use super::*;

#[test]
fn test_write_value() -> io::Result<()> {
use crate::variant::record_buf::info::field::Value as ValueBuf;

fn t(buf: &mut Vec<u8>, value: &Value<'_>, expected: &[u8]) -> io::Result<()> {
buf.clear();
write_value(buf, value)?;
assert_eq!(buf, expected);
Ok(())
}

let mut buf = Vec::new();

t(&mut buf, &Value::Integer(0), b"0")?;
t(&mut buf, &Value::Float(0.0), b"0")?;
t(&mut buf, &Value::Flag, b"")?;

t(&mut buf, &Value::Character('n'), b"n")?;
t(&mut buf, &Value::Character(';'), b";")?; // FIXME

t(&mut buf, &Value::String(Cow::from("ndls")), b"ndls")?;
t(&mut buf, &Value::String(Cow::from("n;d")), b"n%3Bd")?;

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

Ok(())
}
}

0 comments on commit 03fe303

Please sign in to comment.