]> git.scottworley.com Git - tablify/commitdiff
Read multiple row headers
authorScott Worley <scottworley@scottworley.com>
Mon, 19 Aug 2024 07:17:14 +0000 (00:17 -0700)
committerScott Worley <scottworley@scottworley.com>
Mon, 19 Aug 2024 07:17:14 +0000 (00:17 -0700)
src/lib.rs

index 0584cd20406662282a66cb7466bd371ab1b0b5a7..1d098b03d1d314ec7d6c4e94a72f2f7e6b5b94ce 100644 (file)
@@ -11,15 +11,10 @@ struct RowInput {
 
 #[cfg(test)]
 fn read_rows(input: impl std::io::Read) -> impl Iterator<Item = RowInput> {
 
 #[cfg(test)]
 fn read_rows(input: impl std::io::Read) -> impl Iterator<Item = RowInput> {
-    vec![RowInput {
-        label: std::io::BufReader::new(input)
-            .lines()
-            .nth(0)
-            .unwrap()
-            .unwrap(),
+    std::io::BufReader::new(input).lines().map(|line| RowInput {
+        label: line.unwrap(),
         entries: vec![],
         entries: vec![],
-    }]
-    .into_iter()
+    })
 }
 
 pub fn tablify(_input: &impl std::io::Read) -> String {
 }
 
 pub fn tablify(_input: &impl std::io::Read) -> String {
@@ -46,5 +41,18 @@ mod tests {
                 entries: vec![]
             }]
         );
                 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![]
+                }
+            ]
+        );
     }
 }
     }
 }