use std::io::BufRead;
use std::iter::Iterator;
-fn tally_marks(n: usize, mark: Option<&str>) -> String {
- match mark {
+const TALLY_FONT: &str = "BabelStone Han";
+
+fn tally_marks(n: usize, mark: Option<&str>) -> HTML {
+ HTML(match mark {
None => {
let fives = { 0..n / 5 }.map(|_| 'πΈ');
let ones = { 0..n % 5 }.map(|_| 'π·');
- fives.chain(ones).collect()
+ let marks: String = fives.chain(ones).collect();
+ format!("<span style=\"font-family: '{TALLY_FONT}'\">{marks}</span>")
}
Some(m) => { 0..n }.map(|_| m).collect(),
- }
+ })
}
#[derive(PartialEq, Eq, Debug)]
None => tally += 1,
Some(ref content) => {
if tally > 0 {
- out.push(HTML(tally_marks(tally, mark)));
+ out.push(tally_marks(tally, mark));
tally = 0;
}
out.push(HTML::escape(content));
}
}
if tally > 0 {
- out.push(HTML(tally_marks(tally, mark)));
+ out.push(tally_marks(tally, mark));
}
HTML(
out.into_iter()
- .map(|html| html.0) // Waiting for slice_concat_trait to stabilize
+ .map(|html| html.0)
.collect::<Vec<_>>()
.join(" "),
)
row.entries.get(notcol).expect("Key vanished?!"),
)
})
- .map(|html| html.0) // Waiting for slice_concat_trait to stabilize
+ .map(|html| html.0)
.collect::<Vec<_>>()
.join(", "),
)
#[test]
fn test_tally_marks() {
- assert_eq!(tally_marks(1, None), "π·");
- assert_eq!(tally_marks(2, None), "π·π·");
- assert_eq!(tally_marks(3, None), "π·π·π·");
- assert_eq!(tally_marks(4, None), "π·π·π·π·");
- assert_eq!(tally_marks(5, None), "πΈ");
- assert_eq!(tally_marks(6, None), "πΈπ·");
- assert_eq!(tally_marks(7, None), "πΈπ·π·");
- assert_eq!(tally_marks(8, None), "πΈπ·π·π·");
- 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("π")), "ππ");
+ assert_eq!(
+ tally_marks(1, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">π·</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(2, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">π·π·</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(3, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">π·π·π·</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(4, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">π·π·π·π·</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(5, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">πΈ</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(6, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">πΈπ·</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(7, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">πΈπ·π·</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(8, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">πΈπ·π·π·</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(9, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">πΈπ·π·π·π·</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(10, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">πΈπΈ</span>"
+ ))
+ );
+ assert_eq!(
+ tally_marks(11, None),
+ HTML(format!(
+ "<span style=\"font-family: '{TALLY_FONT}'\">πΈπΈπ·</span>"
+ ))
+ );
+ assert_eq!(tally_marks(1, Some("x")), "x".into());
+ assert_eq!(tally_marks(4, Some("x")), "xxxx".into());
+ assert_eq!(tally_marks(5, Some("x")), "xxxxx".into());
+ assert_eq!(tally_marks(6, Some("x")), "xxxxxx".into());
+ assert_eq!(tally_marks(2, Some("π")), "ππ".into());
}
fn read_rows(input: impl std::io::Read) -> Result<Vec<Rowlike>, std::io::Error> {
}
),
HTML::from(
- r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">π·</td>"#
+ r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"><span style="font-family: 'BabelStone Han'">π·</span></td>"#
)
);
assert_eq!(
}
),
HTML::from(
- r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">π·π·</td>"#
+ r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')"><span style="font-family: 'BabelStone Han'">π·π·</span></td>"#
)
);
assert_eq!(
}
),
HTML::from(
- r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 π·</td>"#
+ r#"<td class="yes" onmouseover="h2('nope','foo')" onmouseout="ch2('nope','foo')">5 <span style="font-family: 'BabelStone Han'">π·</span></td>"#
)
);
assert_eq!(
}
),
HTML::from(
- r#"<td class="yes" onmouseover="h2('bob's','foo')" onmouseout="ch2('bob's','foo')">π·</td>"#
+ r#"<td class="yes" onmouseover="h2('bob's','foo')" onmouseout="ch2('bob's','foo')"><span style="font-family: 'BabelStone Han'">π·</span></td>"#
)
);
assert_eq!(
]),
}
),
- HTML::from("bar: π·π·, foo")
+ HTML::from(r#"bar: <span style="font-family: 'BabelStone Han'">π·π·</span>, foo"#)
);
assert_eq!(
render_all_leftovers(
})
),
HTML::from(
- 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>
+ r#"<tr><th id="nope">nope</th><td class="yes" onmouseover="h2('nope','bar')" onmouseout="ch2('nope','bar')"><span style="font-family: 'BabelStone Han'">π·</span></td><td class="leftover" onmouseover="highlight('nope')" onmouseout="clear_highlight('nope')"></td></tr>
"#
)
);