]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Read multiple row headers
[tablify] / src / lib.rs
index 820f43e172653f8f26e63b84abee7d8dadb6cb95..1d098b03d1d314ec7d6c4e94a72f2f7e6b5b94ce 100644 (file)
@@ -1,3 +1,58 @@
+#[cfg(test)]
+use std::io::BufRead;
+#[cfg(test)]
+use std::iter::Iterator;
+
+#[derive(Debug, PartialEq, Eq)]
+struct RowInput {
+    label: String,
+    entries: Vec<String>,
+}
+
+#[cfg(test)]
+fn read_rows(input: impl std::io::Read) -> impl Iterator<Item = RowInput> {
+    std::io::BufReader::new(input).lines().map(|line| RowInput {
+        label: line.unwrap(),
+        entries: vec![],
+    })
+}
+
 pub fn tablify(_input: &impl std::io::Read) -> String {
     String::from("Hello, world!")
 }
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn test_read_rows() {
+        assert_eq!(
+            read_rows(&b"foo"[..]).collect::<Vec<_>>(),
+            vec![RowInput {
+                label: String::from("foo"),
+                entries: vec![]
+            }]
+        );
+        assert_eq!(
+            read_rows(&b"bar"[..]).collect::<Vec<_>>(),
+            vec![RowInput {
+                label: String::from("bar"),
+                entries: vec![]
+            }]
+        );
+        assert_eq!(
+            read_rows(&b"foo\nbar\n"[..]).collect::<Vec<_>>(),
+            vec![
+                RowInput {
+                    label: String::from("foo"),
+                    entries: vec![]
+                },
+                RowInput {
+                    label: String::from("bar"),
+                    entries: vec![]
+                }
+            ]
+        );
+    }
+}