[librsvg: 4/15] Document::load_from_bytes - Moved from css.rs, as a general utility for tests




commit 314d90d4a981842e892c152ad4fff7c37fa4fe6c
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Mar 8 17:28:59 2021 -0600

    Document::load_from_bytes - Moved from css.rs, as a general utility for tests

 src/css.rs      | 17 +----------------
 src/document.rs | 16 ++++++++++++++++
 2 files changed, 17 insertions(+), 16 deletions(-)
---
diff --git a/src/css.rs b/src/css.rs
index 4158d68a..a577d419 100644
--- a/src/css.rs
+++ b/src/css.rs
@@ -795,28 +795,13 @@ pub fn cascade(
 #[cfg(test)]
 mod tests {
     use super::*;
-    use gio;
-    use glib::{self, prelude::*};
     use selectors::Element;
 
     use crate::document::Document;
-    use crate::handle::LoadOptions;
-
-    fn load_document(input: &'static [u8]) -> Document {
-        let bytes = glib::Bytes::from_static(input);
-        let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
-
-        Document::load_from_stream(
-            &LoadOptions::new(UrlResolver::new(None)),
-            &stream.upcast(),
-            None::<&gio::Cancellable>,
-        )
-        .unwrap()
-    }
 
     #[test]
     fn impl_element() {
-        let document = load_document(
+        let document = Document::load_from_bytes(
             br#"<?xml version="1.0" encoding="UTF-8"?>
 <svg xmlns="http://www.w3.org/2000/svg"; id="a">
   <rect id="b" x="10" y="10" width="30" height="30"/>
diff --git a/src/document.rs b/src/document.rs
index 28965b0d..dc106fd9 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -104,6 +104,22 @@ impl Document {
         )
     }
 
+    /// Utility function to load a document from a static string in tests.
+    #[cfg(test)]
+    pub fn load_from_bytes(input: &'static [u8]) -> Document {
+        use glib::prelude::*;
+
+        let bytes = glib::Bytes::from_static(input);
+        let stream = gio::MemoryInputStream::new_from_bytes(&bytes);
+
+        Document::load_from_stream(
+            &LoadOptions::new(UrlResolver::new(None)),
+            &stream.upcast(),
+            None::<&gio::Cancellable>,
+        )
+        .unwrap()
+    }
+
     /// Gets the root node.  This is guaranteed to be an `<svg>` element.
     pub fn root(&self) -> Node {
         self.tree.clone()


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