]> git.scottworley.com Git - tablify/commitdiff
Render tally marks with overridden mark character
authorScott Worley <scottworley@scottworley.com>
Thu, 24 Oct 2024 18:04:58 +0000 (11:04 -0700)
committerScott Worley <scottworley@scottworley.com>
Thu, 24 Oct 2024 18:12:48 +0000 (11:12 -0700)
src/lib.rs

index 731457e6b07389fdd1cf39ff5e423d71b3c6e27a..4deceffb5ff53677903e6f4e2a46a93d7390a462 100644 (file)
@@ -5,9 +5,14 @@ use std::io::BufRead;
 use std::iter::Iterator;
 
 fn tally_marks(n: usize, mark: Option<&str>) -> String {
 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)]
 }
 
 #[derive(PartialEq, Eq, Debug)]
@@ -502,6 +507,11 @@ mod tests {
         assert_eq!(tally_marks(9, None), "𝍸𝍷𝍷𝍷𝍷");
         assert_eq!(tally_marks(10, None), "𝍸𝍸");
         assert_eq!(tally_marks(11, 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("πŸ”")), "πŸ”πŸ”");
     }
 
     fn read_rows(input: impl std::io::Read) -> Result<Vec<Rowlike>, std::io::Error> {
     }
 
     fn read_rows(input: impl std::io::Read) -> Result<Vec<Rowlike>, std::io::Error> {
@@ -821,6 +831,26 @@ mod tests {
                 r#"<td class="yes" onmouseover="h2('bob&#39;s','foo')" onmouseout="ch2('bob&#39;s','foo')">𝍷</td>"#
             )
         );
                 r#"<td class="yes" onmouseover="h2('bob&#39;s','foo')" onmouseout="ch2('bob&#39;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([
         let mut r = Row {
             label: "nope".to_owned(),
             entries: HashMap::from([
@@ -891,6 +921,22 @@ mod tests {
             ),
             HTML::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]
     }
 
     #[test]