X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/75bb888a36b5fdc005a0661c964779d6e0277298..2aa9ef947fa4104deef034305f1238275427a092:/src/lib.rs?ds=sidebyside diff --git a/src/lib.rs b/src/lib.rs index 0e2007d..1d098b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,4 +1,6 @@ #[cfg(test)] +use std::io::BufRead; +#[cfg(test)] use std::iter::Iterator; #[derive(Debug, PartialEq, Eq)] @@ -8,12 +10,11 @@ struct RowInput { } #[cfg(test)] -fn read_rows(_input: &impl std::io::Read) -> impl Iterator { - vec![RowInput { - label: String::from("foo"), +fn read_rows(input: impl std::io::Read) -> impl Iterator { + std::io::BufReader::new(input).lines().map(|line| RowInput { + label: line.unwrap(), entries: vec![], - }] - .into_iter() + }) } pub fn tablify(_input: &impl std::io::Read) -> String { @@ -27,11 +28,31 @@ mod tests { #[test] fn test_read_rows() { assert_eq!( - read_rows(&&b"foo"[..]).collect::>(), + read_rows(&b"foo"[..]).collect::>(), vec![RowInput { label: String::from("foo"), entries: vec![] }] ); + assert_eq!( + read_rows(&b"bar"[..]).collect::>(), + vec![RowInput { + label: String::from("bar"), + entries: vec![] + }] + ); + assert_eq!( + read_rows(&b"foo\nbar\n"[..]).collect::>(), + vec![ + RowInput { + label: String::from("foo"), + entries: vec![] + }, + RowInput { + label: String::from("bar"), + entries: vec![] + } + ] + ); } }