[librsvg] Document Reference::parse()
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Document Reference::parse()
- Date: Thu, 29 Nov 2018 18:04:59 +0000 (UTC)
commit da33223b97dbf670b91808db6d185aea93a43cea
Author: Federico Mena Quintero <federico gnome org>
Date: Wed Nov 28 12:36:46 2018 -0600
Document Reference::parse()
And some stylistic fixes to the tests
rsvg_internals/src/defs.rs | 23 ++++++++++++++++-------
1 file changed, 16 insertions(+), 7 deletions(-)
---
diff --git a/rsvg_internals/src/defs.rs b/rsvg_internals/src/defs.rs
index adecfde7..dbd48f81 100644
--- a/rsvg_internals/src/defs.rs
+++ b/rsvg_internals/src/defs.rs
@@ -101,6 +101,12 @@ pub enum ReferenceError {
}
impl Reference {
+ /// Parses an href into a Reference, or returns an error
+ ///
+ /// An href can come from an `xlink:href` attribute in an SVG
+ /// element. This function determines if the provided href is a
+ /// plain absolute or relative URL ("`foo.png`"), or one with a
+ /// fragment identifier ("`foo.svg#bar`").
pub fn parse(href: &str) -> Result<Reference, ReferenceError> {
let (uri, fragment) = match href.rfind('#') {
None => (Some(href), None),
@@ -153,20 +159,23 @@ mod tests {
use super::*;
#[test]
- fn reference_kinds() {
- assert_eq!(Reference::parse("uri"), Ok(Reference::PlainUri("uri".to_string())));
+ fn parse() {
+ assert_eq!(
+ Reference::parse("uri").unwrap(),
+ Reference::PlainUri("uri".to_string())
+ );
assert_eq!(
- Reference::parse("#fragment"),
- Ok(Reference::FragmentId("fragment".to_string()))
+ Reference::parse("#fragment").unwrap(),
+ Reference::FragmentId("fragment".to_string())
);
assert_eq!(
- Reference::parse("uri#fragment"),
- Ok(Reference::UriWithFragmentId("uri".to_string(), "fragment".to_string()))
+ Reference::parse("uri#fragment").unwrap(),
+ Reference::UriWithFragmentId("uri".to_string(), "fragment".to_string())
);
}
#[test]
- fn reference_errors() {
+ fn parse_errors() {
assert_eq!(Reference::parse(""), Err(ReferenceError::ParseError));
assert_eq!(Reference::parse("#"), Err(ReferenceError::ParseError));
assert_eq!(Reference::parse("uri#"), Err(ReferenceError::ParseError));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]