From 1ac9ef417eb9453da44736e8b4634006a2e4b773 Mon Sep 17 00:00:00 2001 From: Nordine Bittich Date: Fri, 22 Nov 2024 08:42:18 +0100 Subject: [PATCH] fix ns type predicate --- Cargo.toml | 2 +- src/triple_common_parser.rs | 7 ++++--- src/turtle/turtle_doc.rs | 12 ++++++++++++ tests/modelC.ttl | 37 +++++++++++++++++++++++++++++++++++ tests/modelF.ttl | 39 +++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 tests/modelC.ttl create mode 100644 tests/modelF.ttl diff --git a/Cargo.toml b/Cargo.toml index fd64aa6..350c502 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tortank" -version = "0.22.0" +version = "0.23.0" edition = "2021" authors = ["Nordine Bittich "] description = "Turtle/N3 parser" diff --git a/src/triple_common_parser.rs b/src/triple_common_parser.rs index fb2c782..223c9d5 100644 --- a/src/triple_common_parser.rs +++ b/src/triple_common_parser.rs @@ -285,9 +285,10 @@ pub(crate) mod triple { ) } pub(crate) fn ns_type(s: &str) -> ParserResult { - map(terminated(char('a'), multispace1), |_| { - Iri::Enclosed(NS_TYPE) - })(s) + map( + preceded(multispace0, terminated(char('a'), multispace1)), + |_| Iri::Enclosed(NS_TYPE), + )(s) } pub(crate) fn predicate_list<'a, F1, F2, F3, F4, F5, T>( subject_extractor: F1, diff --git a/src/turtle/turtle_doc.rs b/src/turtle/turtle_doc.rs index 7626167..179de76 100644 --- a/src/turtle/turtle_doc.rs +++ b/src/turtle/turtle_doc.rs @@ -1188,6 +1188,18 @@ mod test { assert_eq!(9, triples.len()); } + #[test] + fn turtle_doc_could_not_parse_completely() { + let mut buf_c = String::new(); + let mut buf_f = String::new(); + let turtle_c = TurtleDoc::from_file("tests/modelC.ttl", None, &mut buf_c).unwrap(); + let turtle_f = TurtleDoc::from_file("tests/modelF.ttl", None, &mut buf_f).unwrap(); + + assert!(!turtle_c.to_string().is_empty()); + assert_eq!(39, turtle_c.len()); + assert_eq!(0, turtle_c.difference(&turtle_f).unwrap().len()); + } + #[test] fn turtle_doc_diff_buggy() { let mut buf_a = String::new(); diff --git a/tests/modelC.ttl b/tests/modelC.ttl new file mode 100644 index 0000000..ffff34a --- /dev/null +++ b/tests/modelC.ttl @@ -0,0 +1,37 @@ + + a , ; + <./1>; + ; + . +<./1> a . + . + ; + 1; + ; + a ; + "673E2195C7E1A9B9F3B8666A"; + ; + "2024-11-22T07:12:35.573Z"^^. + . + ; + ; + a ; + "673E2195C7E1A9B9F3B8666B"; + ; + "2024-11-22T07:12:35.574Z"^^. + . + ; + a , ; + "f9312556b1bdfbb278ec04033417152abbb254466df0069ff1894d0ea7a55482"; + ; + "A11"; + ; + ; + ; + "Uitweg op een kaai of een oever."; + ; + , ; + ; + ; + ; + "2024-11-22T07:12:35.575Z"^^. diff --git a/tests/modelF.ttl b/tests/modelF.ttl new file mode 100644 index 0000000..7648482 --- /dev/null +++ b/tests/modelF.ttl @@ -0,0 +1,39 @@ + . + . + <./1>. + . + . +<./1> . + . + . + "1"^^. + . + . + "673E2195C7E1A9B9F3B8666A"^^. + . + "2024-11-22T07:12:35.573Z"^^. + . + . + . + . + "673E2195C7E1A9B9F3B8666B"^^. + . + "2024-11-22T07:12:35.574Z"^^. + . + . + . + . + "f9312556b1bdfbb278ec04033417152abbb254466df0069ff1894d0ea7a55482"^^. + . + "A11"^^. + . + . + . + "Uitweg op een kaai of een oever."^^. + . + . + . + . + . + . + "2024-11-22T07:12:35.575Z"^^. \ No newline at end of file