Skip to content

Commit

Permalink
fix: Fix broken parsing of datetime types
Browse files Browse the repository at this point in the history
  • Loading branch information
floers committed Jan 31, 2023
1 parent 6e538c4 commit 08c7bce
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 1 addition & 3 deletions src/parser/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ impl<'a> TryInto<Literal> for Value<'a> {
.map_err(|_| ())
.map(Literal::Bool)
} else if datatype_iri == well_known::xsd_dateTime_str {
serde_json::from_str(&lexical_form)
.map_err(|_| ())
.map(|n| Literal::DateTime(n))
Ok(Literal::DateTime(lexical_form.to_string()))
} else {
IRI::new(&datatype_iri)
.map_err(|_| ())
Expand Down
13 changes: 12 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,13 +572,14 @@ mod tests {
:Person rdfs:comment "3.14"^^xsd:float .
:Person rdfs:comment "true"^^xsd:boolean .
:Person rdfs:comment false .
:Person rdfs:comment "2023-01-31T08:39:54"^^xsd:dateTime .
"##;

harriet::TurtleDocument::parse_full(turtle).unwrap();
let o = Ontology::parse(turtle, Default::default()).unwrap();
assert_eq!(o.declarations().len(), 1);
assert_eq!(o.axioms().len(), 7);
assert_eq!(o.axioms().len(), 8);
assert_eq!(
o.axioms()[0],
AnnotationAssertion::new(
Expand Down Expand Up @@ -655,6 +656,16 @@ mod tests {
)
.into()
);
assert_eq!(
o.axioms()[7],
AnnotationAssertion::new(
well_known::rdfs_comment(),
IRI::new("http://test#Person").unwrap(),
LiteralOrIRI::Literal(Literal::DateTime("2023-01-31T08:39:54".into())),
vec![]
)
.into()
);
}

#[test]
Expand Down

0 comments on commit 08c7bce

Please sign in to comment.