Ok(())
}
}
+impl Default for Config {
+ fn default() -> Self {
+ Self {
+ column_threshold: 2,
+ static_columns: vec![],
+ }
+ }
+}
const HEADER: &str = r#"<!DOCTYPE html>
<html>
}
fn read_input(input: impl std::io::Read) -> Result<(Vec<Rowlike>, Config), std::io::Error> {
- let mut config = Config {
- column_threshold: 2,
- static_columns: vec![],
- };
+ let mut config = Config::default();
let reader = Reader::new(&mut config, std::io::BufReader::new(input).lines());
reader
.collect::<Result<Vec<_>, _>>()
}
}
-fn render_all_leftovers(row: &Row) -> HTML {
+fn render_all_leftovers(config: &Config, row: &Row) -> HTML {
let mut order: Vec<_> = row.entries.keys().collect();
order.sort_unstable();
HTML(
.iter()
.map(|col| render_cell(col, row))
.collect::<HTML>();
- let leftovers = render_all_leftovers(row);
+ let leftovers = render_all_leftovers(config, row);
HTML(format!(
"<tr><th id=\"{row_label}\">{row_label}</th>{static_cells}{dynamic_cells}<td class=\"leftover\" onmouseover=\"highlight('{row_label}')\" onmouseout=\"clear_highlight('{row_label}')\">{leftovers}</td></tr>\n"
))
#[test]
fn test_render_leftovers() {
assert_eq!(
- render_all_leftovers(&Row {
- label: "nope".to_owned(),
- entries: HashMap::from([("foo".to_owned(), vec![None])]),
- }),
+ render_all_leftovers(
+ &Config::default(),
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("foo".to_owned(), vec![None])]),
+ }
+ ),
HTML::from("foo")
);
assert_eq!(
- render_all_leftovers(&Row {
- label: "nope".to_owned(),
- entries: HashMap::from([
- ("foo".to_owned(), vec![None]),
- ("bar".to_owned(), vec![None])
- ]),
- }),
+ render_all_leftovers(
+ &Config::default(),
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([
+ ("foo".to_owned(), vec![None]),
+ ("bar".to_owned(), vec![None])
+ ]),
+ }
+ ),
HTML::from("bar, foo")
);
assert_eq!(
- render_all_leftovers(&Row {
- label: "nope".to_owned(),
- entries: HashMap::from([
- ("foo".to_owned(), vec![None]),
- ("bar".to_owned(), vec![None, None])
- ]),
- }),
+ render_all_leftovers(
+ &Config::default(),
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([
+ ("foo".to_owned(), vec![None]),
+ ("bar".to_owned(), vec![None, None])
+ ]),
+ }
+ ),
HTML::from("bar: 2, foo")
);
}
fn test_render_row() {
assert_eq!(
render_row(
- &Config {
- column_threshold: 0,
- static_columns: vec![],
- },
+ &Config::default(),
&["foo".to_owned()],
&mut Rowlike::Row(Row {
label: "nope".to_owned(),