aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-06-08 12:49:16 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:02:45 +0200
commitbbb98e4944c3c0a2438aff3c6feae93f749880c9 (patch)
treeb2208159a8cf4d63ba88069cdac54bef10e9c8a2 /test
parent87ac72ad5621c0a6358ee486e4610c82ece9fb30 (diff)
Rdf turtle test:
add remaining tests. All the parsers have tests now, and they work. It would be good to include more tests, e.g. all the examples from the w3 specifications. Literals cannot be integers, that remains a todo (so all those examples won't work).
Diffstat (limited to 'test')
-rw-r--r--test/alcotest/rdf_alcotest.ml4
-rw-r--r--test/alcotest/rdf_alcotest.mli2
-rw-r--r--test/turtle/main.ml119
3 files changed, 117 insertions, 8 deletions
diff --git a/test/alcotest/rdf_alcotest.ml b/test/alcotest/rdf_alcotest.ml
index 88e9831..973072b 100644
--- a/test/alcotest/rdf_alcotest.ml
+++ b/test/alcotest/rdf_alcotest.ml
@@ -55,8 +55,8 @@ let ast_collection =
let ast_subject =
Alcotest.testable Rdf_turtle.AST.subject_pp Rdf_turtle.AST.subject_equal
-let ast_bnodeps =
- Alcotest.testable Rdf_turtle.AST.bnodeps_pp Rdf_turtle.AST.bnodeps_equal
+let ast_bnodps =
+ Alcotest.testable Rdf_turtle.AST.bnodps_pp Rdf_turtle.AST.bnodps_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 56a0e57..d0d6395 100644
--- a/test/alcotest/rdf_alcotest.mli
+++ b/test/alcotest/rdf_alcotest.mli
@@ -38,7 +38,7 @@ val ast_collection : Rdf_turtle.AST.collection Alcotest.testable
val ast_subject : Rdf_turtle.AST.subject Alcotest.testable
-val ast_bnodeps : Rdf_turtle.AST.bnodeps Alcotest.testable
+val ast_bnodps : Rdf_turtle.AST.bnodps Alcotest.testable
val ast_predobjs : Rdf_turtle.AST.predobjs Alcotest.testable
diff --git a/test/turtle/main.ml b/test/turtle/main.ml
index e299132..3c70f28 100644
--- a/test/turtle/main.ml
+++ b/test/turtle/main.ml
@@ -181,7 +181,7 @@ let object_test_case =
(Result.ok @@ v))
cases)
-let bnodeps_test_case =
+let bnodps_test_case =
let cases = [
"[ foaf:name \"Bob\" ]",
BnodPs ([ Predicate.of_iri @@ Iri.of_prefixed_name @@ Prefixed_name.of_strings "foaf" "name",
@@ -197,13 +197,13 @@ let bnodeps_test_case =
);
]
in
- test_case "bnodeps" `Quick
+ test_case "bnodps" `Quick
(fun () ->
List.iter
(fun (enc, v) ->
- check (result Rdf_alcotest.ast_bnodeps string)
+ check (result Rdf_alcotest.ast_bnodps string)
"can parse"
- (parse Parser.bnodeps enc)
+ (parse Parser.bnodps enc)
(Result.ok @@ v))
cases)
@@ -294,10 +294,44 @@ let subject_test_case =
(Result.ok @@ v))
cases)
+let triples_test_case =
+ let cases = [
+ "<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin>",
+ Triples.of_subject_and_predobjs
+ (Sub_iri (Iri.of_iriref (Iriref.of_string @@ "http://example.org/#spiderman")))
+ ([ Predicate.of_iri @@ Iri.of_iriref "http://www.perceive.net/schemas/relationship/enemyOf",
+ [ Obj_iri (Iri.of_iriref "http://example.org/#green-goblin"); ] ; ])
+ ;
+ "[ foaf:name \"Bob\" ]",
+ Triples.of_bnodps (
+ BnodPs ([ Predicate.of_iri @@ Iri.of_prefixed_name @@ Prefixed_name.of_strings "foaf" "name",
+ [ Obj_literal ( Literal.make
+ ("Bob")
+ (Iri.of_prefixed_name @@ Prefixed_name.of_strings "xsd" "string"))
+ ]
+ ]))
+ ;
+ ] in
+ test_case "triples" `Quick
+ (fun () ->
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_triples string)
+ "can parse"
+ (parse Parser.triples enc)
+ (Result.ok @@ v))
+ cases)
+
let directive_test_case =
let cases = [
"@base <http://one.example/> .",
Directive.of_iriref (Iriref.of_string "http://one.example/")
+ ;
+ "@prefix foaf: <http://xmlns.com/foaf/0.1/> .",
+ Directive.of_string_and_iriref
+ "foaf"
+ (Iriref.of_string "http://xmlns.com/foaf/0.1/")
+ ;
] in
test_case "directive" `Quick
(fun () ->
@@ -309,6 +343,78 @@ let directive_test_case =
(Result.ok @@ v))
cases)
+let statement_test_case =
+ let cases = [
+ "@prefix foaf: <http://xmlns.com/foaf/0.1/> .",
+ Statement.of_directive (
+ Directive.of_string_and_iriref
+ "foaf"
+ (Iriref.of_string "http://xmlns.com/foaf/0.1/"))
+ ;
+ "<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> .",
+ Statement.of_triples (
+ Triples.of_subject_and_predobjs
+ (Sub_iri (Iri.of_iriref (Iriref.of_string @@ "http://example.org/#spiderman")))
+ ([ Predicate.of_iri @@ Iri.of_iriref "http://www.perceive.net/schemas/relationship/enemyOf",
+ [ Obj_iri (Iri.of_iriref "http://example.org/#green-goblin"); ] ; ]))
+ ;
+ ] in
+ test_case "statement" `Quick
+ (fun () ->
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_statement string)
+ "can parse"
+ (parse Parser.statement enc)
+ (Result.ok @@ v))
+ cases)
+
+let turtle_test_case =
+ let cases = [
+ "@prefix foaf: <http://xmlns.com/foaf/0.1/> .",
+ Turtle.of_statement_lst (
+ [Statement.of_directive (
+ Directive.of_string_and_iriref
+ "foaf"
+ (Iriref.of_string "http://xmlns.com/foaf/0.1/"))])
+ ;
+ "<http://example.org/#spiderman> <http://www.perceive.net/schemas/relationship/enemyOf> <http://example.org/#green-goblin> .",
+ Turtle.of_statement_lst (
+ [Statement.of_triples (
+ Triples.of_subject_and_predobjs
+ (Sub_iri (Iri.of_iriref (Iriref.of_string @@ "http://example.org/#spiderman")))
+ ([ Predicate.of_iri @@ Iri.of_iriref "http://www.perceive.net/schemas/relationship/enemyOf",
+ [ Obj_iri (Iri.of_iriref "http://example.org/#green-goblin"); ] ; ]))])
+ ;
+ "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . @prefix show: <http://example.org/vocab/show/> . @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .",
+ Turtle.of_statement_lst (
+ [ Statement.of_directive (
+ Directive.of_string_and_iriref
+ "rdfs"
+ (Iriref.of_string "http://www.w3.org/2000/01/rdf-schema#"))
+ ;
+ Statement.of_directive (
+ Directive.of_string_and_iriref
+ "show"
+ (Iriref.of_string "http://example.org/vocab/show/"))
+ ;
+ Statement.of_directive (
+ Directive.of_string_and_iriref
+ "xsd"
+ (Iriref.of_string "http://www.w3.org/2001/XMLSchema#"))
+ ])
+ ;
+ ] in
+ test_case "turtle" `Quick
+ (fun () ->
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_turtle string)
+ "can parse"
+ (parse Parser.turtle enc)
+ (Result.ok @@ v))
+ cases)
+
let () =
Alcotest.run "Turtle" [
"Basic parsers", [
@@ -320,9 +426,12 @@ let () =
literal_test_case;
predicate_test_case;
object_test_case;
- bnodeps_test_case;
+ bnodps_test_case;
predobjs_test_case;
subject_test_case;
+ triples_test_case;
directive_test_case;
+ statement_test_case;
+ turtle_test_case;
]
]