]>
Commit | Line | Data |
---|---|---|
88a08162 | 1 | use std::borrow::ToOwned; |
a411a19d | 2 | use std::collections::{HashMap, HashSet}; |
7067975b | 3 | use std::fmt::Write; |
9dfa98b7 | 4 | use std::io::BufRead; |
75bb888a SW |
5 | use std::iter::Iterator; |
6 | ||
f8c2cab2 SW |
7 | fn tally_marks(n: usize) -> String { |
8 | let fives = { 0..n / 5 }.map(|_| '𝍸'); | |
9 | let ones = { 0..n % 5 }.map(|_| '𝍷'); | |
10 | fives.chain(ones).collect() | |
11 | } | |
12 | ||
e44de444 SW |
13 | #[derive(PartialEq, Eq, Debug)] |
14 | struct Config { | |
15 | column_threshold: usize, | |
a0577201 | 16 | static_columns: Vec<Option<String>>, |
3135b2cd | 17 | hidden_columns: HashSet<String>, |
d669f60d | 18 | substitute_labels: HashMap<String, String>, |
e44de444 SW |
19 | } |
20 | impl Config { | |
f105c5bc | 21 | fn apply_command(&mut self, line_num: usize, cmd: &str) -> Result<(), std::io::Error> { |
e44de444 | 22 | if let Some(threshold) = cmd.strip_prefix("col_threshold ") { |
f105c5bc SW |
23 | self.column_threshold = threshold.parse().map_err(|e| { |
24 | std::io::Error::new( | |
25 | std::io::ErrorKind::InvalidInput, | |
26 | format!("line {line_num}: col_threshold must be numeric: {e}"), | |
27 | ) | |
28 | })?; | |
3135b2cd SW |
29 | } else if let Some(col) = cmd.strip_prefix("hide ") { |
30 | self.hidden_columns.insert(col.to_owned()); | |
a411a19d | 31 | } else if let Some(col) = cmd.strip_prefix("col ") { |
a0577201 SW |
32 | self.static_columns.push(Some(col.to_owned())); |
33 | } else if cmd == "colsep" { | |
34 | self.static_columns.push(None); | |
d669f60d SW |
35 | } else if let Some(directive) = cmd.strip_prefix("label ") { |
36 | match directive.split_once(':') { | |
37 | None => { | |
38 | return Err(std::io::Error::new( | |
39 | std::io::ErrorKind::InvalidInput, | |
40 | format!("line {line_num}: Annotation missing ':'"), | |
41 | )) | |
42 | } | |
43 | Some((col, label)) => self | |
44 | .substitute_labels | |
45 | .insert(col.to_owned(), label.to_owned()), | |
46 | }; | |
b2f31832 SW |
47 | } else { |
48 | return Err(std::io::Error::new( | |
49 | std::io::ErrorKind::InvalidInput, | |
f105c5bc | 50 | format!("line {line_num}: Unknown command: {cmd}"), |
b2f31832 | 51 | )); |
e44de444 SW |
52 | } |
53 | Ok(()) | |
54 | } | |
31af9aac | 55 | } |
bc552978 SW |
56 | impl Default for Config { |
57 | fn default() -> Self { | |
58 | Self { | |
59 | column_threshold: 2, | |
60 | static_columns: vec![], | |
3135b2cd | 61 | hidden_columns: HashSet::new(), |
d669f60d | 62 | substitute_labels: HashMap::new(), |
bc552978 SW |
63 | } |
64 | } | |
65 | } | |
71e34cc0 | 66 | |
5ffe8e3a | 67 | const HEADER: &str = r#"<!DOCTYPE html> |
cc2378d5 SW |
68 | <html> |
69 | <head> | |
5ffe8e3a SW |
70 | <meta charset="utf-8"> |
71 | <meta name="viewport" content="width=device-width, initial-scale=1"> | |
cc2378d5 | 72 | <style> |
b8b365ce | 73 | td { text-align: center; } |
cc2378d5 SW |
74 | /* h/t https://wabain.github.io/2019/10/13/css-rotated-table-header.html */ |
75 | th, td { white-space: nowrap; } | |
76 | th { text-align: left; font-weight: normal; } | |
529cbaa2 | 77 | th.spacer_row { height: .3em; } |
a0577201 | 78 | .spacer_col { border: none; width: .2em; } |
cc2378d5 | 79 | table { border-collapse: collapse } |
3bc643e9 | 80 | tr.key > th { height: 10em; vertical-align: bottom; line-height: 1 } |
cc2378d5 SW |
81 | tr.key > th > div { width: 1em; } |
82 | tr.key > th > div > div { width: 5em; transform-origin: bottom left; transform: translateX(1em) rotate(-65deg) } | |
83 | td { border: thin solid gray; } | |
36bc3a39 | 84 | td.leftover { text-align: left; border: none; padding-left: .4em; } |
1dda21e6 | 85 | td.yes { border: thin solid gray; background-color: #ddd; } |
cc2378d5 SW |
86 | /* h/t https://stackoverflow.com/questions/5687035/css-bolding-some-text-without-changing-its-containers-size/46452396#46452396 */ |
87 | .highlight { text-shadow: -0.06ex 0 black, 0.06ex 0 black; } | |
cc2378d5 SW |
88 | </style> |
89 | <script> | |
5ffe8e3a SW |
90 | function highlight(id) { const e = document.getElementById(id); if (e) { e.classList.add( "highlight"); } } |
91 | function clear_highlight(id) { const e = document.getElementById(id); if (e) { e.classList.remove("highlight"); } } | |
cc2378d5 SW |
92 | function h2(a, b) { highlight(a); highlight(b); } |
93 | function ch2(a, b) { clear_highlight(a); clear_highlight(b); } | |
94 | </script> | |
95 | </head> | |
96 | <body> | |
97 | <table> | |
76638ea1 | 98 | <tbody> |
5ffe8e3a | 99 | "#; |
cc2378d5 SW |
100 | const FOOTER: &str = " </tbody> |
101 | </table> | |
102 | </body> | |
103 | </html>"; | |
104 | ||
70436f23 SW |
105 | #[derive(PartialEq, Eq, Debug)] |
106 | pub struct HTML(String); | |
107 | impl HTML { | |
108 | fn escape(value: &str) -> HTML { | |
109 | let mut escaped: String = String::new(); | |
110 | for c in value.chars() { | |
111 | match c { | |
112 | '>' => escaped.push_str(">"), | |
113 | '<' => escaped.push_str("<"), | |
114 | '\'' => escaped.push_str("'"), | |
115 | '"' => escaped.push_str("""), | |
116 | '&' => escaped.push_str("&"), | |
117 | ok_c => escaped.push(ok_c), | |
118 | } | |
119 | } | |
120 | HTML(escaped) | |
121 | } | |
122 | } | |
123 | impl From<&str> for HTML { | |
124 | fn from(value: &str) -> HTML { | |
125 | HTML(String::from(value)) | |
126 | } | |
127 | } | |
128 | impl FromIterator<HTML> for HTML { | |
129 | fn from_iter<T>(iter: T) -> HTML | |
130 | where | |
131 | T: IntoIterator<Item = HTML>, | |
132 | { | |
133 | HTML(iter.into_iter().map(|html| html.0).collect::<String>()) | |
134 | } | |
135 | } | |
136 | impl std::fmt::Display for HTML { | |
137 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | |
138 | write!(f, "{}", self.0) | |
139 | } | |
140 | } | |
141 | ||
88a08162 SW |
142 | #[derive(Debug, PartialEq, Eq)] |
143 | enum InputLine<'a> { | |
144 | Blank, | |
145 | RowHeader(&'a str), | |
146 | Entry(&'a str, Option<&'a str>), | |
e44de444 | 147 | Command(&'a str), |
e8657dff | 148 | } |
88a08162 SW |
149 | impl<'a> From<&'a str> for InputLine<'a> { |
150 | fn from(value: &'a str) -> InputLine<'a> { | |
151 | let trimmed = value.trim_end(); | |
152 | if trimmed.is_empty() { | |
153 | InputLine::Blank | |
e44de444 SW |
154 | } else if let Some(cmd) = trimmed.strip_prefix('!') { |
155 | InputLine::Command(cmd) | |
88a08162 SW |
156 | } else if !trimmed.starts_with(' ') { |
157 | InputLine::RowHeader(value.trim()) | |
158 | } else { | |
159 | match value.split_once(':') { | |
160 | None => InputLine::Entry(value.trim(), None), | |
161 | Some((col, instance)) => InputLine::Entry(col.trim(), Some(instance.trim())), | |
162 | } | |
e8657dff SW |
163 | } |
164 | } | |
165 | } | |
14e9852b | 166 | |
75bb888a | 167 | #[derive(Debug, PartialEq, Eq)] |
88a08162 SW |
168 | struct Row { |
169 | label: String, | |
170 | entries: HashMap<String, Vec<Option<String>>>, | |
75bb888a SW |
171 | } |
172 | ||
06a6a5ca SW |
173 | #[derive(Debug, PartialEq, Eq)] |
174 | enum Rowlike { | |
175 | Row(Row), | |
176 | Spacer, | |
177 | } | |
178 | ||
e44de444 | 179 | struct Reader<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> { |
8110b492 | 180 | input: std::iter::Enumerate<Input>, |
88a08162 | 181 | row: Option<Row>, |
e44de444 | 182 | config: &'cfg mut Config, |
201b9ef3 | 183 | } |
e44de444 SW |
184 | impl<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> Reader<'cfg, Input> { |
185 | fn new(config: &'cfg mut Config, input: Input) -> Self { | |
8110b492 SW |
186 | Self { |
187 | input: input.enumerate(), | |
188 | row: None, | |
e44de444 | 189 | config, |
8110b492 | 190 | } |
201b9ef3 SW |
191 | } |
192 | } | |
e44de444 SW |
193 | impl<'cfg, Input: Iterator<Item = Result<String, std::io::Error>>> Iterator |
194 | for Reader<'cfg, Input> | |
195 | { | |
06a6a5ca | 196 | type Item = Result<Rowlike, std::io::Error>; |
201b9ef3 SW |
197 | fn next(&mut self) -> Option<Self::Item> { |
198 | loop { | |
8bf0d5b1 | 199 | match self.input.next() { |
06a6a5ca | 200 | None => return Ok(std::mem::take(&mut self.row).map(Rowlike::Row)).transpose(), |
8110b492 | 201 | Some((_, Err(e))) => return Some(Err(e)), |
88a08162 | 202 | Some((n, Ok(line))) => match InputLine::from(line.as_ref()) { |
e44de444 | 203 | InputLine::Command(cmd) => { |
f105c5bc | 204 | if let Err(e) = self.config.apply_command(n + 1, cmd) { |
e44de444 SW |
205 | return Some(Err(e)); |
206 | } | |
207 | } | |
88a08162 | 208 | InputLine::Blank if self.row.is_some() => { |
06a6a5ca | 209 | return Ok(std::mem::take(&mut self.row).map(Rowlike::Row)).transpose() |
8110b492 | 210 | } |
14a039db | 211 | InputLine::Blank => return Some(Ok(Rowlike::Spacer)), |
88a08162 SW |
212 | InputLine::Entry(col, instance) => match &mut self.row { |
213 | None => { | |
214 | return Some(Err(std::io::Error::other(format!( | |
1df4654a | 215 | "line {}: Entry with no header", |
88a08162 SW |
216 | n + 1 |
217 | )))) | |
218 | } | |
219 | Some(ref mut row) => { | |
220 | row.entries | |
221 | .entry(col.to_owned()) | |
222 | .and_modify(|is| is.push(instance.map(ToOwned::to_owned))) | |
223 | .or_insert_with(|| vec![instance.map(ToOwned::to_owned)]); | |
224 | } | |
225 | }, | |
226 | InputLine::RowHeader(row) => { | |
227 | let prev = std::mem::take(&mut self.row); | |
228 | self.row = Some(Row { | |
229 | label: row.to_owned(), | |
230 | entries: HashMap::new(), | |
231 | }); | |
232 | if prev.is_some() { | |
06a6a5ca | 233 | return Ok(prev.map(Rowlike::Row)).transpose(); |
88a08162 | 234 | } |
201b9ef3 | 235 | } |
88a08162 | 236 | }, |
201b9ef3 SW |
237 | } |
238 | } | |
239 | } | |
240 | } | |
241 | ||
586b332a | 242 | fn read_input(input: impl std::io::Read) -> Result<(Vec<Rowlike>, Config), std::io::Error> { |
bc552978 | 243 | let mut config = Config::default(); |
e44de444 SW |
244 | let reader = Reader::new(&mut config, std::io::BufReader::new(input).lines()); |
245 | reader | |
586b332a | 246 | .collect::<Result<Vec<_>, _>>() |
e44de444 | 247 | .map(|rows| (rows, config)) |
75bb888a SW |
248 | } |
249 | ||
06a6a5ca SW |
250 | fn column_counts(rows: &[Rowlike]) -> Vec<(usize, String)> { |
251 | let empty = HashMap::new(); | |
58b5f36d SW |
252 | let mut counts: Vec<_> = rows |
253 | .iter() | |
06a6a5ca SW |
254 | .flat_map(|rl| match rl { |
255 | Rowlike::Row(r) => r.entries.keys(), | |
256 | Rowlike::Spacer => empty.keys(), | |
257 | }) | |
b8907770 | 258 | .fold(HashMap::new(), |mut cs, col| { |
88a08162 | 259 | cs.entry(col.to_owned()) |
58b5f36d | 260 | .and_modify(|n| *n += 1) |
f272e502 | 261 | .or_insert(1); |
58b5f36d | 262 | cs |
f272e502 | 263 | }) |
58b5f36d SW |
264 | .into_iter() |
265 | .map(|(col, n)| (n, col)) | |
266 | .collect(); | |
38d1167a | 267 | counts.sort_unstable_by(|(an, acol), (bn, bcol)| bn.cmp(an).then(acol.cmp(bcol))); |
58b5f36d | 268 | counts |
f272e502 | 269 | } |
06a6a5ca | 270 | fn column_order(config: &Config, rows: &[Rowlike]) -> Vec<String> { |
a411a19d SW |
271 | let static_columns: HashSet<&str> = config |
272 | .static_columns | |
273 | .iter() | |
a0577201 | 274 | .flatten() |
a411a19d SW |
275 | .map(std::string::String::as_str) |
276 | .collect(); | |
d22b2e05 SW |
277 | column_counts(rows) |
278 | .into_iter() | |
a411a19d | 279 | .filter_map(|(n, col)| { |
3135b2cd SW |
280 | (n >= config.column_threshold |
281 | && !static_columns.contains(col.as_str()) | |
282 | && !config.hidden_columns.contains(&col)) | |
283 | .then_some(col) | |
a411a19d | 284 | }) |
d22b2e05 SW |
285 | .collect() |
286 | } | |
f272e502 | 287 | |
f915bc90 | 288 | fn render_instances(instances: &[Option<String>]) -> HTML { |
f8c2cab2 SW |
289 | let mut tally = 0; |
290 | let mut out = vec![]; | |
291 | for ins in instances { | |
292 | match ins { | |
293 | None => tally += 1, | |
294 | Some(content) => { | |
295 | if tally > 0 { | |
296 | out.push(HTML(tally_marks(tally))); | |
297 | tally = 0; | |
298 | } | |
299 | out.push(HTML::escape(content)); | |
300 | } | |
301 | } | |
302 | } | |
303 | if tally > 0 { | |
304 | out.push(HTML(tally_marks(tally))); | |
f915bc90 | 305 | } |
f8c2cab2 SW |
306 | HTML( |
307 | out.into_iter() | |
308 | .map(|html| html.0) // Waiting for slice_concat_trait to stabilize | |
309 | .collect::<Vec<_>>() | |
310 | .join(" "), | |
311 | ) | |
f915bc90 SW |
312 | } |
313 | ||
ba61b04b | 314 | fn render_cell(config: &Config, col: &str, row: &mut Row) -> HTML { |
f915bc90 SW |
315 | let row_label = HTML::escape(row.label.as_ref()); |
316 | let col_label = HTML::escape(col); | |
317 | let instances: Option<&Vec<Option<String>>> = row.entries.get(col); | |
a1a4b3c8 SW |
318 | let is_empty = match instances { |
319 | None => true, | |
320 | Some(is) => is.iter().all(|ins| match ins { | |
321 | None => false, | |
322 | Some(content) => content == "×", | |
323 | }), | |
324 | }; | |
b59ad433 | 325 | let class = HTML::from(if is_empty { "" } else { r#" class="yes""# }); |
f915bc90 SW |
326 | let contents = match instances { |
327 | None => HTML::from(""), | |
328 | Some(is) => render_instances(is), | |
de408c29 | 329 | }; |
d9bfcf4d | 330 | row.entries.remove(col); |
5ffe8e3a | 331 | HTML(format!( |
b59ad433 | 332 | r#"<td{class} onmouseover="h2('{row_label}','{col_label}')" onmouseout="ch2('{row_label}','{col_label}')">{contents}</td>"# |
5ffe8e3a | 333 | )) |
de408c29 SW |
334 | } |
335 | ||
9a626020 SW |
336 | fn render_leftover(notcol: &str, instances: &[Option<String>]) -> HTML { |
337 | let label = HTML::escape(notcol); | |
f8c2cab2 | 338 | if instances.len() == 1 && instances[0].is_none() { |
9a626020 SW |
339 | HTML(format!("{label}")) |
340 | } else { | |
f8c2cab2 | 341 | let rest = render_instances(instances); |
9a626020 SW |
342 | HTML(format!("{label}: {rest}")) |
343 | } | |
344 | } | |
345 | ||
b4bc28ba | 346 | fn render_all_leftovers(config: &Config, row: &Row) -> HTML { |
3135b2cd SW |
347 | let mut order: Vec<_> = row |
348 | .entries | |
349 | .keys() | |
350 | .filter(|&col| !config.hidden_columns.contains(col)) | |
351 | .collect(); | |
9a626020 SW |
352 | order.sort_unstable(); |
353 | HTML( | |
354 | order | |
355 | .into_iter() | |
356 | .map(|notcol| render_leftover(notcol, row.entries.get(notcol).expect("Key vanished?!"))) | |
357 | .map(|html| html.0) // Waiting for slice_concat_trait to stabilize | |
358 | .collect::<Vec<_>>() | |
359 | .join(", "), | |
360 | ) | |
361 | } | |
362 | ||
215d38d5 | 363 | fn render_row(config: &Config, columns: &[String], rowlike: &mut Rowlike) -> HTML { |
06a6a5ca | 364 | match rowlike { |
529cbaa2 | 365 | Rowlike::Spacer => HTML::from("<tr><th class=\"spacer_row\"></th></tr>\n"), |
06a6a5ca SW |
366 | Rowlike::Row(row) => { |
367 | let row_label = HTML::escape(row.label.as_ref()); | |
a411a19d SW |
368 | let static_cells = config |
369 | .static_columns | |
370 | .iter() | |
a0577201 | 371 | .map(|ocol| match ocol { |
3135b2cd | 372 | Some(col) if config.hidden_columns.contains(col) => HTML::from(""), |
ba61b04b | 373 | Some(col) => render_cell(config, col, row), |
a0577201 SW |
374 | None => HTML::from(r#"<td class="spacer_col"></td>"#), |
375 | }) | |
a411a19d SW |
376 | .collect::<HTML>(); |
377 | let dynamic_cells = columns | |
06a6a5ca | 378 | .iter() |
3135b2cd | 379 | .filter(|&col| !config.hidden_columns.contains(col)) |
ba61b04b | 380 | .map(|col| render_cell(config, col, row)) |
06a6a5ca | 381 | .collect::<HTML>(); |
b4bc28ba | 382 | let leftovers = render_all_leftovers(config, row); |
06a6a5ca | 383 | HTML(format!( |
a411a19d | 384 | "<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" |
06a6a5ca SW |
385 | )) |
386 | } | |
387 | } | |
de408c29 SW |
388 | } |
389 | ||
e3feb9dc | 390 | fn column_header_labels<'a>( |
f93f5541 SW |
391 | config: &'a Config, |
392 | columns: &'a [String], | |
393 | ) -> impl Iterator<Item = Option<&'a String>> { | |
a0577201 SW |
394 | let static_columns = config.static_columns.iter().map(|oc| oc.as_ref()); |
395 | let dynamic_columns = columns.iter().map(Some); | |
d669f60d SW |
396 | static_columns |
397 | .chain(dynamic_columns) | |
398 | .filter(|ocol| ocol.map_or(true, |col| !config.hidden_columns.contains(col))) | |
399 | .map(|ocol| { | |
400 | ocol.map(|col| match config.substitute_labels.get(col) { | |
401 | None => col, | |
402 | Some(substitute) => substitute, | |
403 | }) | |
404 | }) | |
f93f5541 SW |
405 | } |
406 | ||
407 | fn render_column_headers(config: &Config, columns: &[String]) -> HTML { | |
70436f23 | 408 | HTML( |
5ffe8e3a | 409 | String::from(r#"<tr class="key"><th></th>"#) |
e3feb9dc | 410 | + &column_header_labels(config, columns).fold(String::new(), |mut acc, ocol| { |
f93f5541 SW |
411 | match ocol { |
412 | Some(col) => { | |
413 | let col_header = HTML::escape(col); | |
414 | write!( | |
415 | &mut acc, | |
416 | r#"<th id="{col_header}"><div><div>{col_header}</div></div></th>"# | |
417 | ) | |
a0577201 | 418 | } |
f93f5541 SW |
419 | None => write!(&mut acc, r#"<th class="col_spacer"></th>"#), |
420 | } | |
421 | .unwrap(); | |
422 | acc | |
423 | }) | |
70436f23 SW |
424 | + "</tr>\n", |
425 | ) | |
76638ea1 SW |
426 | } |
427 | ||
4b99fb70 SW |
428 | /// # Errors |
429 | /// | |
430 | /// Will return `Err` if | |
431 | /// * there's an i/o error while reading `input` | |
432 | /// * the log has invalid syntax: | |
433 | /// * an indented line with no preceding non-indented line | |
586b332a SW |
434 | pub fn tablify(input: impl std::io::Read) -> Result<HTML, std::io::Error> { |
435 | let (rows, config) = read_input(input)?; | |
436 | let columns = column_order(&config, &rows); | |
70436f23 SW |
437 | Ok(HTML(format!( |
438 | "{HEADER}{}{}{FOOTER}", | |
215d38d5 | 439 | render_column_headers(&config, &columns), |
70436f23 | 440 | rows.into_iter() |
215d38d5 | 441 | .map(|mut r| render_row(&config, &columns, &mut r)) |
70436f23 SW |
442 | .collect::<HTML>() |
443 | ))) | |
ece97615 | 444 | } |
75bb888a SW |
445 | |
446 | #[cfg(test)] | |
447 | mod tests { | |
448 | use super::*; | |
449 | ||
b8907770 | 450 | #[test] |
88a08162 SW |
451 | fn test_parse_line() { |
452 | assert_eq!(InputLine::from(""), InputLine::Blank); | |
453 | assert_eq!(InputLine::from(" "), InputLine::Blank); | |
454 | assert_eq!(InputLine::from("foo"), InputLine::RowHeader("foo")); | |
455 | assert_eq!(InputLine::from("foo "), InputLine::RowHeader("foo")); | |
456 | assert_eq!(InputLine::from(" foo"), InputLine::Entry("foo", None)); | |
b8907770 | 457 | assert_eq!( |
88a08162 SW |
458 | InputLine::from(" foo:bar"), |
459 | InputLine::Entry("foo", Some("bar")) | |
b8907770 SW |
460 | ); |
461 | assert_eq!( | |
88a08162 SW |
462 | InputLine::from(" foo: bar"), |
463 | InputLine::Entry("foo", Some("bar")) | |
b8907770 | 464 | ); |
0d999bc3 | 465 | assert_eq!( |
88a08162 SW |
466 | InputLine::from(" foo: bar "), |
467 | InputLine::Entry("foo", Some("bar")) | |
468 | ); | |
469 | assert_eq!( | |
470 | InputLine::from(" foo: bar "), | |
471 | InputLine::Entry("foo", Some("bar")) | |
472 | ); | |
473 | assert_eq!( | |
474 | InputLine::from(" foo : bar "), | |
475 | InputLine::Entry("foo", Some("bar")) | |
0d999bc3 | 476 | ); |
b8907770 SW |
477 | } |
478 | ||
f8c2cab2 SW |
479 | #[test] |
480 | fn test_tally_marks() { | |
481 | assert_eq!(tally_marks(1), "𝍷"); | |
482 | assert_eq!(tally_marks(2), "𝍷𝍷"); | |
483 | assert_eq!(tally_marks(3), "𝍷𝍷𝍷"); | |
484 | assert_eq!(tally_marks(4), "𝍷𝍷𝍷𝍷"); | |
485 | assert_eq!(tally_marks(5), "𝍸"); | |
486 | assert_eq!(tally_marks(6), "𝍸𝍷"); | |
487 | assert_eq!(tally_marks(7), "𝍸𝍷𝍷"); | |
488 | assert_eq!(tally_marks(8), "𝍸𝍷𝍷𝍷"); | |
489 | assert_eq!(tally_marks(9), "𝍸𝍷𝍷𝍷𝍷"); | |
490 | assert_eq!(tally_marks(10), "𝍸𝍸"); | |
491 | assert_eq!(tally_marks(11), "𝍸𝍸𝍷"); | |
492 | } | |
493 | ||
586b332a SW |
494 | fn read_rows(input: impl std::io::Read) -> Result<Vec<Rowlike>, std::io::Error> { |
495 | read_input(input).map(|(rows, _)| rows) | |
496 | } | |
e44de444 SW |
497 | fn read_config(input: impl std::io::Read) -> Result<Config, std::io::Error> { |
498 | read_input(input).map(|(_, config)| config) | |
499 | } | |
75bb888a SW |
500 | #[test] |
501 | fn test_read_rows() { | |
502 | assert_eq!( | |
12e91300 | 503 | read_rows(&b"foo"[..]).unwrap(), |
06a6a5ca | 504 | vec![Rowlike::Row(Row { |
88a08162 SW |
505 | label: "foo".to_owned(), |
506 | entries: HashMap::new(), | |
06a6a5ca | 507 | })] |
75bb888a | 508 | ); |
9dfa98b7 | 509 | assert_eq!( |
12e91300 | 510 | read_rows(&b"bar"[..]).unwrap(), |
06a6a5ca | 511 | vec![Rowlike::Row(Row { |
88a08162 SW |
512 | label: "bar".to_owned(), |
513 | entries: HashMap::new(), | |
06a6a5ca | 514 | })] |
9dfa98b7 | 515 | ); |
2aa9ef94 | 516 | assert_eq!( |
12e91300 | 517 | read_rows(&b"foo\nbar\n"[..]).unwrap(), |
2aa9ef94 | 518 | vec![ |
06a6a5ca | 519 | Rowlike::Row(Row { |
88a08162 SW |
520 | label: "foo".to_owned(), |
521 | entries: HashMap::new(), | |
06a6a5ca SW |
522 | }), |
523 | Rowlike::Row(Row { | |
88a08162 SW |
524 | label: "bar".to_owned(), |
525 | entries: HashMap::new(), | |
06a6a5ca | 526 | }) |
2aa9ef94 SW |
527 | ] |
528 | ); | |
201b9ef3 | 529 | assert_eq!( |
12e91300 | 530 | read_rows(&b"foo\n bar\n"[..]).unwrap(), |
06a6a5ca | 531 | vec![Rowlike::Row(Row { |
88a08162 SW |
532 | label: "foo".to_owned(), |
533 | entries: HashMap::from([("bar".to_owned(), vec![None])]), | |
06a6a5ca | 534 | })] |
201b9ef3 SW |
535 | ); |
536 | assert_eq!( | |
12e91300 | 537 | read_rows(&b"foo\n bar\n baz\n"[..]).unwrap(), |
06a6a5ca | 538 | vec![Rowlike::Row(Row { |
88a08162 SW |
539 | label: "foo".to_owned(), |
540 | entries: HashMap::from([ | |
541 | ("bar".to_owned(), vec![None]), | |
542 | ("baz".to_owned(), vec![None]) | |
543 | ]), | |
06a6a5ca | 544 | })] |
201b9ef3 SW |
545 | ); |
546 | assert_eq!( | |
12e91300 | 547 | read_rows(&b"foo\n\nbar\n"[..]).unwrap(), |
722ea297 SW |
548 | vec![ |
549 | Rowlike::Row(Row { | |
550 | label: "foo".to_owned(), | |
551 | entries: HashMap::new(), | |
552 | }), | |
553 | Rowlike::Row(Row { | |
554 | label: "bar".to_owned(), | |
555 | entries: HashMap::new(), | |
556 | }) | |
557 | ] | |
558 | ); | |
559 | assert_eq!( | |
12e91300 | 560 | read_rows(&b"foo\n\n\nbar\n"[..]).unwrap(), |
201b9ef3 | 561 | vec![ |
06a6a5ca | 562 | Rowlike::Row(Row { |
88a08162 SW |
563 | label: "foo".to_owned(), |
564 | entries: HashMap::new(), | |
06a6a5ca | 565 | }), |
14a039db | 566 | Rowlike::Spacer, |
06a6a5ca | 567 | Rowlike::Row(Row { |
88a08162 SW |
568 | label: "bar".to_owned(), |
569 | entries: HashMap::new(), | |
06a6a5ca | 570 | }) |
201b9ef3 SW |
571 | ] |
572 | ); | |
1f6bd845 | 573 | assert_eq!( |
12e91300 | 574 | read_rows(&b"foo\n \nbar\n"[..]).unwrap(), |
1f6bd845 | 575 | vec![ |
06a6a5ca | 576 | Rowlike::Row(Row { |
88a08162 SW |
577 | label: "foo".to_owned(), |
578 | entries: HashMap::new(), | |
06a6a5ca SW |
579 | }), |
580 | Rowlike::Row(Row { | |
88a08162 SW |
581 | label: "bar".to_owned(), |
582 | entries: HashMap::new(), | |
06a6a5ca | 583 | }) |
1f6bd845 SW |
584 | ] |
585 | ); | |
586 | assert_eq!( | |
12e91300 | 587 | read_rows(&b"foo \n bar \n"[..]).unwrap(), |
06a6a5ca | 588 | vec![Rowlike::Row(Row { |
88a08162 SW |
589 | label: "foo".to_owned(), |
590 | entries: HashMap::from([("bar".to_owned(), vec![None])]), | |
06a6a5ca | 591 | })] |
1f6bd845 | 592 | ); |
201b9ef3 | 593 | |
12e91300 | 594 | let bad = read_rows(&b" foo"[..]); |
201b9ef3 | 595 | assert!(bad.is_err()); |
1df4654a | 596 | assert!(format!("{bad:?}").contains("line 1: Entry with no header")); |
201b9ef3 | 597 | |
12e91300 | 598 | let bad2 = read_rows(&b"foo\n\n bar"[..]); |
201b9ef3 | 599 | assert!(bad2.is_err()); |
1df4654a | 600 | assert!(format!("{bad2:?}").contains("line 3: Entry with no header")); |
75bb888a | 601 | } |
f272e502 | 602 | |
e44de444 SW |
603 | #[test] |
604 | fn test_read_config() { | |
605 | assert_eq!( | |
fa8b5479 SW |
606 | read_config(&b"!col_threshold 10"[..]) |
607 | .unwrap() | |
608 | .column_threshold, | |
609 | 10 | |
e44de444 | 610 | ); |
a411a19d SW |
611 | assert_eq!( |
612 | read_config(&b"!col foo"[..]).unwrap().static_columns, | |
a0577201 | 613 | vec![Some("foo".to_owned())] |
a411a19d | 614 | ); |
d669f60d SW |
615 | assert_eq!( |
616 | read_config(&b"!label foo:bar"[..]) | |
617 | .unwrap() | |
618 | .substitute_labels["foo"], | |
619 | "bar" | |
620 | ); | |
e44de444 | 621 | |
b2f31832 SW |
622 | let bad_command = read_config(&b"!no such command"[..]); |
623 | assert!(bad_command.is_err()); | |
f105c5bc | 624 | assert!(format!("{bad_command:?}").contains("line 1: Unknown command")); |
b2f31832 | 625 | |
e44de444 SW |
626 | let bad_num = read_config(&b"!col_threshold foo"[..]); |
627 | assert!(bad_num.is_err()); | |
f105c5bc | 628 | assert!(format!("{bad_num:?}").contains("line 1: col_threshold must be numeric")); |
d669f60d SW |
629 | |
630 | let bad_sub = read_config(&b"!label foo"[..]); | |
631 | assert!(bad_sub.is_err()); | |
632 | assert!(format!("{bad_sub:?}").contains("line 1: Annotation missing ':'")); | |
e44de444 SW |
633 | } |
634 | ||
f272e502 SW |
635 | #[test] |
636 | fn test_column_counts() { | |
637 | assert_eq!( | |
12e91300 | 638 | column_counts(&read_rows(&b"foo\n bar\n baz\n"[..]).unwrap()), |
58b5f36d | 639 | vec![(1, String::from("bar")), (1, String::from("baz"))] |
f272e502 SW |
640 | ); |
641 | assert_eq!( | |
12e91300 | 642 | column_counts(&read_rows(&b"foo\n bar\n baz\nquux\n baz"[..]).unwrap()), |
38d1167a | 643 | vec![(2, String::from("baz")), (1, String::from("bar"))] |
f272e502 | 644 | ); |
397ef957 | 645 | assert_eq!( |
12e91300 | 646 | column_counts(&read_rows(&b"foo\n bar\n bar\n baz\n bar\nquux\n baz"[..]).unwrap()), |
38d1167a | 647 | vec![(2, String::from("baz")), (1, String::from("bar"))] |
397ef957 | 648 | ); |
b8907770 SW |
649 | assert_eq!( |
650 | column_counts( | |
12e91300 | 651 | &read_rows(&b"foo\n bar: 1\n bar: 2\n baz\n bar\nquux\n baz"[..]).unwrap() |
b8907770 | 652 | ), |
38d1167a | 653 | vec![(2, String::from("baz")), (1, String::from("bar"))] |
b8907770 | 654 | ); |
f272e502 | 655 | } |
de408c29 | 656 | |
a638dfe7 | 657 | #[test] |
e3feb9dc | 658 | fn test_column_header_labels() { |
a638dfe7 SW |
659 | let mut cfg = Config::default(); |
660 | ||
e3feb9dc | 661 | assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([Some(&"foo".to_owned())])); |
a638dfe7 SW |
662 | |
663 | cfg.static_columns.push(Some("bar".to_owned())); | |
e3feb9dc | 664 | assert!(column_header_labels(&cfg, &["foo".to_owned()]) |
a638dfe7 SW |
665 | .eq([Some(&"bar".to_owned()), Some(&"foo".to_owned())])); |
666 | ||
667 | cfg.static_columns.push(None); | |
e3feb9dc | 668 | assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([ |
a638dfe7 SW |
669 | Some(&"bar".to_owned()), |
670 | None, | |
671 | Some(&"foo".to_owned()) | |
672 | ])); | |
673 | ||
d669f60d SW |
674 | cfg.substitute_labels |
675 | .insert("foo".to_owned(), "foo (bits)".to_owned()); | |
676 | assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([ | |
677 | Some(&"bar".to_owned()), | |
678 | None, | |
679 | Some(&"foo (bits)".to_owned()) | |
680 | ])); | |
681 | ||
a638dfe7 | 682 | cfg.hidden_columns.insert("foo".to_owned()); |
e3feb9dc | 683 | assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([Some(&"bar".to_owned()), None])); |
a638dfe7 SW |
684 | |
685 | cfg.hidden_columns.insert("bar".to_owned()); | |
e3feb9dc | 686 | assert!(column_header_labels(&cfg, &["foo".to_owned()]).eq([None])); |
a638dfe7 SW |
687 | } |
688 | ||
de408c29 SW |
689 | #[test] |
690 | fn test_render_cell() { | |
691 | assert_eq!( | |
692 | render_cell( | |
ba61b04b | 693 | &Config::default(), |
de408c29 | 694 | "foo", |
d9bfcf4d | 695 | &mut Row { |
88a08162 SW |
696 | label: "nope".to_owned(), |
697 | entries: HashMap::new(), | |
de408c29 SW |
698 | } |
699 | ), | |
5ffe8e3a | 700 | HTML::from( |
b59ad433 | 701 | r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"></td>"# |
5ffe8e3a | 702 | ) |
de408c29 SW |
703 | ); |
704 | assert_eq!( | |
705 | render_cell( | |
ba61b04b | 706 | &Config::default(), |
de408c29 | 707 | "foo", |
d9bfcf4d | 708 | &mut Row { |
88a08162 SW |
709 | label: "nope".to_owned(), |
710 | entries: HashMap::from([("bar".to_owned(), vec![None])]), | |
de408c29 SW |
711 | } |
712 | ), | |
5ffe8e3a | 713 | HTML::from( |
b59ad433 | 714 | r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"></td>"# |
5ffe8e3a | 715 | ) |
de408c29 SW |
716 | ); |
717 | assert_eq!( | |
718 | render_cell( | |
ba61b04b | 719 | &Config::default(), |
de408c29 | 720 | "foo", |
d9bfcf4d | 721 | &mut Row { |
88a08162 SW |
722 | label: "nope".to_owned(), |
723 | entries: HashMap::from([("foo".to_owned(), vec![None])]), | |
de408c29 SW |
724 | } |
725 | ), | |
5ffe8e3a | 726 | HTML::from( |
f8c2cab2 | 727 | r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">𝍷</td>"# |
5ffe8e3a | 728 | ) |
de408c29 SW |
729 | ); |
730 | assert_eq!( | |
731 | render_cell( | |
ba61b04b | 732 | &Config::default(), |
de408c29 | 733 | "foo", |
d9bfcf4d | 734 | &mut Row { |
88a08162 SW |
735 | label: "nope".to_owned(), |
736 | entries: HashMap::from([("foo".to_owned(), vec![None, None])]), | |
de408c29 SW |
737 | } |
738 | ), | |
5ffe8e3a | 739 | HTML::from( |
f8c2cab2 | 740 | r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">𝍷𝍷</td>"# |
5ffe8e3a | 741 | ) |
de408c29 SW |
742 | ); |
743 | assert_eq!( | |
744 | render_cell( | |
ba61b04b | 745 | &Config::default(), |
de408c29 | 746 | "foo", |
d9bfcf4d | 747 | &mut Row { |
88a08162 | 748 | label: "nope".to_owned(), |
5ffe8e3a SW |
749 | entries: HashMap::from([( |
750 | "foo".to_owned(), | |
751 | vec![Some("5".to_owned()), Some("10".to_owned())] | |
752 | )]), | |
de408c29 SW |
753 | } |
754 | ), | |
5ffe8e3a SW |
755 | HTML::from( |
756 | r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 10</td>"# | |
757 | ) | |
de408c29 SW |
758 | ); |
759 | assert_eq!( | |
760 | render_cell( | |
ba61b04b | 761 | &Config::default(), |
de408c29 | 762 | "foo", |
d9bfcf4d | 763 | &mut Row { |
88a08162 SW |
764 | label: "nope".to_owned(), |
765 | entries: HashMap::from([("foo".to_owned(), vec![Some("5".to_owned()), None])]), | |
de408c29 SW |
766 | } |
767 | ), | |
5ffe8e3a | 768 | HTML::from( |
f8c2cab2 | 769 | r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 𝍷</td>"# |
5ffe8e3a | 770 | ) |
70436f23 | 771 | ); |
a1a4b3c8 SW |
772 | assert_eq!( |
773 | render_cell( | |
ba61b04b | 774 | &Config::default(), |
a1a4b3c8 SW |
775 | "foo", |
776 | &mut Row { | |
777 | label: "nope".to_owned(), | |
778 | entries: HashMap::from([("foo".to_owned(), vec![Some("×".to_owned())])]), | |
779 | } | |
780 | ), | |
781 | HTML::from( | |
b59ad433 | 782 | r#"<td onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">×</td>"# |
a1a4b3c8 SW |
783 | ) |
784 | ); | |
70436f23 SW |
785 | assert_eq!( |
786 | render_cell( | |
ba61b04b | 787 | &Config::default(), |
70436f23 | 788 | "heart", |
d9bfcf4d | 789 | &mut Row { |
88a08162 SW |
790 | label: "nope".to_owned(), |
791 | entries: HashMap::from([("heart".to_owned(), vec![Some("<3".to_owned())])]), | |
70436f23 SW |
792 | } |
793 | ), | |
5ffe8e3a SW |
794 | HTML::from( |
795 | r#"<td class="yes" onmouseover="h2('nope','heart')" onmouseout="ch2('nope','heart')"><3</td>"# | |
796 | ) | |
70436f23 SW |
797 | ); |
798 | assert_eq!( | |
799 | render_cell( | |
ba61b04b | 800 | &Config::default(), |
70436f23 | 801 | "foo", |
d9bfcf4d | 802 | &mut Row { |
88a08162 SW |
803 | label: "bob's".to_owned(), |
804 | entries: HashMap::from([("foo".to_owned(), vec![None])]), | |
70436f23 SW |
805 | } |
806 | ), | |
5ffe8e3a | 807 | HTML::from( |
f8c2cab2 | 808 | r#"<td class="yes" onmouseover="h2('bob's','foo')" onmouseout="ch2('bob's','foo')">𝍷</td>"# |
5ffe8e3a | 809 | ) |
de408c29 | 810 | ); |
d9bfcf4d SW |
811 | let mut r = Row { |
812 | label: "nope".to_owned(), | |
813 | entries: HashMap::from([ | |
814 | ("foo".to_owned(), vec![None]), | |
815 | ("baz".to_owned(), vec![None]), | |
816 | ]), | |
817 | }; | |
818 | assert_eq!(r.entries.len(), 2); | |
ba61b04b | 819 | render_cell(&Config::default(), "foo", &mut r); |
d9bfcf4d | 820 | assert_eq!(r.entries.len(), 1); |
ba61b04b | 821 | render_cell(&Config::default(), "bar", &mut r); |
d9bfcf4d | 822 | assert_eq!(r.entries.len(), 1); |
ba61b04b | 823 | render_cell(&Config::default(), "baz", &mut r); |
d9bfcf4d | 824 | assert_eq!(r.entries.len(), 0); |
de408c29 | 825 | } |
25fd008e | 826 | |
9a626020 SW |
827 | #[test] |
828 | fn test_render_leftovers() { | |
829 | assert_eq!( | |
b4bc28ba SW |
830 | render_all_leftovers( |
831 | &Config::default(), | |
832 | &Row { | |
833 | label: "nope".to_owned(), | |
834 | entries: HashMap::from([("foo".to_owned(), vec![None])]), | |
835 | } | |
836 | ), | |
9a626020 SW |
837 | HTML::from("foo") |
838 | ); | |
839 | assert_eq!( | |
b4bc28ba SW |
840 | render_all_leftovers( |
841 | &Config::default(), | |
842 | &Row { | |
843 | label: "nope".to_owned(), | |
844 | entries: HashMap::from([ | |
845 | ("foo".to_owned(), vec![None]), | |
846 | ("bar".to_owned(), vec![None]) | |
847 | ]), | |
848 | } | |
849 | ), | |
9a626020 SW |
850 | HTML::from("bar, foo") |
851 | ); | |
852 | assert_eq!( | |
b4bc28ba SW |
853 | render_all_leftovers( |
854 | &Config::default(), | |
855 | &Row { | |
856 | label: "nope".to_owned(), | |
857 | entries: HashMap::from([ | |
858 | ("foo".to_owned(), vec![None]), | |
859 | ("bar".to_owned(), vec![None, None]) | |
860 | ]), | |
861 | } | |
862 | ), | |
f8c2cab2 | 863 | HTML::from("bar: 𝍷𝍷, foo") |
9a626020 | 864 | ); |
3135b2cd SW |
865 | assert_eq!( |
866 | render_all_leftovers( | |
867 | &Config { | |
868 | column_threshold: 2, | |
869 | static_columns: vec![], | |
870 | hidden_columns: HashSet::from(["private".to_owned()]), | |
d669f60d | 871 | substitute_labels: HashMap::new(), |
3135b2cd SW |
872 | }, |
873 | &Row { | |
874 | label: "nope".to_owned(), | |
875 | entries: HashMap::from([("private".to_owned(), vec![None]),]), | |
876 | } | |
877 | ), | |
878 | HTML::from("") | |
879 | ); | |
9a626020 SW |
880 | } |
881 | ||
25fd008e SW |
882 | #[test] |
883 | fn test_render_row() { | |
884 | assert_eq!( | |
885 | render_row( | |
bc552978 | 886 | &Config::default(), |
25fd008e | 887 | &["foo".to_owned()], |
06a6a5ca | 888 | &mut Rowlike::Row(Row { |
25fd008e SW |
889 | label: "nope".to_owned(), |
890 | entries: HashMap::from([("bar".to_owned(), vec![None])]), | |
06a6a5ca | 891 | }) |
25fd008e SW |
892 | ), |
893 | HTML::from( | |
b59ad433 | 894 | 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> |
a411a19d SW |
895 | "# |
896 | ) | |
897 | ); | |
898 | assert_eq!( | |
899 | render_row( | |
900 | &Config { | |
901 | column_threshold: 0, | |
a0577201 | 902 | static_columns: vec![Some("foo".to_owned()), Some("bar".to_owned())], |
3135b2cd | 903 | hidden_columns: HashSet::new(), |
d669f60d | 904 | substitute_labels: HashMap::new(), |
a411a19d SW |
905 | }, |
906 | &["baz".to_owned()], | |
907 | &mut Rowlike::Row(Row { | |
908 | label: "nope".to_owned(), | |
909 | entries: HashMap::from([ | |
910 | ("bar".to_owned(), vec![Some("r".to_owned())]), | |
911 | ("baz".to_owned(), vec![Some("z".to_owned())]), | |
912 | ("foo".to_owned(), vec![Some("f".to_owned())]), | |
913 | ]), | |
914 | }) | |
915 | ), | |
916 | HTML::from( | |
917 | 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> | |
a0577201 SW |
918 | "# |
919 | ) | |
920 | ); | |
921 | assert_eq!( | |
922 | render_row( | |
923 | &Config { | |
924 | column_threshold: 0, | |
925 | static_columns: vec![Some("foo".to_owned()), None, Some("bar".to_owned())], | |
3135b2cd | 926 | hidden_columns: HashSet::new(), |
d669f60d | 927 | substitute_labels: HashMap::new(), |
a0577201 SW |
928 | }, |
929 | &[], | |
930 | &mut Rowlike::Row(Row { | |
931 | label: "nope".to_owned(), | |
932 | entries: HashMap::from([ | |
933 | ("bar".to_owned(), vec![Some("r".to_owned())]), | |
934 | ("foo".to_owned(), vec![Some("f".to_owned())]), | |
935 | ]), | |
936 | }) | |
937 | ), | |
938 | HTML::from( | |
939 | 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> | |
3135b2cd SW |
940 | "# |
941 | ) | |
942 | ); | |
943 | assert_eq!( | |
944 | render_row( | |
945 | &Config { | |
946 | column_threshold: 0, | |
947 | static_columns: vec![], | |
948 | hidden_columns: HashSet::from(["foo".to_owned()]), | |
d669f60d | 949 | substitute_labels: HashMap::new(), |
3135b2cd SW |
950 | }, |
951 | &[], | |
952 | &mut Rowlike::Row(Row { | |
953 | label: "nope".to_owned(), | |
954 | entries: HashMap::from([("foo".to_owned(), vec![Some("f".to_owned())]),]), | |
955 | }) | |
956 | ), | |
957 | HTML::from( | |
958 | r#"<tr><th id="nope">nope</th><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr> | |
959 | "# | |
960 | ) | |
961 | ); | |
962 | assert_eq!( | |
963 | render_row( | |
964 | &Config { | |
965 | column_threshold: 0, | |
966 | static_columns: vec![Some("foo".to_owned())], | |
967 | hidden_columns: HashSet::from(["foo".to_owned()]), | |
d669f60d | 968 | substitute_labels: HashMap::new(), |
3135b2cd SW |
969 | }, |
970 | &[], | |
971 | &mut Rowlike::Row(Row { | |
972 | label: "nope".to_owned(), | |
973 | entries: HashMap::from([("foo".to_owned(), vec![Some("f".to_owned())]),]), | |
974 | }) | |
975 | ), | |
976 | HTML::from( | |
977 | r#"<tr><th id="nope">nope</th><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr> | |
25fd008e SW |
978 | "# |
979 | ) | |
980 | ); | |
981 | } | |
75bb888a | 982 | } |