From 6c7514d0589838653a824f1f095edf8747db46a9 Mon Sep 17 00:00:00 2001 From: Tpt Date: Tue, 20 Feb 2024 20:40:53 +0100 Subject: [PATCH] OxRDF: fixes running doc tests with rdf-star disabled Issue #794 --- lib/oxrdf/src/parser.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/lib/oxrdf/src/parser.rs b/lib/oxrdf/src/parser.rs index bcadd1ad..8986c352 100644 --- a/lib/oxrdf/src/parser.rs +++ b/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 \"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 { 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 { 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 \"o\" >>").unwrap(), + Triple::new( + BlankNode::new("s").unwrap(), + NamedNode::new("http://example.com/p").unwrap(), + Literal::new_simple_literal("o"), + ) + .into() + ); + } +}