[librsvg: 1/2] Remove ignore from doctests




commit f084aa10d754ffce14d19a245ffd140aa2c65544
Author: Dunja Lalic <dunja lalic gmail com>
Date:   Mon Oct 19 16:19:17 2020 +0000

    Remove ignore from doctests

 librsvg_crate/src/lib.rs              | 13 +++++++------
 rsvg_internals/src/aspect_ratio.rs    | 15 +++++----------
 rsvg_internals/src/css.rs             |  4 ++--
 rsvg_internals/src/error.rs           | 22 ++++++++++++++++------
 rsvg_internals/src/href.rs            | 11 +++++++----
 rsvg_internals/src/length.rs          | 28 ++++++++++++++++++++++------
 rsvg_internals/src/lib.rs             | 12 ++++++++++++
 rsvg_internals/src/parsers.rs         | 10 +++++++++-
 rsvg_internals/src/properties.rs      |  2 +-
 rsvg_internals/src/property_macros.rs |  6 +++---
 10 files changed, 84 insertions(+), 39 deletions(-)
---
diff --git a/librsvg_crate/src/lib.rs b/librsvg_crate/src/lib.rs
index a68f08af..7425924e 100644
--- a/librsvg_crate/src/lib.rs
+++ b/librsvg_crate/src/lib.rs
@@ -241,23 +241,24 @@ impl Loader {
     ///
     /// # Example:
     ///
-    /// ```ignore
-    /// # // Test is ignored because "make distcheck" breaks, as the output file
-    /// # // can't be written to the read-only srcdir.
-    ///
+    /// ```
+    /// # use std::env;
     /// let svg_handle = librsvg::Loader::new()
     ///     .keep_image_data()
     ///     .read_path("example.svg")
     ///     .unwrap();
     ///
-    /// let surface = cairo::PdfSurface::new(640.0, 480.0, "output.pdf");
+    /// let mut output = env::temp_dir();
+    /// output.push("output.pdf");
+    /// let surface = cairo::PdfSurface::new(640.0, 480.0, output)?;
     /// let cr = cairo::Context::new(&surface);
     ///
     /// let renderer = librsvg::CairoRenderer::new(&svg_handle);
     /// renderer.render_document(
     ///     &cr,
     ///     &cairo::Rectangle { x: 0.0, y: 0.0, width: 640.0, height: 480.0 },
-    /// ).unwrap();
+    /// )?;
+    /// # Ok::<(), librsvg::RenderingError>(())
     /// ```
     pub fn keep_image_data(mut self) -> Self {
         self.keep_image_data = true;
diff --git a/rsvg_internals/src/aspect_ratio.rs b/rsvg_internals/src/aspect_ratio.rs
index f663c541..93c0b807 100644
--- a/rsvg_internals/src/aspect_ratio.rs
+++ b/rsvg_internals/src/aspect_ratio.rs
@@ -3,17 +3,12 @@
 //! This module handles `preserveAspectRatio` values [per the SVG specification][spec].
 //! We have an [`AspectRatio`] struct which encapsulates such a value.
 //!
-//! ```ignore
+//! ```
+//! # use rsvg_internals::doctest_only::AspectRatio;
+//! # use crate::rsvg_internals::Parse;
 //! assert_eq!(
-//!     AspectRatio::parse("xMidYMid", ()),
-//!     Ok(AspectRatio {
-//!         defer: false,
-//!         align: Some(Align {
-//!             x: X(Align1D::Mid),
-//!             y: Y(Align1D::Mid),
-//!             fit: FitMode::Meet,
-//!         }),
-//!     })
+//!     AspectRatio::parse_str("xMidYMid"),
+//!     Ok(AspectRatio::default())
 //! );
 //! ```
 //!
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index 3b20a4a1..522cf2fd 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -4,7 +4,7 @@
 //!
 //! Consider a CSS **stylesheet** like this:
 //!
-//! ```ignore
+//! ```css
 //! @import url("another.css");
 //!
 //! foo, .bar {
@@ -210,7 +210,7 @@ impl<'i> selectors::Parser<'i> for RuleParser {
 // implement a way to parse the `Prelude` of a ruleset or rule.  For
 // example, in this ruleset:
 //
-// ```ignore
+// ```css
 // foo, .bar { fill: red; stroke: green; }
 // ```
 //
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index 2a1345e1..839bd37e 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -206,14 +206,24 @@ impl fmt::Display for AcquireError {
 /// From<FooError> for ValueErrorKind`, then this trait helps assign attribute values in
 /// `set_atts()` methods as follows:
 ///
-/// ```ignore
-/// use error::AttributeResultExt;
-///
-/// // fn parse_foo(...) -> Result<Foo, FooError>
+/// ```
+/// # use rsvg_internals::doctest_only::AttributeResultExt;
+/// # use rsvg_internals::doctest_only::ValueErrorKind;
+/// # use rsvg_internals::doctest_only::ElementError;
+/// # use markup5ever::{QualName, Prefix, Namespace, LocalName};
+/// # type FooError = ValueErrorKind;
+/// fn parse_foo(value: &str) -> Result<(), FooError>
+/// # { Err(ValueErrorKind::value_error("test")) }
 ///
 /// // It is assumed that there is an impl From<FooError> for ValueErrorKind
-///
-/// self.foo = parse_foo(value).attribute(local_name!("foo"))?;
+/// # let attr = QualName::new(
+/// #     Some(Prefix::from("")),
+/// #     Namespace::from(""),
+/// #     LocalName::from(""),
+/// # );
+/// let result = parse_foo("value").attribute(attr);
+/// assert!(result.is_err());
+/// # Ok::<(), ElementError>(())
 /// ```
 ///
 /// The call to `.attribute(attr)` converts the `Result` from `parse_foo()` into a full
diff --git a/rsvg_internals/src/href.rs b/rsvg_internals/src/href.rs
index 3628828c..de090643 100644
--- a/rsvg_internals/src/href.rs
+++ b/rsvg_internals/src/href.rs
@@ -15,16 +15,19 @@ use markup5ever::{expanded_name, local_name, namespace_url, ns, ExpandedName};
 ///
 /// Use with an `if` pattern inside a `match`:
 ///
-/// ```ignore
-/// # use markup5ever::{LocalName, Namespace, Prefix, QualName, namespace_url};
+/// ```
+/// # #[macro_use] extern crate markup5ever;
+/// # use markup5ever::{QualName, Prefix, Namespace, LocalName, ExpandedName};
+/// # use rsvg_internals::doctest_only::{is_href,set_href};
+///
 /// let qual_name = QualName::new(
 ///     Some(Prefix::from("xlink")),
 ///     Namespace::from("http://www.w3.org/1999/xlink";),
 ///     LocalName::from("href"),
 /// );
 ///
-/// // assume foo is an Option<Value>
-/// // assume value is a Value
+/// let value = expanded_name!("", "path");
+/// let mut foo = Some(value);
 ///
 /// match qual_name.expanded() {
 ///     ref name if is_href(name) => set_href(name, &mut foo, value),
diff --git a/rsvg_internals/src/length.rs b/rsvg_internals/src/length.rs
index 85d5d2ae..317ad521 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -12,7 +12,8 @@
 //! For example, the implementation of [`Circle`] defines this structure with fields for the
 //! `(center_x, center_y, radius)`:
 //!
-//! ```ignore
+//! ```
+//! # use rsvg_internals::doctest_only::{Length,Horizontal,Vertical,Both};
 //! pub struct Circle {
 //!     cx: Length<Horizontal>,
 //!     cy: Length<Vertical>,
@@ -172,7 +173,9 @@ impl Normalize for Both {
 ///
 /// Examples of construction:
 ///
-/// ```ignore
+/// ```
+/// # use rsvg_internals::doctest_only::{Length,LengthUnit,Horizontal,Vertical,Both};
+/// # use crate::rsvg_internals::Parse;
 /// // Explicit type
 /// let width: Length<Horizontal> = Length::new(42.0, LengthUnit::Cm);
 ///
@@ -276,7 +279,8 @@ impl<N: Normalize> Length<N> {
     /// The compiler needs to know the type parameter `N` which represents the length's
     /// orientation.  You can specify it explicitly, or call the parametrized method:
     ///
-    /// ```ignore
+    /// ```
+    /// # use rsvg_internals::doctest_only::{Length,LengthUnit,Horizontal,Vertical};
     /// // Explicit type
     /// let width: Length<Horizontal> = Length::new(42.0, LengthUnit::Cm);
     ///
@@ -295,10 +299,22 @@ impl<N: Normalize> Length<N> {
     ///
     /// This is usually used right after parsing a length value, as part of a validation step:
     ///
-    /// ```ignore
-    /// let mut parser = Parser::new(...);
+    /// ```
+    /// # use rsvg_internals::doctest_only::{Length,Horizontal,LengthUnit};
+    /// # use rsvg_internals::doctest_only::ElementError;
+    /// # use rsvg_internals::doctest_only::ParseValue;
+    /// # use markup5ever::{QualName, Prefix, Namespace, LocalName};
+    /// # let attr = QualName::new(
+    /// #     Some(Prefix::from("")),
+    /// #     Namespace::from(""),
+    /// #     LocalName::from(""),
+    /// # );
+    /// let length: Length<Horizontal> = attr.parse_and_validate("0", Length::check_nonnegative)?;
+    /// assert_eq!(length, Length::new(0.0, LengthUnit::Px));
     ///
-    /// let length = Length::<Horizontal>::parse(&mut parser).and_then(Length::check_nonnegative)?;
+    /// let result: Result<Length<Horizontal>, ElementError> = attr.parse_and_validate("-2", 
Length::check_nonnegative);
+    /// assert!(result.is_err());
+    /// # Ok::<(), ElementError>(())
     /// ```
     pub fn check_nonnegative(self) -> Result<Self, ValueErrorKind> {
         if self.length >= 0.0 {
diff --git a/rsvg_internals/src/lib.rs b/rsvg_internals/src/lib.rs
index 64bb94bd..24f24490 100644
--- a/rsvg_internals/src/lib.rs
+++ b/rsvg_internals/src/lib.rs
@@ -149,3 +149,15 @@ mod viewbox;
 mod xml;
 mod xml2;
 mod xml2_load;
+
+#[doc(hidden)]
+pub mod doctest_only {
+    pub use crate::aspect_ratio::AspectRatio;
+    pub use crate::error::AttributeResultExt;
+    pub use crate::error::ElementError;
+    pub use crate::error::ValueErrorKind;
+    pub use crate::href::is_href;
+    pub use crate::href::set_href;
+    pub use crate::length::{Both, Horizontal, Length, LengthUnit, Vertical};
+    pub use crate::parsers::ParseValue;
+}
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index 886bc214..840c5655 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -123,13 +123,21 @@ impl Parse for i32 {
 ///
 /// # Example
 ///
-/// ```ignore
+/// ```
+/// # #[macro_use] extern crate rsvg_internals;
+/// # use cssparser::{ParserInput, Parser};
+/// # fn main() -> Result<(), cssparser::BasicParseError<'static>> {
+/// # let mut input = ParserInput::new("true");
+/// # let mut parser = Parser::new(&mut input);
 /// let my_boolean = parse_identifiers!(
 ///     parser,
 ///     "true" => true,
 ///     "false" => false,
 /// )?;
+/// # Ok(())
+/// # }
 /// ```
+#[macro_export]
 macro_rules! parse_identifiers {
     ($parser:expr,
      $($str:expr => $val:expr,)+) => {
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index a7ac1ae9..16a708b3 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -136,7 +136,7 @@ impl ComputedValues {
 ///
 /// **NOTE:** If you get a compiler error similar to this:
 ///
-/// ```
+/// ```text
 /// 362 |         "mix-blend-mode"              => mix_blend_mode              : MixBlendMode,
 ///     |         ^^^^^^^^^^^^^^^^ no rules expected this token in macro call
 /// ```
diff --git a/rsvg_internals/src/property_macros.rs b/rsvg_internals/src/property_macros.rs
index abcd7b3e..5ad4185d 100644
--- a/rsvg_internals/src/property_macros.rs
+++ b/rsvg_internals/src/property_macros.rs
@@ -52,7 +52,7 @@ pub trait Property<T> {
 /// Many properties are just sets of identifiers and can be represented
 /// by simple enums.  In this case, you can use the following:
 ///
-/// ```ignore
+/// ```text
 /// make_property!(
 ///   ComputedValues,
 ///   StrokeLinejoin,
@@ -69,7 +69,7 @@ pub trait Property<T> {
 /// This generates a simple enum like the following, with implementations of [`Parse`],
 /// `Default`, and [`Property`].
 ///
-/// ```ignore
+/// ```
 /// pub enum StrokeLinejoin { Miter, Round, Bevel }
 /// ```
 ///
@@ -79,7 +79,7 @@ pub trait Property<T> {
 /// with a `cssparser::Color`, but their intial values are different.  In this case, the macro
 /// can generate a newtype around `cssparser::Color` for each case:
 ///
-/// ```ignore
+/// ```text
 /// make_property!(
 ///     ComputedValues,
 ///     FloodColor,


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