]> git.scottworley.com Git - tablify/blobdiff - src/lib.rs
Double blank lines in the input generate spacer rows
[tablify] / src / lib.rs
index 73e517b14016e2a2681f422c4c173e4f20eb7fd5..744dc66d5dd9d478ddb73fb7e9b88af01ba32129 100644 (file)
@@ -138,7 +138,7 @@ impl<Input: Iterator<Item = Result<String, std::io::Error>>> Iterator for Reader
                     InputLine::Blank if self.row.is_some() => {
                         return Ok(std::mem::take(&mut self.row).map(Rowlike::Row)).transpose()
                     }
-                    InputLine::Blank => {}
+                    InputLine::Blank => return Some(Ok(Rowlike::Spacer)),
                     InputLine::Entry(col, instance) => match &mut self.row {
                         None => {
                             return Some(Err(std::io::Error::other(format!(
@@ -410,6 +410,22 @@ mod tests {
                 })
             ]
         );
+        assert_eq!(
+            read_rows(&b"foo\n\n\nbar\n"[..])
+                .flatten()
+                .collect::<Vec<_>>(),
+            vec![
+                Rowlike::Row(Row {
+                    label: "foo".to_owned(),
+                    entries: HashMap::new(),
+                }),
+                Rowlike::Spacer,
+                Rowlike::Row(Row {
+                    label: "bar".to_owned(),
+                    entries: HashMap::new(),
+                })
+            ]
+        );
         assert_eq!(
             read_rows(&b"foo\n \nbar\n"[..])
                 .flatten()