aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-06-08 09:34:59 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:02:45 +0200
commit6fd93f6259c4723471aacdaebec627d60b710894 (patch)
tree9ef65c67195860aad56d0adff6c0af5b9d2f13d8
parent933fde01c878fbe20952c05ad700fecd0c0286ef (diff)
Rdf turtle tests
add subject test case (does not work yet).
-rw-r--r--lib/turtle/rdf_turtle.ml8
-rw-r--r--test/turtle/main.ml136
2 files changed, 89 insertions, 55 deletions
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
index c9512f0..644b33f 100644
--- a/lib/turtle/rdf_turtle.ml
+++ b/lib/turtle/rdf_turtle.ml
@@ -463,13 +463,13 @@ module Parser = struct
collection
);
(lift
- (fun iri -> AST.Sub_iri iri)
- iri
- );
- (lift
(fun blank_node -> AST.Sub_blank_node blank_node)
blank_node
);
+ (lift
+ (fun iri -> AST.Sub_iri iri)
+ iri
+ );
]
let bnodeps_ predobjs =
diff --git a/test/turtle/main.ml b/test/turtle/main.ml
index d70ca4e..fa75377 100644
--- a/test/turtle/main.ml
+++ b/test/turtle/main.ml
@@ -1,6 +1,7 @@
module Parser = Rdf_turtle.Parser
module Turtle = Rdf_turtle.AST
+open Turtle
open Alcotest
let parse p =
@@ -11,7 +12,7 @@ let parse p =
let iriref_test_case =
let cases = [
"<http://one.example/subject1>",
- Turtle.Iriref.of_string "http://one.example/subject1" ;
+ Iriref.of_string "http://one.example/subject1" ;
] in
test_case "iriref" `Quick
(fun () ->
@@ -29,15 +30,15 @@ let language_test_case =
check (result Rdf_alcotest.ast_language string)
"can parse"
(parse Parser.language "@fr-be")
- (Result.ok @@ Turtle.Language.of_string "fr-be")
+ (Result.ok @@ Language.of_string "fr-be")
)
let prefixed_name_test_case =
let cases = [
"rdf:first",
- Turtle.Prefixed_name.of_strings "rdf" "first" ;
+ Prefixed_name.of_strings "rdf" "first" ;
":first",
- Turtle.Prefixed_name.of_strings "" "first" ;
+ Prefixed_name.of_strings "" "first" ;
] in
test_case "prefixed_name" `Quick
(fun () ->
@@ -55,15 +56,15 @@ let blank_node_test_case =
check (result Rdf_alcotest.ast_blank_node string)
"can parse"
(parse Parser.blank_node "_:alice")
- (Result.ok @@ Turtle.Blank_node.of_string "alice")
+ (Result.ok @@ Blank_node.of_string "alice")
)
let iri_test_case =
let cases = [
"<http://one.example/subject1>",
- Turtle.Iri.of_iriref @@ Turtle.Iriref.of_string "http://one.example/subject1" ;
+ Iri.of_iriref @@ Iriref.of_string "http://one.example/subject1" ;
"p:subject3",
- Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "p" "subject3" ;
+ Iri.of_prefixed_name @@ Prefixed_name.of_strings "p" "subject3" ;
] in
test_case "iri" `Quick
(fun () ->
@@ -78,21 +79,21 @@ let iri_test_case =
let literal_test_case =
let cases = [
"\"That Seventies Show\"^^xsd:string",
- Turtle.Literal.make
+ Literal.make
("That Seventies Show")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string") ;
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string") ;
"\"That Seventies Show\"^^<http://www.w3.org/2001/XMLSchema#string>",
- Turtle.Literal.make
+ Literal.make
("That Seventies Show")
- (Turtle.Iri.of_iriref @@ Turtle.Iriref.of_string "http://www.w3.org/2001/XMLSchema#string");
+ (Iri.of_iriref @@ Iriref.of_string "http://www.w3.org/2001/XMLSchema#string");
"\"That Seventies Show\"",
- Turtle.Literal.make
+ Literal.make
("That Seventies Show")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string") ;
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string") ;
"\"Cette Série des Années Septantei\"@fr-be",
- Turtle.Literal.make
+ Literal.make
"Cette Série des Années Septantei"
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string")
~language:"fr-be" ;
] in
test_case "literal" `Quick
@@ -108,9 +109,9 @@ let literal_test_case =
let predicate_test_case =
let cases = [
"<http://one.example/subject1>",
- Turtle.Predicate.of_iri @@ Turtle.Iri.of_iriref @@ Turtle.Iriref.of_string "http://one.example/subject1" ;
+ Predicate.of_iri @@ Iri.of_iriref @@ Iriref.of_string "http://one.example/subject1" ;
"p:subject3",
- Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "p" "subject3" ;
+ Predicate.of_iri @@ Iri.of_prefixed_name @@ Prefixed_name.of_strings "p" "subject3" ;
] in
test_case "predicate" `Quick
(fun () ->
@@ -126,42 +127,42 @@ let object_test_case =
let cases = [
(* Literal *)
"\"That Seventies Show\"^^xsd:string",
- Turtle.Literal.make
+ Literal.make
("That Seventies Show")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")
- |> (fun lit -> Turtle.Obj_literal lit) ;
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string")
+ |> (fun lit -> Obj_literal lit) ;
(* Iri *)
"xsd:string",
- Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"
- |> (fun iri -> Turtle.Obj_iri iri) ;
+ Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string"
+ |> (fun iri -> Obj_iri iri) ;
(* Blank_node *)
"_:string",
- Turtle.Obj_blank_node (Turtle.Blank_node.of_string "string") ;
+ Obj_blank_node (Blank_node.of_string "string") ;
(* Blank_node *)
"_:string",
- Turtle.Obj_blank_node (Turtle.Blank_node.of_string "string") ;
+ Obj_blank_node (Blank_node.of_string "string") ;
(* Collection *)
"( \"apple\" \"banana\" )",
- Turtle.Obj_coll (
- Turtle.Collection (
+ Obj_coll (
+ Collection (
[
- Turtle.Obj_literal (
- Turtle.Literal.make
+ Obj_literal (
+ Literal.make
("apple")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")) ;
- Turtle.Obj_literal (
- Turtle.Literal.make
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string")) ;
+ Obj_literal (
+ Literal.make
("banana")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")) ;
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string")) ;
]
)
) ;
(* BNodePlist *)
"[ foaf:name \"Bob\" ]",
- Turtle.Obj_BnodPs (Turtle.BNodePs ([ Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "foaf" "name",
- [ Turtle.Obj_literal ( Turtle.Literal.make
+ Obj_BnodPs (BNodePs ([ Predicate.of_iri @@ Iri.of_prefixed_name @@ Prefixed_name.of_strings "foaf" "name",
+ [ Obj_literal ( Literal.make
("Bob")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"))
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string"))
]
]))
;
@@ -179,10 +180,10 @@ let object_test_case =
let bnodeps_test_case =
let cases = [
"[ foaf:name \"Bob\" ]",
- Turtle.BNodePs ([ Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "foaf" "name",
- [ Turtle.Obj_literal ( Turtle.Literal.make
+ BNodePs ([ Predicate.of_iri @@ Iri.of_prefixed_name @@ Prefixed_name.of_strings "foaf" "name",
+ [ Obj_literal ( Literal.make
("Bob")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"))
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string"))
]
])
;
@@ -200,29 +201,29 @@ let bnodeps_test_case =
let predobjs_test_case =
let cases = [
" foaf:name \"Bob\" ",
- [ Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "foaf" "name",
- [ Turtle.Obj_literal ( Turtle.Literal.make
+ [ Predicate.of_iri @@ Iri.of_prefixed_name @@ Prefixed_name.of_strings "foaf" "name",
+ [ Obj_literal ( Literal.make
("Bob")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"))
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string"))
]
]
;
"rel:enemyOf <#green-goblin> ;
a foaf:Person ;
foaf:name \"Spiderman\", \"Человек-паук\"@ru",
- [ Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "rel" "enemyOf",
- [ Turtle.Obj_iri ( Turtle.Iri.of_iriref (Turtle.Iriref.of_string "#green-goblin"));]
+ [ Predicate.of_iri @@ Iri.of_prefixed_name @@ Prefixed_name.of_strings "rel" "enemyOf",
+ [ Obj_iri ( Iri.of_iriref (Iriref.of_string "#green-goblin"));]
;
- Turtle.Predicate.a,
- [ Turtle.Obj_iri (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "foaf" "Person");]
+ Predicate.a,
+ [ Obj_iri (Iri.of_prefixed_name @@ Prefixed_name.of_strings "foaf" "Person");]
;
- Turtle.Predicate.of_iri @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "foaf" "name",
- [ Turtle.Obj_literal ( Turtle.Literal.make
+ Predicate.of_iri @@ Iri.of_prefixed_name @@ Prefixed_name.of_strings "foaf" "name",
+ [ Obj_literal ( Literal.make
("Spiderman")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string"));
- Turtle.Obj_literal ( Turtle.Literal.make
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string"));
+ Obj_literal ( Literal.make
("Человек-паук")
- (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string")
~language:"ru");
]
]
@@ -237,10 +238,42 @@ let predobjs_test_case =
(Result.ok @@ v))
cases)
+let subject_test_case =
+ let cases = [
+ (* Iri *)
+ "<http://one.example/>",
+ Sub_iri (Iri.of_iriref (Iriref.of_string "http://one.example/"));
+ (* Collection *)
+ "(1 [:p :q] ( 2 ) )",
+ Sub_coll (
+ Collection (
+ [
+ Obj_literal (
+ Literal.make
+ ("apple")
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string")) ;
+ Obj_literal (
+ Literal.make
+ ("banana")
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string")) ;
+ ]
+ )
+ ) ;
+ ] in
+ test_case "subject" `Quick
+ (fun () ->
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_subject string)
+ "can parse"
+ (parse Parser.subject enc)
+ (Result.ok @@ v))
+ cases)
+
let directive_test_case =
let cases = [
"@base <http://one.example/> .",
- Turtle.Directive.of_iriref (Turtle.Iriref.of_string "http://one.example/")
+ Directive.of_iriref (Iriref.of_string "http://one.example/")
] in
test_case "directive" `Quick
(fun () ->
@@ -265,6 +298,7 @@ let () =
object_test_case;
bnodeps_test_case;
predobjs_test_case;
+ subject_test_case;
directive_test_case;
]
]