From 46b4461cfd8505f4d417ea1e6c631fcfa12c72df Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 24 Feb 2025 20:45:11 -0800 Subject: [PATCH] pass all the text_line tests! --- rust/pspp/src/output/text_line.rs | 116 +++++++++++++++++++++++++++--- 1 file changed, 108 insertions(+), 8 deletions(-) diff --git a/rust/pspp/src/output/text_line.rs b/rust/pspp/src/output/text_line.rs index b739656e7e..4b2b0f5919 100644 --- a/rust/pspp/src/output/text_line.rs +++ b/rust/pspp/src/output/text_line.rs @@ -409,25 +409,125 @@ mod test { for bottom in all::() { for top in all::() { 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::() { + for top in all::() { + 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::() { + for top in all::() { + 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::() { + for top in all::() { + 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::() { + for top in all::() { + 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:?}" ); } -- 2.30.2