1 use std::borrow::ToOwned;
2 use std::collections::{HashMap, HashSet};
5 use std::iter::Iterator;
7 const TALLY_FONT: &str = "BabelStone Han";
9 fn tally_marks(n: usize, mark: Option<&str>) -> HTML {
12 let fives = { 0..n / 5 }.map(|_| '𝍸');
13 let ones = { 0..n % 5 }.map(|_| '𝍷');
14 let marks: String = fives.chain(ones).collect();
15 format!("<span style=\"font-family: '{TALLY_FONT}'\">{marks}</span>")
17 Some(m) => { 0..n }.map(|_| m).collect(),
21 #[derive(PartialEq, Eq, Debug)]
23 column_threshold: usize,
24 static_columns: Vec<Option<String>>,
25 hidden_columns: HashSet<String>,
26 substitute_labels: HashMap<String, String>,
27 mark: HashMap<String, String>,
30 fn apply_command(&mut self, line_num: usize, cmd: &str) -> Result<(), std::io::Error> {
31 if let Some(threshold) = cmd.strip_prefix("col_threshold ") {
32 self.column_threshold = threshold.parse().map_err(|e| {
34 std::io::ErrorKind::InvalidInput,
35 format!("line {line_num}: col_threshold must be numeric: {e}"),
38 } else if let Some(col) = cmd.strip_prefix("hide ") {
39 self.hidden_columns.insert(col.to_owned());
40 } else if let Some(col) = cmd.strip_prefix("col ") {
41 self.static_columns.push(Some(col.to_owned()));
42 } else if cmd == "colsep" {
43 self.static_columns.push(None);
44 } else if let Some(directive) = cmd.strip_prefix("label ") {
45 match directive.split_once(':') {
47 return Err(std::io::Error::new(
48 std::io::ErrorKind::InvalidInput,
49 format!("line {line_num}: Annotation missing ':'"),
52 Some((col, label)) => self
54 .insert(col.to_owned(), label.to_owned()),
56 } else if let Some(directive) = cmd.strip_prefix("mark ") {
57 match directive.split_once(':') {
59 return Err(std::io::Error::new(
60 std::io::ErrorKind::InvalidInput,
61 format!("line {line_num}: Mark missing ':'"),
64 Some((col, label)) => self.mark.insert(col.to_owned(), label.to_owned()),
67 return Err(std::io::Error::new(
68 std::io::ErrorKind::InvalidInput,
69 format!("line {line_num}: Unknown command: {cmd}"),
75 impl Default for Config {
76 fn default() -> Self {
79 static_columns: vec![],
80 hidden_columns: HashSet::new(),
81 substitute_labels: HashMap::new(),
87 const HEADER: &str = r#"<!DOCTYPE html>
90 <meta charset="utf-8">
91 <meta name="viewport" content="width=device-width, initial-scale=1">
93 td { text-align: center; }
94 /* h/t https://wabain.github.io/2019/10/13/css-rotated-table-header.html */
95 th, td { white-space: nowrap; }
96 th { text-align: left; font-weight: normal; }
97 th.spacer_row { height: .3em; }
98 .spacer_col { border: none; width: .2em; }
99 table { border-collapse: collapse }
100 tr.key > th { height: 10em; vertical-align: bottom; line-height: 1 }
101 tr.key > th > div { width: 1em; }
102 tr.key > th > div > div { width: 5em; transform-origin: bottom left; transform: translateX(1em) rotate(-65deg) }
103 td { border: thin solid gray; }
104 td.leftover { text-align: left; border: none; padding-left: .4em; }
105 td.yes { border: thin solid gray; background-color: #eee; }
106 /* h/t https://stackoverflow.com/questions/5687035/css-bolding-some-text-without-changing-its-containers-size/46452396#46452396 */
107 .highlight { text-shadow: -0.06ex 0 black, 0.06ex 0 black; }
110 function highlight(id) { const e = document.getElementById(id); if (e) { e.classList.add( "highlight"); } }
111 function clear_highlight(id) { const e = document.getElementById(id); if (e) { e.classList.remove("highlight"); } }
112 function h2(a, b) { highlight(a); highlight(b); }
113 function ch2(a, b) { clear_highlight(a); clear_highlight(b); }
120 const FOOTER: &str = " </tbody>
125 #[derive(PartialEq, Eq, Debug)]
126 pub struct HTML(String);
128 fn escape(value: &str) -> HTML {
129 let mut escaped: String = String::new();
130 for c in value.chars() {
132 '>' => escaped.push_str(">"),
133 '<' => escaped.push_str("<"),
134 '\'' => escaped.push_str("'"),
135 '"' => escaped.push_str("""),
136 '&' => escaped.push_str("&"),
137 ok_c => escaped.push(ok_c),
143 impl From<&str> for HTML {
144 fn from(value: &str) -> HTML {
145 HTML(String::from(value))
148 impl FromIterator<HTML> for HTML {
149 fn from_iter<T>(iter: T) -> HTML
151 T: IntoIterator<Item = HTML>,
153 HTML(iter.into_iter().map(|html| html.0).collect::<String>())
156 impl std::fmt::Display for HTML {
157 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
158 write!(f, "{}", self.0)
162 #[derive(Debug, PartialEq, Eq)]
166 Entry(&'a str, Option<&'a str>),
169 impl<'a> From<&'a str> for InputLine<'a> {
170 fn from(value: &'a str) -> InputLine<'a> {
171 let trimmed = value.trim_end();
172 if trimmed.is_empty() {
174 } else if let Some(cmd) = trimmed.strip_prefix('!') {
175 InputLine::Command(cmd)
176 } else if !trimmed.starts_with(' ') {
177 InputLine::RowHeader(value.trim())
179 match value.split_once(':') {
180 None => InputLine::Entry(value.trim(), None),
181 Some((col, instance)) => InputLine::Entry(col.trim(), Some(instance.trim())),
187 #[derive(Debug, PartialEq, Eq)]
190 entries: HashMap<String, Vec<Option<String>>>,
193 #[derive(Debug, PartialEq, Eq)]
199 struct Reader<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> {
200 input: std::iter::Enumerate<Input>,
202 config: &'cfg mut Config,
204 impl<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> Reader<'cfg, Input> {
205 fn new(config: &'cfg mut Config, input: Input) -> Self {
207 input: input.enumerate(),
213 impl<Input: Iterator<Item = Result<String, std::io::Error>>> Iterator for Reader<'_, Input> {
214 type Item = Result<Rowlike, std::io::Error>;
215 fn next(&mut self) -> Option<Self::Item> {
217 match self.input.next() {
218 None => return Ok(std::mem::take(&mut self.row).map(Rowlike::Row)).transpose(),
219 Some((_, Err(e))) => return Some(Err(e)),
220 Some((n, Ok(line))) => match InputLine::from(line.as_ref()) {
221 InputLine::Command(cmd) => {
222 if let Err(e) = self.config.apply_command(n + 1, cmd) {
226 InputLine::Blank if self.row.is_some() => {
227 return Ok(std::mem::take(&mut self.row).map(Rowlike::Row)).transpose()
229 InputLine::Blank => return Some(Ok(Rowlike::Spacer)),
230 InputLine::Entry(col, instance) => match self.row {
232 return Some(Err(std::io::Error::other(format!(
233 "line {}: Entry with no header",
237 Some(ref mut row) => {
239 .entry(col.to_owned())
240 .and_modify(|is| is.push(instance.map(ToOwned::to_owned)))
241 .or_insert_with(|| vec![instance.map(ToOwned::to_owned)]);
244 InputLine::RowHeader(row) => {
245 let prev = std::mem::take(&mut self.row);
246 self.row = Some(Row {
247 label: row.to_owned(),
248 entries: HashMap::new(),
251 return Ok(prev.map(Rowlike::Row)).transpose();
260 fn read_input(input: impl std::io::Read) -> Result<(Vec<Rowlike>, Config), std::io::Error> {
261 let mut config = Config::default();
262 let reader = Reader::new(&mut config, std::io::BufReader::new(input).lines());
264 .collect::<Result<Vec<_>, _>>()
265 .map(|rows| (rows, config))
268 fn column_counts(rows: &[Rowlike]) -> Vec<(usize, String)> {
269 let empty = HashMap::new();
270 let mut counts: Vec<_> = rows
272 .flat_map(|rl| match *rl {
273 Rowlike::Row(ref r) => r.entries.keys(),
274 Rowlike::Spacer => empty.keys(),
276 .fold(HashMap::new(), |mut cs, col| {
277 cs.entry(col.to_owned())
278 .and_modify(|n| *n += 1)
283 .map(|(col, n)| (n, col))
285 counts.sort_unstable_by(|a, b| b.0.cmp(&a.0).then(a.1.cmp(&b.1)));
288 fn column_order(config: &Config, rows: &[Rowlike]) -> Vec<String> {
289 let static_columns: HashSet<&str> = config
293 .map(std::string::String::as_str)
297 .filter_map(|(n, col)| {
298 (n >= config.column_threshold
299 && !static_columns.contains(col.as_str())
300 && !config.hidden_columns.contains(&col))
306 fn render_instances(instances: &[Option<String>], mark: Option<&str>) -> HTML {
308 let mut out = vec![];
309 for ins in instances {
312 Some(ref content) => {
314 out.push(tally_marks(tally, mark));
317 out.push(HTML::escape(content));
322 out.push(tally_marks(tally, mark));
332 fn render_cell(config: &Config, col: &str, row: &mut Row) -> HTML {
333 let row_label = HTML::escape(row.label.as_ref());
334 let col_label = HTML::escape(
338 .map_or(col, std::string::String::as_str),
340 let instances: Option<&Vec<Option<String>>> = row.entries.get(col);
341 let is_empty = match instances {
343 Some(is) => is.iter().all(|ins| match *ins {
345 Some(ref content) => content == "×",
348 let class = HTML::from(if is_empty { "" } else { r#" class="yes""# });
349 let contents = match instances {
350 None => HTML::from(""),
351 Some(is) => render_instances(is, config.mark.get(col).map(String::as_str)),
353 row.entries.remove(col);
355 r#"<td{class} onmouseover="h2('{row_label}','{col_label}')" onmouseout="ch2('{row_label}','{col_label}')">{contents}</td>"#
359 fn render_leftover(config: &Config, notcol: &str, instances: &[Option<String>]) -> HTML {
360 let label = HTML::escape(notcol);
361 if instances.len() == 1 && instances[0].is_none() {
362 HTML(format!("{label}"))
364 let rest = render_instances(instances, config.mark.get(notcol).map(String::as_str));
365 HTML(format!("{label}: {rest}"))
369 fn render_all_leftovers(config: &Config, row: &Row) -> HTML {
370 let mut order: Vec<_> = row
373 .filter(|&col| !config.hidden_columns.contains(col))
375 order.sort_unstable();
383 row.entries.get(notcol).expect("Key vanished?!"),
392 fn render_row(config: &Config, columns: &[String], rowlike: &mut Rowlike) -> HTML {
394 Rowlike::Spacer => HTML::from("<tr><th class=\"spacer_row\"></th></tr>\n"),
395 Rowlike::Row(ref mut row) => {
396 let row_label = HTML::escape(row.label.as_ref());
397 let static_cells = config
400 .map(|ocol| match *ocol {
401 Some(ref col) if config.hidden_columns.contains(col) => HTML::from(""),
402 Some(ref col) => render_cell(config, col, row),
403 None => HTML::from(r#"<td class="spacer_col"></td>"#),
406 let dynamic_cells = columns
408 .filter(|&col| !config.hidden_columns.contains(col))
409 .map(|col| render_cell(config, col, row))
411 let leftovers = render_all_leftovers(config, row);
413 "<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"
419 fn column_header_labels<'a>(
421 columns: &'a [String],
422 ) -> impl Iterator<Item = Option<&'a String>> {
423 let static_columns = config.static_columns.iter().map(|oc| oc.as_ref());
424 let dynamic_columns = columns.iter().map(Some);
426 .chain(dynamic_columns)
427 .filter(|ocol| ocol.is_none_or(|col| !config.hidden_columns.contains(col)))
429 ocol.map(|col| match config.substitute_labels.get(col) {
431 Some(substitute) => substitute,
436 fn render_column_headers(config: &Config, columns: &[String]) -> HTML {
438 String::from(r#"<tr class="key"><th></th>"#)
439 + &column_header_labels(config, columns).fold(String::new(), |mut acc, ocol| {
442 let col_header = HTML::escape(col);
445 r#"<th id="{col_header}"><div><div>{col_header}</div></div></th>"#
448 None => write!(&mut acc, r#"<th class="col_spacer"></th>"#),
459 /// Will return `Err` if
460 /// * there's an i/o error while reading `input`
461 /// * the log has invalid syntax:
462 /// * an indented line with no preceding non-indented line
463 pub fn tablify<R: std::io::Read>(input: R) -> Result<HTML, std::io::Error> {
464 let (rows, config) = read_input(input)?;
465 let columns = column_order(&config, &rows);
467 "{HEADER}{}{}{FOOTER}",
468 render_column_headers(&config, &columns),
470 .map(|mut r| render_row(&config, &columns, &mut r))
480 fn test_parse_line() {
481 assert_eq!(InputLine::from(""), InputLine::Blank);
482 assert_eq!(InputLine::from(" "), InputLine::Blank);
483 assert_eq!(InputLine::from("foo"), InputLine::RowHeader("foo"));
484 assert_eq!(InputLine::from("foo "), InputLine::RowHeader("foo"));
485 assert_eq!(InputLine::from(" foo"), InputLine::Entry("foo", None));
487 InputLine::from(" foo:bar"),
488 InputLine::Entry("foo", Some("bar"))
491 InputLine::from(" foo: bar"),
492 InputLine::Entry("foo", Some("bar"))
495 InputLine::from(" foo: bar "),
496 InputLine::Entry("foo", Some("bar"))
499 InputLine::from(" foo: bar "),
500 InputLine::Entry("foo", Some("bar"))
503 InputLine::from(" foo : bar "),
504 InputLine::Entry("foo", Some("bar"))
509 fn test_tally_marks() {
511 tally_marks(1, None),
513 "<span style=\"font-family: '{TALLY_FONT}'\">𝍷</span>"
517 tally_marks(2, None),
519 "<span style=\"font-family: '{TALLY_FONT}'\">𝍷𝍷</span>"
523 tally_marks(3, None),
525 "<span style=\"font-family: '{TALLY_FONT}'\">𝍷𝍷𝍷</span>"
529 tally_marks(4, None),
531 "<span style=\"font-family: '{TALLY_FONT}'\">𝍷𝍷𝍷𝍷</span>"
535 tally_marks(5, None),
537 "<span style=\"font-family: '{TALLY_FONT}'\">𝍸</span>"
541 tally_marks(6, None),
543 "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍷</span>"
547 tally_marks(7, None),
549 "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍷𝍷</span>"
553 tally_marks(8, None),
555 "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍷𝍷𝍷</span>"
559 tally_marks(9, None),
561 "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍷𝍷𝍷𝍷</span>"
565 tally_marks(10, None),
567 "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍸</span>"
571 tally_marks(11, None),
573 "<span style=\"font-family: '{TALLY_FONT}'\">𝍸𝍸𝍷</span>"
576 assert_eq!(tally_marks(1, Some("x")), "x".into());
577 assert_eq!(tally_marks(4, Some("x")), "xxxx".into());
578 assert_eq!(tally_marks(5, Some("x")), "xxxxx".into());
579 assert_eq!(tally_marks(6, Some("x")), "xxxxxx".into());
580 assert_eq!(tally_marks(2, Some("🍔")), "🍔🍔".into());
583 fn read_rows(input: impl std::io::Read) -> Result<Vec<Rowlike>, std::io::Error> {
584 read_input(input).map(|(rows, _)| rows)
586 fn read_config(input: impl std::io::Read) -> Result<Config, std::io::Error> {
587 read_input(input).map(|(_, config)| config)
590 fn test_read_rows() {
592 read_rows(&b"foo"[..]).unwrap(),
593 vec![Rowlike::Row(Row {
594 label: "foo".to_owned(),
595 entries: HashMap::new(),
599 read_rows(&b"bar"[..]).unwrap(),
600 vec![Rowlike::Row(Row {
601 label: "bar".to_owned(),
602 entries: HashMap::new(),
606 read_rows(&b"foo\nbar\n"[..]).unwrap(),
609 label: "foo".to_owned(),
610 entries: HashMap::new(),
613 label: "bar".to_owned(),
614 entries: HashMap::new(),
619 read_rows(&b"foo\n bar\n"[..]).unwrap(),
620 vec![Rowlike::Row(Row {
621 label: "foo".to_owned(),
622 entries: HashMap::from([("bar".to_owned(), vec![None])]),
626 read_rows(&b"foo\n bar\n baz\n"[..]).unwrap(),
627 vec![Rowlike::Row(Row {
628 label: "foo".to_owned(),
629 entries: HashMap::from([
630 ("bar".to_owned(), vec![None]),
631 ("baz".to_owned(), vec![None])
636 read_rows(&b"foo\n\nbar\n"[..]).unwrap(),
639 label: "foo".to_owned(),
640 entries: HashMap::new(),
643 label: "bar".to_owned(),
644 entries: HashMap::new(),
649 read_rows(&b"foo\n\n\nbar\n"[..]).unwrap(),
652 label: "foo".to_owned(),
653 entries: HashMap::new(),
657 label: "bar".to_owned(),
658 entries: HashMap::new(),
663 read_rows(&b"foo\n \nbar\n"[..]).unwrap(),
666 label: "foo".to_owned(),
667 entries: HashMap::new(),
670 label: "bar".to_owned(),
671 entries: HashMap::new(),
676 read_rows(&b"foo \n bar \n"[..]).unwrap(),
677 vec![Rowlike::Row(Row {
678 label: "foo".to_owned(),
679 entries: HashMap::from([("bar".to_owned(), vec![None])]),
683 let bad = read_rows(&b" foo"[..]);
684 assert!(bad.is_err());
685 assert!(format!("{bad:?}").contains("line 1: Entry with no header"));
687 let bad2 = read_rows(&b"foo\n\n bar"[..]);
688 assert!(bad2.is_err());
689 assert!(format!("{bad2:?}").contains("line 3: Entry with no header"));
693 fn test_read_config() {
695 read_config(&b"!col_threshold 10"[..])
701 read_config(&b"!col foo"[..]).unwrap().static_columns,
702 vec![Some("foo".to_owned())]
705 read_config(&b"!label foo:bar"[..])
707 .substitute_labels["foo"],
710 assert_eq!(read_config(&b"!mark foo:*"[..]).unwrap().mark["foo"], "*");
712 let bad_command = read_config(&b"!no such command"[..]);
713 assert!(bad_command.is_err());
714 assert!(format!("{bad_command:?}").contains("line 1: Unknown command"));
716 let bad_num = read_config(&b"!col_threshold foo"[..]);
717 assert!(bad_num.is_err());
718 assert!(format!("{bad_num:?}").contains("line 1: col_threshold must be numeric"));
720 let bad_sub = read_config(&b"!label foo"[..]);
721 assert!(bad_sub.is_err());
722 assert!(format!("{bad_sub:?}").contains("line 1: Annotation missing ':'"));
724 let bad_mark = read_config(&b"!mark foo"[..]);
725 assert!(bad_mark.is_err());
726 assert!(format!("{bad_mark:?}").contains("line 1: Mark missing ':'"));
730 fn test_column_counts() {
732 column_counts(&read_rows(&b"foo\n bar\n baz\n"[..]).unwrap()),
733 vec![(1, String::from("bar")), (1, String::from("baz"))]
736 column_counts(&read_rows(&b"foo\n bar\n baz\nquux\n baz"[..]).unwrap()),
737 vec![(2, String::from("baz")), (1, String::from("bar"))]
740 column_counts(&read_rows(&b"foo\n bar\n bar\n baz\n bar\nquux\n baz"[..]).unwrap()),
741 vec![(2, String::from("baz")), (1, String::from("bar"))]
745 &read_rows(&b"foo\n bar: 1\n bar: 2\n baz\n bar\nquux\n baz"[..]).unwrap()
747 vec![(2, String::from("baz")), (1, String::from("bar"))]
752 fn test_column_header_labels() {
753 let mut cfg = Config::default();
755 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([Some(&"foo".to_owned())]));
757 cfg.static_columns.push(Some("bar".to_owned()));
758 assert!(column_header_labels(&cfg, &["foo".to_owned()])
759 .eq([Some(&"bar".to_owned()), Some(&"foo".to_owned())]));
761 cfg.static_columns.push(None);
762 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([
763 Some(&"bar".to_owned()),
765 Some(&"foo".to_owned())
768 cfg.substitute_labels
769 .insert("foo".to_owned(), "foo (bits)".to_owned());
770 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([
771 Some(&"bar".to_owned()),
773 Some(&"foo (bits)".to_owned())
776 cfg.hidden_columns.insert("foo".to_owned());
777 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([Some(&"bar".to_owned()), None]));
779 cfg.hidden_columns.insert("bar".to_owned());
780 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([None]));
784 fn test_render_cell() {
790 label: "nope".to_owned(),
791 entries: HashMap::new(),
795 r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"></td>"#
803 label: "nope".to_owned(),
804 entries: HashMap::from([("bar".to_owned(), vec![None])]),
808 r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"></td>"#
816 label: "nope".to_owned(),
817 entries: HashMap::from([("foo".to_owned(), vec![None])]),
821 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"><span style="font-family: 'BabelStone Han'">𝍷</span></td>"#
829 label: "nope".to_owned(),
830 entries: HashMap::from([("foo".to_owned(), vec![None, None])]),
834 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"><span style="font-family: 'BabelStone Han'">𝍷𝍷</span></td>"#
842 label: "nope".to_owned(),
843 entries: HashMap::from([(
845 vec![Some("5".to_owned()), Some("10".to_owned())]
850 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 10</td>"#
858 label: "nope".to_owned(),
859 entries: HashMap::from([("foo".to_owned(), vec![Some("5".to_owned()), None])]),
863 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 <span style="font-family: 'BabelStone Han'">𝍷</span></td>"#
871 label: "nope".to_owned(),
872 entries: HashMap::from([("foo".to_owned(), vec![Some("×".to_owned())])]),
876 r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">×</td>"#
884 label: "nope".to_owned(),
885 entries: HashMap::from([("heart".to_owned(), vec![Some("<3".to_owned())])]),
889 r#"<td class="yes" onmouseover="h2('nope','heart')" onmouseout="ch2('nope','heart')"><3</td>"#
897 label: "bob's".to_owned(),
898 entries: HashMap::from([("foo".to_owned(), vec![None])]),
902 r#"<td class="yes" onmouseover="h2('bob's','foo')" onmouseout="ch2('bob's','foo')"><span style="font-family: 'BabelStone Han'">𝍷</span></td>"#
909 static_columns: vec![],
910 hidden_columns: HashSet::new(),
911 substitute_labels: HashMap::new(),
912 mark: HashMap::from([("foo".to_owned(), "🦄".to_owned())]),
916 label: "nope".to_owned(),
917 entries: HashMap::from([("foo".to_owned(), vec![None])]),
921 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">🦄</td>"#
926 label: "nope".to_owned(),
927 entries: HashMap::from([
928 ("foo".to_owned(), vec![None]),
929 ("baz".to_owned(), vec![None]),
932 assert_eq!(r.entries.len(), 2);
933 render_cell(&Config::default(), "foo", &mut r);
934 assert_eq!(r.entries.len(), 1);
935 render_cell(&Config::default(), "bar", &mut r);
936 assert_eq!(r.entries.len(), 1);
937 render_cell(&Config::default(), "baz", &mut r);
938 assert_eq!(r.entries.len(), 0);
942 fn test_render_leftovers() {
944 render_all_leftovers(
947 label: "nope".to_owned(),
948 entries: HashMap::from([("foo".to_owned(), vec![None])]),
954 render_all_leftovers(
957 label: "nope".to_owned(),
958 entries: HashMap::from([
959 ("foo".to_owned(), vec![None]),
960 ("bar".to_owned(), vec![None])
964 HTML::from("bar, foo")
967 render_all_leftovers(
970 label: "nope".to_owned(),
971 entries: HashMap::from([
972 ("foo".to_owned(), vec![None]),
973 ("bar".to_owned(), vec![None, None])
977 HTML::from(r#"bar: <span style="font-family: 'BabelStone Han'">𝍷𝍷</span>, foo"#)
980 render_all_leftovers(
983 static_columns: vec![],
984 hidden_columns: HashSet::from(["private".to_owned()]),
985 substitute_labels: HashMap::new(),
986 mark: HashMap::new(),
989 label: "nope".to_owned(),
990 entries: HashMap::from([("private".to_owned(), vec![None]),]),
996 render_all_leftovers(
999 static_columns: vec![],
1000 hidden_columns: HashSet::new(),
1001 substitute_labels: HashMap::new(),
1002 mark: HashMap::from([("foo".to_owned(), "🌈".to_owned())]),
1005 label: "nope".to_owned(),
1006 entries: HashMap::from([("foo".to_owned(), vec![None, None])]),
1009 HTML::from("foo: 🌈🌈")
1014 fn test_render_row() {
1018 &["foo".to_owned()],
1019 &mut Rowlike::Row(Row {
1020 label: "nope".to_owned(),
1021 entries: HashMap::from([("bar".to_owned(), vec![None])]),
1025 r#"<tr><th id="nope">nope</th><td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"></td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')">bar</td></tr>
1032 column_threshold: 0,
1033 static_columns: vec![Some("foo".to_owned()), Some("bar".to_owned())],
1034 hidden_columns: HashSet::new(),
1035 substitute_labels: HashMap::new(),
1036 mark: HashMap::new(),
1038 &["baz".to_owned()],
1039 &mut Rowlike::Row(Row {
1040 label: "nope".to_owned(),
1041 entries: HashMap::from([
1042 ("bar".to_owned(), vec![Some("r".to_owned())]),
1043 ("baz".to_owned(), vec![Some("z".to_owned())]),
1044 ("foo".to_owned(), vec![Some("f".to_owned())]),
1049 r#"<tr><th id="nope">nope</th><td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">f</td><td class="yes" onmouseover="h2('nope','bar')" onmouseout="ch2('nope','bar')">r</td><td class="yes" onmouseover="h2('nope','baz')" onmouseout="ch2('nope','baz')">z</td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
1056 column_threshold: 0,
1057 static_columns: vec![Some("foo".to_owned()), None, Some("bar".to_owned())],
1058 hidden_columns: HashSet::new(),
1059 substitute_labels: HashMap::new(),
1060 mark: HashMap::new(),
1063 &mut Rowlike::Row(Row {
1064 label: "nope".to_owned(),
1065 entries: HashMap::from([
1066 ("bar".to_owned(), vec![Some("r".to_owned())]),
1067 ("foo".to_owned(), vec![Some("f".to_owned())]),
1072 r#"<tr><th id="nope">nope</th><td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">f</td><td class="spacer_col"></td><td class="yes" onmouseover="h2('nope','bar')" onmouseout="ch2('nope','bar')">r</td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
1079 column_threshold: 0,
1080 static_columns: vec![],
1081 hidden_columns: HashSet::from(["foo".to_owned()]),
1082 substitute_labels: HashMap::new(),
1083 mark: HashMap::new(),
1086 &mut Rowlike::Row(Row {
1087 label: "nope".to_owned(),
1088 entries: HashMap::from([("foo".to_owned(), vec![Some("f".to_owned())]),]),
1092 r#"<tr><th id="nope">nope</th><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
1099 column_threshold: 0,
1100 static_columns: vec![Some("foo".to_owned())],
1101 hidden_columns: HashSet::from(["foo".to_owned()]),
1102 substitute_labels: HashMap::new(),
1103 mark: HashMap::new(),
1106 &mut Rowlike::Row(Row {
1107 label: "nope".to_owned(),
1108 entries: HashMap::from([("foo".to_owned(), vec![Some("f".to_owned())]),]),
1112 r#"<tr><th id="nope">nope</th><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
1119 column_threshold: 0,
1120 static_columns: vec![],
1121 hidden_columns: HashSet::new(),
1122 substitute_labels: HashMap::from([("foo".to_owned(), "bar".to_owned())]),
1123 mark: HashMap::new(),
1125 &["foo".to_owned()],
1126 &mut Rowlike::Row(Row {
1127 label: "nope".to_owned(),
1128 entries: HashMap::from([("foo".to_owned(), vec![None])]),
1132 r#"<tr><th id="nope">nope</th><td class="yes" onmouseover="h2('nope','bar')" onmouseout="ch2('nope','bar')"><span style="font-family: 'BabelStone Han'">𝍷</span></td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>