1 use std::borrow::ToOwned;
2 use std::collections::{HashMap, HashSet};
5 use std::iter::Iterator;
7 fn tally_marks(n: usize, mark: Option<&str>) -> String {
10 let fives = { 0..n / 5 }.map(|_| '𝍸');
11 let ones = { 0..n % 5 }.map(|_| '𝍷');
12 fives.chain(ones).collect()
14 Some(m) => { 0..n }.map(|_| m).collect(),
18 #[derive(PartialEq, Eq, Debug)]
20 column_threshold: usize,
21 static_columns: Vec<Option<String>>,
22 hidden_columns: HashSet<String>,
23 substitute_labels: HashMap<String, String>,
24 mark: HashMap<String, String>,
27 fn apply_command(&mut self, line_num: usize, cmd: &str) -> Result<(), std::io::Error> {
28 if let Some(threshold) = cmd.strip_prefix("col_threshold ") {
29 self.column_threshold = threshold.parse().map_err(|e| {
31 std::io::ErrorKind::InvalidInput,
32 format!("line {line_num}: col_threshold must be numeric: {e}"),
35 } else if let Some(col) = cmd.strip_prefix("hide ") {
36 self.hidden_columns.insert(col.to_owned());
37 } else if let Some(col) = cmd.strip_prefix("col ") {
38 self.static_columns.push(Some(col.to_owned()));
39 } else if cmd == "colsep" {
40 self.static_columns.push(None);
41 } else if let Some(directive) = cmd.strip_prefix("label ") {
42 match directive.split_once(':') {
44 return Err(std::io::Error::new(
45 std::io::ErrorKind::InvalidInput,
46 format!("line {line_num}: Annotation missing ':'"),
49 Some((col, label)) => self
51 .insert(col.to_owned(), label.to_owned()),
53 } else if let Some(directive) = cmd.strip_prefix("mark ") {
54 match directive.split_once(':') {
56 return Err(std::io::Error::new(
57 std::io::ErrorKind::InvalidInput,
58 format!("line {line_num}: Mark missing ':'"),
61 Some((col, label)) => self.mark.insert(col.to_owned(), label.to_owned()),
64 return Err(std::io::Error::new(
65 std::io::ErrorKind::InvalidInput,
66 format!("line {line_num}: Unknown command: {cmd}"),
72 impl Default for Config {
73 fn default() -> Self {
76 static_columns: vec![],
77 hidden_columns: HashSet::new(),
78 substitute_labels: HashMap::new(),
84 const HEADER: &str = r#"<!DOCTYPE html>
87 <meta charset="utf-8">
88 <meta name="viewport" content="width=device-width, initial-scale=1">
90 td { text-align: center; }
91 /* h/t https://wabain.github.io/2019/10/13/css-rotated-table-header.html */
92 th, td { white-space: nowrap; }
93 th { text-align: left; font-weight: normal; }
94 th.spacer_row { height: .3em; }
95 .spacer_col { border: none; width: .2em; }
96 table { border-collapse: collapse }
97 tr.key > th { height: 10em; vertical-align: bottom; line-height: 1 }
98 tr.key > th > div { width: 1em; }
99 tr.key > th > div > div { width: 5em; transform-origin: bottom left; transform: translateX(1em) rotate(-65deg) }
100 td { border: thin solid gray; }
101 td.leftover { text-align: left; border: none; padding-left: .4em; }
102 td.yes { border: thin solid gray; background-color: #eee; }
103 /* h/t https://stackoverflow.com/questions/5687035/css-bolding-some-text-without-changing-its-containers-size/46452396#46452396 */
104 .highlight { text-shadow: -0.06ex 0 black, 0.06ex 0 black; }
107 function highlight(id) { const e = document.getElementById(id); if (e) { e.classList.add( "highlight"); } }
108 function clear_highlight(id) { const e = document.getElementById(id); if (e) { e.classList.remove("highlight"); } }
109 function h2(a, b) { highlight(a); highlight(b); }
110 function ch2(a, b) { clear_highlight(a); clear_highlight(b); }
117 const FOOTER: &str = " </tbody>
122 #[derive(PartialEq, Eq, Debug)]
123 pub struct HTML(String);
125 fn escape(value: &str) -> HTML {
126 let mut escaped: String = String::new();
127 for c in value.chars() {
129 '>' => escaped.push_str(">"),
130 '<' => escaped.push_str("<"),
131 '\'' => escaped.push_str("'"),
132 '"' => escaped.push_str("""),
133 '&' => escaped.push_str("&"),
134 ok_c => escaped.push(ok_c),
140 impl From<&str> for HTML {
141 fn from(value: &str) -> HTML {
142 HTML(String::from(value))
145 impl FromIterator<HTML> for HTML {
146 fn from_iter<T>(iter: T) -> HTML
148 T: IntoIterator<Item = HTML>,
150 HTML(iter.into_iter().map(|html| html.0).collect::<String>())
153 impl std::fmt::Display for HTML {
154 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
155 write!(f, "{}", self.0)
159 #[derive(Debug, PartialEq, Eq)]
163 Entry(&'a str, Option<&'a str>),
166 impl<'a> From<&'a str> for InputLine<'a> {
167 fn from(value: &'a str) -> InputLine<'a> {
168 let trimmed = value.trim_end();
169 if trimmed.is_empty() {
171 } else if let Some(cmd) = trimmed.strip_prefix('!') {
172 InputLine::Command(cmd)
173 } else if !trimmed.starts_with(' ') {
174 InputLine::RowHeader(value.trim())
176 match value.split_once(':') {
177 None => InputLine::Entry(value.trim(), None),
178 Some((col, instance)) => InputLine::Entry(col.trim(), Some(instance.trim())),
184 #[derive(Debug, PartialEq, Eq)]
187 entries: HashMap<String, Vec<Option<String>>>,
190 #[derive(Debug, PartialEq, Eq)]
196 struct Reader<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> {
197 input: std::iter::Enumerate<Input>,
199 config: &'cfg mut Config,
201 impl<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> Reader<'cfg, Input> {
202 fn new(config: &'cfg mut Config, input: Input) -> Self {
204 input: input.enumerate(),
210 impl<Input: Iterator<Item = Result<String, std::io::Error>>> Iterator for Reader<'_, Input> {
211 type Item = Result<Rowlike, std::io::Error>;
212 fn next(&mut self) -> Option<Self::Item> {
214 match self.input.next() {
215 None => return Ok(std::mem::take(&mut self.row).map(Rowlike::Row)).transpose(),
216 Some((_, Err(e))) => return Some(Err(e)),
217 Some((n, Ok(line))) => match InputLine::from(line.as_ref()) {
218 InputLine::Command(cmd) => {
219 if let Err(e) = self.config.apply_command(n + 1, cmd) {
223 InputLine::Blank if self.row.is_some() => {
224 return Ok(std::mem::take(&mut self.row).map(Rowlike::Row)).transpose()
226 InputLine::Blank => return Some(Ok(Rowlike::Spacer)),
227 InputLine::Entry(col, instance) => match &mut self.row {
229 return Some(Err(std::io::Error::other(format!(
230 "line {}: Entry with no header",
234 Some(ref mut row) => {
236 .entry(col.to_owned())
237 .and_modify(|is| is.push(instance.map(ToOwned::to_owned)))
238 .or_insert_with(|| vec![instance.map(ToOwned::to_owned)]);
241 InputLine::RowHeader(row) => {
242 let prev = std::mem::take(&mut self.row);
243 self.row = Some(Row {
244 label: row.to_owned(),
245 entries: HashMap::new(),
248 return Ok(prev.map(Rowlike::Row)).transpose();
257 fn read_input(input: impl std::io::Read) -> Result<(Vec<Rowlike>, Config), std::io::Error> {
258 let mut config = Config::default();
259 let reader = Reader::new(&mut config, std::io::BufReader::new(input).lines());
261 .collect::<Result<Vec<_>, _>>()
262 .map(|rows| (rows, config))
265 fn column_counts(rows: &[Rowlike]) -> Vec<(usize, String)> {
266 let empty = HashMap::new();
267 let mut counts: Vec<_> = rows
269 .flat_map(|rl| match rl {
270 Rowlike::Row(r) => r.entries.keys(),
271 Rowlike::Spacer => empty.keys(),
273 .fold(HashMap::new(), |mut cs, col| {
274 cs.entry(col.to_owned())
275 .and_modify(|n| *n += 1)
280 .map(|(col, n)| (n, col))
282 counts.sort_unstable_by(|(an, acol), (bn, bcol)| bn.cmp(an).then(acol.cmp(bcol)));
285 fn column_order(config: &Config, rows: &[Rowlike]) -> Vec<String> {
286 let static_columns: HashSet<&str> = config
290 .map(std::string::String::as_str)
294 .filter_map(|(n, col)| {
295 (n >= config.column_threshold
296 && !static_columns.contains(col.as_str())
297 && !config.hidden_columns.contains(&col))
303 fn render_instances(instances: &[Option<String>], mark: Option<&str>) -> HTML {
305 let mut out = vec![];
306 for ins in instances {
311 out.push(HTML(tally_marks(tally, mark)));
314 out.push(HTML::escape(content));
319 out.push(HTML(tally_marks(tally, mark)));
323 .map(|html| html.0) // Waiting for slice_concat_trait to stabilize
329 fn render_cell(config: &Config, col: &str, row: &mut Row) -> HTML {
330 let row_label = HTML::escape(row.label.as_ref());
331 let col_label = HTML::escape(
335 .map_or(col, std::string::String::as_str),
337 let instances: Option<&Vec<Option<String>>> = row.entries.get(col);
338 let is_empty = match instances {
340 Some(is) => is.iter().all(|ins| match ins {
342 Some(content) => content == "×",
345 let class = HTML::from(if is_empty { "" } else { r#" class="yes""# });
346 let contents = match instances {
347 None => HTML::from(""),
348 Some(is) => render_instances(is, config.mark.get(col).map(String::as_str)),
350 row.entries.remove(col);
352 r#"<td{class} onmouseover="h2('{row_label}','{col_label}')" onmouseout="ch2('{row_label}','{col_label}')">{contents}</td>"#
356 fn render_leftover(config: &Config, notcol: &str, instances: &[Option<String>]) -> HTML {
357 let label = HTML::escape(notcol);
358 if instances.len() == 1 && instances[0].is_none() {
359 HTML(format!("{label}"))
361 let rest = render_instances(instances, config.mark.get(notcol).map(String::as_str));
362 HTML(format!("{label}: {rest}"))
366 fn render_all_leftovers(config: &Config, row: &Row) -> HTML {
367 let mut order: Vec<_> = row
370 .filter(|&col| !config.hidden_columns.contains(col))
372 order.sort_unstable();
380 row.entries.get(notcol).expect("Key vanished?!"),
383 .map(|html| html.0) // Waiting for slice_concat_trait to stabilize
389 fn render_row(config: &Config, columns: &[String], rowlike: &mut Rowlike) -> HTML {
391 Rowlike::Spacer => HTML::from("<tr><th class=\"spacer_row\"></th></tr>\n"),
392 Rowlike::Row(row) => {
393 let row_label = HTML::escape(row.label.as_ref());
394 let static_cells = config
397 .map(|ocol| match ocol {
398 Some(col) if config.hidden_columns.contains(col) => HTML::from(""),
399 Some(col) => render_cell(config, col, row),
400 None => HTML::from(r#"<td class="spacer_col"></td>"#),
403 let dynamic_cells = columns
405 .filter(|&col| !config.hidden_columns.contains(col))
406 .map(|col| render_cell(config, col, row))
408 let leftovers = render_all_leftovers(config, row);
410 "<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"
416 fn column_header_labels<'a>(
418 columns: &'a [String],
419 ) -> impl Iterator<Item = Option<&'a String>> {
420 let static_columns = config.static_columns.iter().map(|oc| oc.as_ref());
421 let dynamic_columns = columns.iter().map(Some);
423 .chain(dynamic_columns)
424 .filter(|ocol| ocol.map_or(true, |col| !config.hidden_columns.contains(col)))
426 ocol.map(|col| match config.substitute_labels.get(col) {
428 Some(substitute) => substitute,
433 fn render_column_headers(config: &Config, columns: &[String]) -> HTML {
435 String::from(r#"<tr class="key"><th></th>"#)
436 + &column_header_labels(config, columns).fold(String::new(), |mut acc, ocol| {
439 let col_header = HTML::escape(col);
442 r#"<th id="{col_header}"><div><div>{col_header}</div></div></th>"#
445 None => write!(&mut acc, r#"<th class="col_spacer"></th>"#),
456 /// Will return `Err` if
457 /// * there's an i/o error while reading `input`
458 /// * the log has invalid syntax:
459 /// * an indented line with no preceding non-indented line
460 pub fn tablify(input: impl std::io::Read) -> Result<HTML, std::io::Error> {
461 let (rows, config) = read_input(input)?;
462 let columns = column_order(&config, &rows);
464 "{HEADER}{}{}{FOOTER}",
465 render_column_headers(&config, &columns),
467 .map(|mut r| render_row(&config, &columns, &mut r))
477 fn test_parse_line() {
478 assert_eq!(InputLine::from(""), InputLine::Blank);
479 assert_eq!(InputLine::from(" "), InputLine::Blank);
480 assert_eq!(InputLine::from("foo"), InputLine::RowHeader("foo"));
481 assert_eq!(InputLine::from("foo "), InputLine::RowHeader("foo"));
482 assert_eq!(InputLine::from(" foo"), InputLine::Entry("foo", None));
484 InputLine::from(" foo:bar"),
485 InputLine::Entry("foo", Some("bar"))
488 InputLine::from(" foo: bar"),
489 InputLine::Entry("foo", Some("bar"))
492 InputLine::from(" foo: bar "),
493 InputLine::Entry("foo", Some("bar"))
496 InputLine::from(" foo: bar "),
497 InputLine::Entry("foo", Some("bar"))
500 InputLine::from(" foo : bar "),
501 InputLine::Entry("foo", Some("bar"))
506 fn test_tally_marks() {
507 assert_eq!(tally_marks(1, None), "𝍷");
508 assert_eq!(tally_marks(2, None), "𝍷𝍷");
509 assert_eq!(tally_marks(3, None), "𝍷𝍷𝍷");
510 assert_eq!(tally_marks(4, None), "𝍷𝍷𝍷𝍷");
511 assert_eq!(tally_marks(5, None), "𝍸");
512 assert_eq!(tally_marks(6, None), "𝍸𝍷");
513 assert_eq!(tally_marks(7, None), "𝍸𝍷𝍷");
514 assert_eq!(tally_marks(8, None), "𝍸𝍷𝍷𝍷");
515 assert_eq!(tally_marks(9, None), "𝍸𝍷𝍷𝍷𝍷");
516 assert_eq!(tally_marks(10, None), "𝍸𝍸");
517 assert_eq!(tally_marks(11, None), "𝍸𝍸𝍷");
518 assert_eq!(tally_marks(1, Some("x")), "x");
519 assert_eq!(tally_marks(4, Some("x")), "xxxx");
520 assert_eq!(tally_marks(5, Some("x")), "xxxxx");
521 assert_eq!(tally_marks(6, Some("x")), "xxxxxx");
522 assert_eq!(tally_marks(2, Some("🍔")), "🍔🍔");
525 fn read_rows(input: impl std::io::Read) -> Result<Vec<Rowlike>, std::io::Error> {
526 read_input(input).map(|(rows, _)| rows)
528 fn read_config(input: impl std::io::Read) -> Result<Config, std::io::Error> {
529 read_input(input).map(|(_, config)| config)
532 fn test_read_rows() {
534 read_rows(&b"foo"[..]).unwrap(),
535 vec![Rowlike::Row(Row {
536 label: "foo".to_owned(),
537 entries: HashMap::new(),
541 read_rows(&b"bar"[..]).unwrap(),
542 vec![Rowlike::Row(Row {
543 label: "bar".to_owned(),
544 entries: HashMap::new(),
548 read_rows(&b"foo\nbar\n"[..]).unwrap(),
551 label: "foo".to_owned(),
552 entries: HashMap::new(),
555 label: "bar".to_owned(),
556 entries: HashMap::new(),
561 read_rows(&b"foo\n bar\n"[..]).unwrap(),
562 vec![Rowlike::Row(Row {
563 label: "foo".to_owned(),
564 entries: HashMap::from([("bar".to_owned(), vec![None])]),
568 read_rows(&b"foo\n bar\n baz\n"[..]).unwrap(),
569 vec![Rowlike::Row(Row {
570 label: "foo".to_owned(),
571 entries: HashMap::from([
572 ("bar".to_owned(), vec![None]),
573 ("baz".to_owned(), vec![None])
578 read_rows(&b"foo\n\nbar\n"[..]).unwrap(),
581 label: "foo".to_owned(),
582 entries: HashMap::new(),
585 label: "bar".to_owned(),
586 entries: HashMap::new(),
591 read_rows(&b"foo\n\n\nbar\n"[..]).unwrap(),
594 label: "foo".to_owned(),
595 entries: HashMap::new(),
599 label: "bar".to_owned(),
600 entries: HashMap::new(),
605 read_rows(&b"foo\n \nbar\n"[..]).unwrap(),
608 label: "foo".to_owned(),
609 entries: HashMap::new(),
612 label: "bar".to_owned(),
613 entries: HashMap::new(),
618 read_rows(&b"foo \n bar \n"[..]).unwrap(),
619 vec![Rowlike::Row(Row {
620 label: "foo".to_owned(),
621 entries: HashMap::from([("bar".to_owned(), vec![None])]),
625 let bad = read_rows(&b" foo"[..]);
626 assert!(bad.is_err());
627 assert!(format!("{bad:?}").contains("line 1: Entry with no header"));
629 let bad2 = read_rows(&b"foo\n\n bar"[..]);
630 assert!(bad2.is_err());
631 assert!(format!("{bad2:?}").contains("line 3: Entry with no header"));
635 fn test_read_config() {
637 read_config(&b"!col_threshold 10"[..])
643 read_config(&b"!col foo"[..]).unwrap().static_columns,
644 vec![Some("foo".to_owned())]
647 read_config(&b"!label foo:bar"[..])
649 .substitute_labels["foo"],
652 assert_eq!(read_config(&b"!mark foo:*"[..]).unwrap().mark["foo"], "*");
654 let bad_command = read_config(&b"!no such command"[..]);
655 assert!(bad_command.is_err());
656 assert!(format!("{bad_command:?}").contains("line 1: Unknown command"));
658 let bad_num = read_config(&b"!col_threshold foo"[..]);
659 assert!(bad_num.is_err());
660 assert!(format!("{bad_num:?}").contains("line 1: col_threshold must be numeric"));
662 let bad_sub = read_config(&b"!label foo"[..]);
663 assert!(bad_sub.is_err());
664 assert!(format!("{bad_sub:?}").contains("line 1: Annotation missing ':'"));
666 let bad_mark = read_config(&b"!mark foo"[..]);
667 assert!(bad_mark.is_err());
668 assert!(format!("{bad_mark:?}").contains("line 1: Mark missing ':'"));
672 fn test_column_counts() {
674 column_counts(&read_rows(&b"foo\n bar\n baz\n"[..]).unwrap()),
675 vec![(1, String::from("bar")), (1, String::from("baz"))]
678 column_counts(&read_rows(&b"foo\n bar\n baz\nquux\n baz"[..]).unwrap()),
679 vec![(2, String::from("baz")), (1, String::from("bar"))]
682 column_counts(&read_rows(&b"foo\n bar\n bar\n baz\n bar\nquux\n baz"[..]).unwrap()),
683 vec![(2, String::from("baz")), (1, String::from("bar"))]
687 &read_rows(&b"foo\n bar: 1\n bar: 2\n baz\n bar\nquux\n baz"[..]).unwrap()
689 vec![(2, String::from("baz")), (1, String::from("bar"))]
694 fn test_column_header_labels() {
695 let mut cfg = Config::default();
697 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([Some(&"foo".to_owned())]));
699 cfg.static_columns.push(Some("bar".to_owned()));
700 assert!(column_header_labels(&cfg, &["foo".to_owned()])
701 .eq([Some(&"bar".to_owned()), Some(&"foo".to_owned())]));
703 cfg.static_columns.push(None);
704 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([
705 Some(&"bar".to_owned()),
707 Some(&"foo".to_owned())
710 cfg.substitute_labels
711 .insert("foo".to_owned(), "foo (bits)".to_owned());
712 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([
713 Some(&"bar".to_owned()),
715 Some(&"foo (bits)".to_owned())
718 cfg.hidden_columns.insert("foo".to_owned());
719 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([Some(&"bar".to_owned()), None]));
721 cfg.hidden_columns.insert("bar".to_owned());
722 assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([None]));
726 fn test_render_cell() {
732 label: "nope".to_owned(),
733 entries: HashMap::new(),
737 r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"></td>"#
745 label: "nope".to_owned(),
746 entries: HashMap::from([("bar".to_owned(), vec![None])]),
750 r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"></td>"#
758 label: "nope".to_owned(),
759 entries: HashMap::from([("foo".to_owned(), vec![None])]),
763 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">𝍷</td>"#
771 label: "nope".to_owned(),
772 entries: HashMap::from([("foo".to_owned(), vec![None, None])]),
776 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">𝍷𝍷</td>"#
784 label: "nope".to_owned(),
785 entries: HashMap::from([(
787 vec![Some("5".to_owned()), Some("10".to_owned())]
792 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 10</td>"#
800 label: "nope".to_owned(),
801 entries: HashMap::from([("foo".to_owned(), vec![Some("5".to_owned()), None])]),
805 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 𝍷</td>"#
813 label: "nope".to_owned(),
814 entries: HashMap::from([("foo".to_owned(), vec![Some("×".to_owned())])]),
818 r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">×</td>"#
826 label: "nope".to_owned(),
827 entries: HashMap::from([("heart".to_owned(), vec![Some("<3".to_owned())])]),
831 r#"<td class="yes" onmouseover="h2('nope','heart')" onmouseout="ch2('nope','heart')"><3</td>"#
839 label: "bob's".to_owned(),
840 entries: HashMap::from([("foo".to_owned(), vec![None])]),
844 r#"<td class="yes" onmouseover="h2('bob's','foo')" onmouseout="ch2('bob's','foo')">𝍷</td>"#
851 static_columns: vec![],
852 hidden_columns: HashSet::new(),
853 substitute_labels: HashMap::new(),
854 mark: HashMap::from([("foo".to_owned(), "🦄".to_owned())]),
858 label: "nope".to_owned(),
859 entries: HashMap::from([("foo".to_owned(), vec![None])]),
863 r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">🦄</td>"#
868 label: "nope".to_owned(),
869 entries: HashMap::from([
870 ("foo".to_owned(), vec![None]),
871 ("baz".to_owned(), vec![None]),
874 assert_eq!(r.entries.len(), 2);
875 render_cell(&Config::default(), "foo", &mut r);
876 assert_eq!(r.entries.len(), 1);
877 render_cell(&Config::default(), "bar", &mut r);
878 assert_eq!(r.entries.len(), 1);
879 render_cell(&Config::default(), "baz", &mut r);
880 assert_eq!(r.entries.len(), 0);
884 fn test_render_leftovers() {
886 render_all_leftovers(
889 label: "nope".to_owned(),
890 entries: HashMap::from([("foo".to_owned(), vec![None])]),
896 render_all_leftovers(
899 label: "nope".to_owned(),
900 entries: HashMap::from([
901 ("foo".to_owned(), vec![None]),
902 ("bar".to_owned(), vec![None])
906 HTML::from("bar, foo")
909 render_all_leftovers(
912 label: "nope".to_owned(),
913 entries: HashMap::from([
914 ("foo".to_owned(), vec![None]),
915 ("bar".to_owned(), vec![None, None])
919 HTML::from("bar: 𝍷𝍷, foo")
922 render_all_leftovers(
925 static_columns: vec![],
926 hidden_columns: HashSet::from(["private".to_owned()]),
927 substitute_labels: HashMap::new(),
928 mark: HashMap::new(),
931 label: "nope".to_owned(),
932 entries: HashMap::from([("private".to_owned(), vec![None]),]),
938 render_all_leftovers(
941 static_columns: vec![],
942 hidden_columns: HashSet::new(),
943 substitute_labels: HashMap::new(),
944 mark: HashMap::from([("foo".to_owned(), "🌈".to_owned())]),
947 label: "nope".to_owned(),
948 entries: HashMap::from([("foo".to_owned(), vec![None, None])]),
951 HTML::from("foo: 🌈🌈")
956 fn test_render_row() {
961 &mut Rowlike::Row(Row {
962 label: "nope".to_owned(),
963 entries: HashMap::from([("bar".to_owned(), vec![None])]),
967 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>
975 static_columns: vec![Some("foo".to_owned()), Some("bar".to_owned())],
976 hidden_columns: HashSet::new(),
977 substitute_labels: HashMap::new(),
978 mark: HashMap::new(),
981 &mut Rowlike::Row(Row {
982 label: "nope".to_owned(),
983 entries: HashMap::from([
984 ("bar".to_owned(), vec![Some("r".to_owned())]),
985 ("baz".to_owned(), vec![Some("z".to_owned())]),
986 ("foo".to_owned(), vec![Some("f".to_owned())]),
991 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>
999 static_columns: vec![Some("foo".to_owned()), None, Some("bar".to_owned())],
1000 hidden_columns: HashSet::new(),
1001 substitute_labels: HashMap::new(),
1002 mark: HashMap::new(),
1005 &mut Rowlike::Row(Row {
1006 label: "nope".to_owned(),
1007 entries: HashMap::from([
1008 ("bar".to_owned(), vec![Some("r".to_owned())]),
1009 ("foo".to_owned(), vec![Some("f".to_owned())]),
1014 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>
1021 column_threshold: 0,
1022 static_columns: vec![],
1023 hidden_columns: HashSet::from(["foo".to_owned()]),
1024 substitute_labels: HashMap::new(),
1025 mark: HashMap::new(),
1028 &mut Rowlike::Row(Row {
1029 label: "nope".to_owned(),
1030 entries: HashMap::from([("foo".to_owned(), vec![Some("f".to_owned())]),]),
1034 r#"<tr><th id="nope">nope</th><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
1041 column_threshold: 0,
1042 static_columns: vec![Some("foo".to_owned())],
1043 hidden_columns: HashSet::from(["foo".to_owned()]),
1044 substitute_labels: HashMap::new(),
1045 mark: HashMap::new(),
1048 &mut Rowlike::Row(Row {
1049 label: "nope".to_owned(),
1050 entries: HashMap::from([("foo".to_owned(), vec![Some("f".to_owned())]),]),
1054 r#"<tr><th id="nope">nope</th><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
1061 column_threshold: 0,
1062 static_columns: vec![],
1063 hidden_columns: HashSet::new(),
1064 substitute_labels: HashMap::from([("foo".to_owned(), "bar".to_owned())]),
1065 mark: HashMap::new(),
1067 &["foo".to_owned()],
1068 &mut Rowlike::Row(Row {
1069 label: "nope".to_owned(),
1070 entries: HashMap::from([("foo".to_owned(), vec![None])]),
1074 r#"<tr><th id="nope">nope</th><td class="yes" onmouseover="h2('nope','bar')" onmouseout="ch2('nope','bar')">𝍷</td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>