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:?}"
);
}