aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-05-31 15:45:12 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:02:44 +0200
commit157927df5907a085c238169b85b0c489384e6bfd (patch)
treed235ce4fb445b67f6c2ce37c6655a774aeb9369f
parent69ae7300da09315ffec8b3699b032dbfc3863e4f (diff)
Rdf turtle tests
add some more tests. Improve parsers.
-rw-r--r--lib/turtle/rdf_turtle.ml14
-rw-r--r--lib/turtle/rdf_turtle.mli8
-rw-r--r--test/alcotest/rdf_alcotest.ml15
-rw-r--r--test/alcotest/rdf_alcotest.mli10
-rw-r--r--test/turtle/main.ml46
5 files changed, 84 insertions, 9 deletions
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
index 20360f0..d280985 100644
--- a/lib/turtle/rdf_turtle.ml
+++ b/lib/turtle/rdf_turtle.ml
@@ -334,19 +334,23 @@ module Parser = struct
let predicate =
lift AST.Predicate.of_iri iri
+(* TODO if you change the order of literal and iri, the tests won't work anymore. *)
+(* This is because the prefixed name parser accepts, for example: *)
+(* "\"That Seventies Show\"^^xsd:string" *)
+(* Same thing for blank_node! *)
let object_ collection bnodep =
choice [
(lift
- (fun iri -> AST.Obj_iri iri)
- iri);
+ (fun literal -> AST.Obj_literal literal)
+ literal
+ );
(lift
(fun blank_node -> AST.Obj_blank_node blank_node)
blank_node
);
(lift
- (fun literal -> AST.Obj_literal literal)
- literal
- );
+ (fun iri -> AST.Obj_iri iri)
+ iri);
(lift
(fun collection -> AST.Obj_coll collection)
collection
diff --git a/lib/turtle/rdf_turtle.mli b/lib/turtle/rdf_turtle.mli
index 3be6a58..5573c3a 100644
--- a/lib/turtle/rdf_turtle.mli
+++ b/lib/turtle/rdf_turtle.mli
@@ -140,10 +140,6 @@ module AST : sig
and bnodep = BNodeP of predobjs
and predobjs = (Predicate.t * object' list) list
- type triples =
- SubjPredObjs of subject * predobjs
- | BNodePs of (bnodep list)
-
val object_equal : object' -> object' -> bool
val collection_equal : collection -> collection -> bool
val subject_equal : subject -> subject -> bool
@@ -165,6 +161,10 @@ module AST : sig
val predobjs_pp : predobjs Fmt.t
[@@ocaml.toplevel_printer]
+ type triples =
+ SubjPredObjs of subject * predobjs
+ | BNodePs of (bnodep list)
+
type directive = PrefixID of string * Iriref.t | Base of Iriref.t
type statement = Directive of directive | Triples of triples
diff --git a/test/alcotest/rdf_alcotest.ml b/test/alcotest/rdf_alcotest.ml
index 7144f27..8d8ecc1 100644
--- a/test/alcotest/rdf_alcotest.ml
+++ b/test/alcotest/rdf_alcotest.ml
@@ -45,3 +45,18 @@ let ast_literal =
let ast_predicate =
Alcotest.testable Rdf_turtle.AST.Predicate.pp Rdf_turtle.AST.Predicate.equal
+
+let ast_object =
+ Alcotest.testable Rdf_turtle.AST.object_pp Rdf_turtle.AST.object_equal
+
+let ast_collection =
+ Alcotest.testable Rdf_turtle.AST.collection_pp Rdf_turtle.AST.collection_equal
+
+let ast_subject =
+ Alcotest.testable Rdf_turtle.AST.subject_pp Rdf_turtle.AST.subject_equal
+
+let ast_bnodep =
+ Alcotest.testable Rdf_turtle.AST.bnodep_pp Rdf_turtle.AST.bnodep_equal
+
+let ast_predobjs =
+ Alcotest.testable Rdf_turtle.AST.predobjs_pp Rdf_turtle.AST.predobjs_equal
diff --git a/test/alcotest/rdf_alcotest.mli b/test/alcotest/rdf_alcotest.mli
index 144c5ec..2514165 100644
--- a/test/alcotest/rdf_alcotest.mli
+++ b/test/alcotest/rdf_alcotest.mli
@@ -31,3 +31,13 @@ val ast_iri: Rdf_turtle.AST.Iri.t Alcotest.testable
val ast_literal : Rdf_turtle.AST.Literal.t Alcotest.testable
val ast_predicate : Rdf_turtle.AST.Predicate.t Alcotest.testable
+
+val ast_object : Rdf_turtle.AST.object' Alcotest.testable
+
+val ast_collection : Rdf_turtle.AST.collection Alcotest.testable
+
+val ast_subject : Rdf_turtle.AST.subject Alcotest.testable
+
+val ast_bnodep : Rdf_turtle.AST.bnodep Alcotest.testable
+
+val ast_predobjs : Rdf_turtle.AST.predobjs Alcotest.testable
diff --git a/test/turtle/main.ml b/test/turtle/main.ml
index e6ee3c3..e5c3a59 100644
--- a/test/turtle/main.ml
+++ b/test/turtle/main.ml
@@ -105,6 +105,51 @@ let literal_test_case =
(Result.ok @@ v))
cases)
+let object_test_case =
+ let cases = [
+ (* Literal *)
+ "\"That Seventies Show\"^^xsd:string",
+ Turtle.Literal.make
+ ("That Seventies Show")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")
+ |> (fun lit -> Turtle.Obj_literal lit) ;
+ (* Iri *)
+ "xsd:string",
+ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"
+ |> (fun iri -> Turtle.Obj_iri iri) ;
+ (* Blank_node *)
+ "_:string",
+ Turtle.Obj_blank_node (Turtle.Blank_node.of_string "string") ;
+ (* Blank_node *)
+ "_:string",
+ Turtle.Obj_blank_node (Turtle.Blank_node.of_string "string") ;
+ (* Collection *)
+ "( \"apple\" \"banana\" )",
+ Turtle.Obj_coll (
+ Turtle.Collection (
+ [
+ Turtle.Obj_literal (
+ Turtle.Literal.make
+ ("apple")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")) ;
+ Turtle.Obj_literal (
+ Turtle.Literal.make
+ ("apple")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")) ;
+ ]
+ )
+ ) ;
+ ] in
+ test_case "object" `Quick
+ (fun () ->
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_object string)
+ "can parse"
+ (parse Parser.object' enc)
+ (Result.ok @@ v))
+ cases)
+
let () =
Alcotest.run "Turtle" [
"Basic parsers", [
@@ -114,5 +159,6 @@ let () =
blank_node_test_case;
iri_test_case;
literal_test_case;
+ object_test_case;
]
]