X-Git-Url: http://git.scottworley.com/tablify/blobdiff_plain/58b5f36de045c760efa51b21a6d841f5b62558db..cc2378d55111b3745a8f980f34b1f7b1126f37b1:/src/lib.rs
diff --git a/src/lib.rs b/src/lib.rs
index fcf5dc8..c2da4c9 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,10 +1,43 @@
-#[cfg(test)]
use std::collections::{HashMap, HashSet};
-#[cfg(test)]
use std::io::BufRead;
-#[cfg(test)]
use std::iter::Iterator;
+const HEADER: &str = "
+
+
+
+
+
+
+
+
+
+ ";
+const FOOTER: &str = "
+
+
+";
+
#[derive(Debug, PartialEq, Eq)]
struct RowInput {
label: String,
@@ -16,7 +49,6 @@ struct Reader>> {
row: Option,
}
impl>> Reader {
- #[cfg(test)]
fn new(input: Input) -> Self {
Self {
input: input.enumerate(),
@@ -63,12 +95,10 @@ impl>> Iterator for Reader
}
}
-#[cfg(test)]
fn read_rows(input: impl std::io::Read) -> impl Iterator- > {
Reader::new(std::io::BufReader::new(input).lines())
}
-#[cfg(test)]
fn column_counts(rows: &[RowInput]) -> Vec<(usize, String)> {
let mut counts: Vec<_> = rows
.iter()
@@ -86,8 +116,16 @@ fn column_counts(rows: &[RowInput]) -> Vec<(usize, String)> {
counts
}
-pub fn tablify(_input: &impl std::io::Read) -> String {
- String::from("Hello, world!")
+/// # Errors
+///
+/// Will return `Err` if
+/// * there's an i/o error while reading `input`
+/// * the log has invalid syntax:
+/// * an indented line with no preceding non-indented line
+pub fn tablify(input: impl std::io::Read) -> Result {
+ let rows = read_rows(input).collect::, _>>()?;
+ let _columns = column_counts(&rows);
+ Ok(String::from(HEADER) + "Hello, world!" + FOOTER)
}
#[cfg(test)]