[librsvg: 4/22] Characterization tests for text_anchor_advance() so I don't break it




commit 2cbf66e9512330e4fcb6ad200d71c54f4c22171b
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Sep 22 19:47:16 2021 -0500

    Characterization tests for text_anchor_advance() so I don't break it
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/593>

 src/text.rs | 44 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)
---
diff --git a/src/text.rs b/src/text.rs
index f9573389..66957706 100644
--- a/src/text.rs
+++ b/src/text.rs
@@ -891,7 +891,7 @@ fn create_pango_layout(draw_ctx: &DrawingCtx, props: &FontProperties, text: &str
 
 #[cfg(test)]
 mod tests {
-    use super::Chars;
+    use super::*;
 
     #[test]
     fn chars_default() {
@@ -907,4 +907,46 @@ mod tests {
         assert_eq!(c.get_string(), example);
         assert!(c.space_normalized.borrow().is_none());
     }
+
+    // This is called _horizontal because the property value in "CSS Writing Modes 3"
+    // is `horizontal-tb`.  Eventually we will support that and this will make more sense.
+    #[test]
+    fn adjusted_advance_horizontal() {
+        assert_eq!(
+            text_anchor_advance(TextAnchor::Start, WritingMode::LrTb, (2.0, 4.0)),
+            (0.0, 0.0)
+        );
+
+        assert_eq!(
+            text_anchor_advance(TextAnchor::Middle, WritingMode::LrTb, (2.0, 4.0)),
+            (-1.0, 0.0)
+        );
+
+        assert_eq!(
+            text_anchor_advance(TextAnchor::End, WritingMode::LrTb, (2.0, 4.0)),
+            (-2.0, 0.0)
+        );
+    }
+
+    // This is called _vertical because "CSS Writing Modes 3" has both `vertical-rl` (East
+    // Asia), and `vertical-lr` (Manchu, Mongolian), but librsvg does not support block
+    // flow direction properly yet.  Eventually we will support that and this will make
+    // more sense.
+    #[test]
+    fn adjusted_advance_vertical() {
+        assert_eq!(
+            text_anchor_advance(TextAnchor::Start, WritingMode::Tb, (2.0, 4.0)),
+            (0.0, 0.0)
+        );
+
+        assert_eq!(
+            text_anchor_advance(TextAnchor::Middle, WritingMode::Tb, (2.0, 4.0)),
+            (0.0, -2.0)
+        );
+
+        assert_eq!(
+            text_anchor_advance(TextAnchor::End, WritingMode::Tb, (2.0, 4.0)),
+            (0.0, -4.0)
+        );
+    }
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]