OxRDF: fixes running doc tests with rdf-star disabled

Issue #794
pull/793/head
Tpt 7 months ago committed by Thomas Tanon
parent e48b268fc5
commit 6c7514d058
  1. 35
      lib/oxrdf/src/parser.rs

@ -126,15 +126,6 @@ impl FromStr for Term {
/// Term::from_str("\"ex\"").unwrap(),
/// Literal::new_simple_literal("ex").into()
/// );
/// assert_eq!(
/// Term::from_str("<< _:s <http://example.com/p> \"o\" >>").unwrap(),
/// Triple::new(
/// BlankNode::new("s").unwrap(),
/// NamedNode::new("http://example.com/p").unwrap(),
/// Literal::new_simple_literal("o")
/// )
/// .into()
/// );
/// ```
fn from_str(s: &str) -> Result<Self, Self::Err> {
let (term, left) = read_term(s, 0)?;
@ -365,7 +356,7 @@ fn read_term(s: &str, number_of_recursive_calls: usize) -> Result<(Term, &str),
Term::Literal(_) => {
return Err(TermParseError::msg(
"Literals are not allowed in subject position",
))
));
}
Term::Triple(s) => Subject::Triple(s),
},
@ -409,7 +400,7 @@ fn read_hexa_char(input: &mut Chars<'_>, len: usize) -> Result<char, TermParseEr
_ => {
return Err(TermParseError::msg(
"Unexpected character in a unicode escape",
))
));
}
}
} else {
@ -453,3 +444,25 @@ impl TermParseError {
Self(TermParseErrorKind::Msg(msg))
}
}
#[cfg(all(test, feature = "rdf-star"))]
mod tests {
use super::*;
#[test]
fn triple_term_parsing() {
assert_eq!(
Term::from_str("\"ex\"").unwrap(),
Literal::new_simple_literal("ex").into()
);
assert_eq!(
Term::from_str("<< _:s <http://example.com/p> \"o\" >>").unwrap(),
Triple::new(
BlankNode::new("s").unwrap(),
NamedNode::new("http://example.com/p").unwrap(),
Literal::new_simple_literal("o"),
)
.into()
);
}
}

Loading…
Cancel
Save