use std::iter::Iterator;
fn tally_marks(n: usize, mark: Option<&str>) -> String {
- let fives = { 0..n / 5 }.map(|_| 'πΈ');
- let ones = { 0..n % 5 }.map(|_| 'π·');
- fives.chain(ones).collect()
+ match mark {
+ None => {
+ let fives = { 0..n / 5 }.map(|_| 'πΈ');
+ let ones = { 0..n % 5 }.map(|_| 'π·');
+ fives.chain(ones).collect()
+ }
+ Some(m) => { 0..n }.map(|_| m).collect(),
+ }
}
#[derive(PartialEq, Eq, Debug)]
.substitute_labels
.insert(col.to_owned(), label.to_owned()),
};
+ } else if let Some(directive) = cmd.strip_prefix("mark ") {
+ match directive.split_once(':') {
+ None => {
+ return Err(std::io::Error::new(
+ std::io::ErrorKind::InvalidInput,
+ format!("line {line_num}: Mark missing ':'"),
+ ))
+ }
+ Some((col, label)) => self.mark.insert(col.to_owned(), label.to_owned()),
+ };
} else {
return Err(std::io::Error::new(
std::io::ErrorKind::InvalidInput,
assert_eq!(tally_marks(9, None), "πΈπ·π·π·π·");
assert_eq!(tally_marks(10, None), "πΈπΈ");
assert_eq!(tally_marks(11, None), "πΈπΈπ·");
+ assert_eq!(tally_marks(1, Some("x")), "x");
+ assert_eq!(tally_marks(4, Some("x")), "xxxx");
+ assert_eq!(tally_marks(5, Some("x")), "xxxxx");
+ assert_eq!(tally_marks(6, Some("x")), "xxxxxx");
+ assert_eq!(tally_marks(2, Some("π")), "ππ");
}
fn read_rows(input: impl std::io::Read) -> Result<Vec<Rowlike>, std::io::Error> {
.substitute_labels["foo"],
"bar"
);
+ assert_eq!(read_config(&b"!mark foo:*"[..]).unwrap().mark["foo"], "*");
let bad_command = read_config(&b"!no such command"[..]);
assert!(bad_command.is_err());
let bad_sub = read_config(&b"!label foo"[..]);
assert!(bad_sub.is_err());
assert!(format!("{bad_sub:?}").contains("line 1: Annotation missing ':'"));
+
+ let bad_mark = read_config(&b"!mark foo"[..]);
+ assert!(bad_mark.is_err());
+ assert!(format!("{bad_mark:?}").contains("line 1: Mark missing ':'"));
}
#[test]
r#"<td class="yes" onmouseover="h2('bob's','foo')" onmouseout="ch2('bob's','foo')">π·</td>"#
)
);
+ assert_eq!(
+ render_cell(
+ &Config {
+ column_threshold: 2,
+ static_columns: vec![],
+ hidden_columns: HashSet::new(),
+ substitute_labels: HashMap::new(),
+ mark: HashMap::from([("foo".to_owned(), "π¦".to_owned())]),
+ },
+ "foo",
+ &mut Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("foo".to_owned(), vec![None])]),
+ }
+ ),
+ HTML::from(
+ r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">π¦</td>"#
+ )
+ );
+
let mut r = Row {
label: "nope".to_owned(),
entries: HashMap::from([
),
HTML::from("")
);
+ assert_eq!(
+ render_all_leftovers(
+ &Config {
+ column_threshold: 2,
+ static_columns: vec![],
+ hidden_columns: HashSet::new(),
+ substitute_labels: HashMap::new(),
+ mark: HashMap::from([("foo".to_owned(), "π".to_owned())]),
+ },
+ &Row {
+ label: "nope".to_owned(),
+ entries: HashMap::from([("foo".to_owned(), vec![None, None])]),
+ }
+ ),
+ HTML::from("foo: ππ")
+ );
}
#[test]