[librsvg] Length: basic tests for normalization



commit a8e5a3386698617876a69e4b38aa8fb6c08cc314
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Sep 3 14:57:16 2018 -0500

    Length: basic tests for normalization

 rsvg_internals/src/length.rs | 62 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
---
diff --git a/rsvg_internals/src/length.rs b/rsvg_internals/src/length.rs
index c812d568..f3a3881a 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -301,6 +301,8 @@ fn parse_dash_array(parser: &mut Parser) -> Result<Vec<Length>, AttributeError>
 mod tests {
     use super::*;
 
+    use float_eq_cairo::ApproxEqCairo;
+
     #[test]
     fn parses_default() {
         assert_eq!(
@@ -401,6 +403,66 @@ mod tests {
         );
     }
 
+    #[test]
+    fn normalize_default_works() {
+        let params = ViewParams {
+            dpi_x: 40.0,
+            dpi_y: 40.0,
+            view_box_width: 100.0,
+            view_box_height: 100.0,
+        };
+
+        let values = ComputedValues::default();
+
+        assert_approx_eq_cairo!(
+            Length::new(10.0, LengthUnit::Default, LengthDir::Both).normalize(&values, &params),
+            10.0
+        );
+    }
+
+    #[test]
+    fn normalize_absolute_units_works() {
+        let params = ViewParams {
+            dpi_x: 40.0,
+            dpi_y: 50.0,
+            view_box_width: 100.0,
+            view_box_height: 100.0,
+        };
+
+        let values = ComputedValues::default();
+
+        assert_approx_eq_cairo!(
+            Length::new(10.0, LengthUnit::Inch, LengthDir::Horizontal).normalize(&values, &params),
+            400.0
+        );
+        assert_approx_eq_cairo!(
+            Length::new(10.0, LengthUnit::Inch, LengthDir::Vertical).normalize(&values, &params),
+            500.0
+        );
+    }
+
+    #[test]
+    fn normalize_percent_works() {
+        let params = ViewParams {
+            dpi_x: 40.0,
+            dpi_y: 40.0,
+            view_box_width: 100.0,
+            view_box_height: 200.0,
+        };
+
+        let values = ComputedValues::default();
+
+        assert_approx_eq_cairo!(
+            Length::new(0.05, LengthUnit::Percent, LengthDir::Horizontal)
+                .normalize(&values, &params),
+            5.0
+        );
+        assert_approx_eq_cairo!(
+            Length::new(0.05, LengthUnit::Percent, LengthDir::Vertical).normalize(&values, &params),
+            10.0
+        );
+    }
+
     fn parse_dash_array_str(s: &str) -> Result<Dasharray, AttributeError> {
         Dasharray::parse_str(s, ())
     }


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