pass all the text_line tests!
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 25 Feb 2025 04:45:11 +0000 (20:45 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Tue, 25 Feb 2025 04:45:11 +0000 (20:45 -0800)
rust/pspp/src/output/text_line.rs

index b739656e7ef6ccdcd520d6bf0b810692f9772300..4b2b0f5919ec66a96a860c715b7806c2c4216d53 100644 (file)
@@ -409,25 +409,125 @@ mod test {
         for bottom in all::<Emphasis>() {
             for top in all::<Emphasis>() {
                 let mut line = TextLine::new();
-                // Produces `?か??くけ?さ`.
-                // Produces `?か?うえお`.
-                line.put(0, &bottom.apply("あいうえお"));
+                // Produces `?か?うえおさ`.
+                line.put(0, &bottom.apply("あいうえおさ"));
                 line.put(1, &top.apply("か"));
-                //line.put(5, &top.apply("くけ"));
-                /*
+                assert_eq!(
+                    line.str(),
+                    &format!("?{}?{}", top.apply("か"), bottom.apply("うえおさ"),),
+                    "bottom={bottom:?} top={top:?}"
+                );
+
+                // Produces `?か??くけ?さ`.
+                line.put(5, &top.apply("くけ"));
                 assert_eq!(
                     line.str(),
                     &format!(
-                        "?{}??{}{}",
+                        "?{}??{}?{}",
                         top.apply("か"),
                         top.apply("くけ"),
                         bottom.apply("さ")
                     ),
                     "bottom={bottom:?} top={top:?}"
-                );*/
+                );
+            }
+        }
+    }
+
+    /// Overwrite rest of line, aligned single-width over double-width.
+    #[test]
+    fn aligned_rest_single_over_double() {
+        for bottom in all::<Emphasis>() {
+            for top in all::<Emphasis>() {
+                let mut line = TextLine::new();
+                // Produces `あkikuko`.
+                line.put(0, &bottom.apply("あいう"));
+                line.put(2, &top.apply("kikuko"));
+                assert_eq!(
+                    line.str(),
+                    &format!("{}{}", bottom.apply("あ"), top.apply("kikuko"),),
+                    "bottom={bottom:?} top={top:?}"
+                );
+            }
+        }
+    }
+
+    /// Overwrite rest of line, misaligned single-width over double-width.
+    #[test]
+    fn misaligned_rest_single_over_double() {
+        for bottom in all::<Emphasis>() {
+            for top in all::<Emphasis>() {
+                let mut line = TextLine::new();
+                // Produces `あ?kikuko`.
+                line.put(0, &bottom.apply("あいう"));
+                line.put(3, &top.apply("kikuko"));
                 assert_eq!(
                     line.str(),
-                    &format!("?{}?{}", top.apply("か"), bottom.apply("うえお"),),
+                    &format!("{}?{}", bottom.apply("あ"), top.apply("kikuko"),),
+                    "bottom={bottom:?} top={top:?}"
+                );
+            }
+        }
+    }
+
+    /// Overwrite partial line, aligned single-width over double-width.
+    #[test]
+    fn aligned_partial_single_over_double() {
+        for bottom in all::<Emphasis>() {
+            for top in all::<Emphasis>() {
+                let mut line = TextLine::new();
+                // Produces `kaいうえお`.
+                line.put(0, &bottom.apply("あいうえお"));
+                line.put(0, &top.apply("ka"));
+                assert_eq!(
+                    line.str(),
+                    &format!("{}{}", top.apply("ka"), bottom.apply("いうえお"),),
+                    "bottom={bottom:?} top={top:?}"
+                );
+
+                // Produces `kaいkukeお`.
+                line.put(4, &top.apply("kuke"));
+                assert_eq!(
+                    line.str(),
+                    &format!(
+                        "{}{}{}{}",
+                        top.apply("ka"),
+                        bottom.apply("い"),
+                        top.apply("kuke"),
+                        bottom.apply("お")
+                    ),
+                    "bottom={bottom:?} top={top:?}"
+                );
+            }
+        }
+    }
+
+    /// Overwrite partial line, misaligned single-width over double-width.
+    #[test]
+    fn misaligned_partial_single_over_double() {
+        for bottom in all::<Emphasis>() {
+            for top in all::<Emphasis>() {
+                let mut line = TextLine::new();
+                // Produces `?aいうえおさ`.
+                line.put(0, &bottom.apply("あいうえおさ"));
+                line.put(1, &top.apply("a"));
+                assert_eq!(
+                    line.str(),
+                    &format!("?{}{}", top.apply("a"), bottom.apply("いうえおさ"),),
+                    "bottom={bottom:?} top={top:?}"
+                );
+
+                // Produces `?aい?kuke?さ`.
+                line.put(5, &top.apply("kuke"));
+                assert_eq!(
+                    line.str(),
+                    &format!(
+                        "?{}{}?{}?{}",
+                        top.apply("a"),
+                        bottom.apply("い"),
+                        top.apply("kuke"),
+                        bottom.apply("さ")
+                    ),
                     "bottom={bottom:?} top={top:?}"
                 );
             }