[librsvg/librsvg-2.44] Length: basic tests for normalization



commit 69faef48004aca4bd70bf6ee2de5a08178f41d5c
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 37ff9eac..37dfdd02 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -304,6 +304,8 @@ fn parse_dash_array(parser: &mut Parser) -> Result<Vec<Length>, ValueErrorKind>
 mod tests {
     use super::*;
 
+    use float_eq_cairo::ApproxEqCairo;
+
     #[test]
     fn parses_default() {
         assert_eq!(
@@ -404,6 +406,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, ValueErrorKind> {
         Dasharray::parse_str(s, ())
     }


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