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