From 834398111bb56bbc4302594e38beb91fa941291a Mon Sep 17 00:00:00 2001 From: Michael Macias Date: Thu, 12 Sep 2024 10:15:00 -0500 Subject: [PATCH] vcf/io/writer/record/info/field/value: Add character writer --- .../src/io/writer/record/info/field/value.rs | 5 ++-- .../record/info/field/value/character.rs | 28 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 noodles-vcf/src/io/writer/record/info/field/value/character.rs diff --git a/noodles-vcf/src/io/writer/record/info/field/value.rs b/noodles-vcf/src/io/writer/record/info/field/value.rs index 489c621e3..a9f4b9bf9 100644 --- a/noodles-vcf/src/io/writer/record/info/field/value.rs +++ b/noodles-vcf/src/io/writer/record/info/field/value.rs @@ -1,9 +1,10 @@ mod array; +mod character; mod string; use std::io::{self, Write}; -use self::{array::write_array, string::write_string}; +use self::{array::write_array, character::write_character, string::write_string}; use crate::variant::record::info::field::Value; pub(super) fn write_value(writer: &mut W, value: &Value) -> io::Result<()> @@ -14,7 +15,7 @@ where Value::Integer(n) => write!(writer, "{n}"), Value::Float(n) => write!(writer, "{n}"), Value::Flag => Ok(()), - Value::Character(c) => write!(writer, "{c}"), + Value::Character(c) => write_character(writer, *c), Value::String(s) => write_string(writer, s), Value::Array(array) => write_array(writer, array), } diff --git a/noodles-vcf/src/io/writer/record/info/field/value/character.rs b/noodles-vcf/src/io/writer/record/info/field/value/character.rs new file mode 100644 index 000000000..44837b97b --- /dev/null +++ b/noodles-vcf/src/io/writer/record/info/field/value/character.rs @@ -0,0 +1,28 @@ +use std::io::{self, Write}; + +pub(super) fn write_character(writer: &mut W, c: char) -> io::Result<()> +where + W: Write, +{ + write!(writer, "{c}") +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_write_character() -> io::Result<()> { + let mut buf = Vec::new(); + + buf.clear(); + write_character(&mut buf, 'n')?; + assert_eq!(buf, b"n"); + + buf.clear(); + write_character(&mut buf, ':')?; + assert_eq!(buf, b":"); // FIXME + + Ok(()) + } +}