aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-05-26 22:48:26 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:01:35 +0200
commit253809af6f90cc86bba9e0510b524918c1c4d01e (patch)
tree12ead36018694f0141f6433a4e8714da6610b321
parent1d297b2741751c6a63cfffe5a51016d90c49db2c (diff)
Rdf-turtle tests:
Add several tests for parsers. The one for literal is not working yet, because the parser is not right. We don't really deal with whitespaces yet, and only included a few cases.
-rw-r--r--test/turtle/dune9
-rw-r--r--test/turtle/main.ml98
2 files changed, 107 insertions, 0 deletions
diff --git a/test/turtle/dune b/test/turtle/dune
new file mode 100644
index 0000000..fc96e4f
--- /dev/null
+++ b/test/turtle/dune
@@ -0,0 +1,9 @@
+
+(executables
+ (names main)
+ (libraries rdf_turtle rdf_alcotest
+ alcotest qcheck-alcotest))
+
+(rule
+ (alias runtest)
+ (action (run ./main.exe)))
diff --git a/test/turtle/main.ml b/test/turtle/main.ml
new file mode 100644
index 0000000..7f96981
--- /dev/null
+++ b/test/turtle/main.ml
@@ -0,0 +1,98 @@
+module Parser = Rdf_turtle.Parser
+module Turtle = Rdf_turtle.AST
+
+open Alcotest
+
+let parse p =
+ Angstrom.parse_string
+ ~consume:Angstrom.Consume.All
+ p
+
+let iriref_test_case =
+ test_case "iriref" `Quick
+ (fun () ->
+ check (result Rdf_alcotest.ast_iriref string)
+ "can parse"
+ (parse Parser.iriref "<http://one.example/subject1>")
+ (Result.ok @@ Turtle.Iriref.of_string "http://one.example/subject1")
+ )
+
+let language_test_case =
+ test_case "language" `Quick
+ (fun () ->
+ check (result Rdf_alcotest.ast_language string)
+ "can parse"
+ (parse Parser.language "@fr-be")
+ (Result.ok @@ Turtle.Language.of_string "fr-be")
+ )
+
+let prefixed_name_test_case =
+ test_case "prefixed_name" `Quick
+ (fun () ->
+ check (result Rdf_alcotest.ast_prefixed_name string)
+ "can parse"
+ (parse Parser.prefixed_name "rdf:first")
+ (Result.ok @@ Turtle.Prefixed_name.of_strings "rdf" "first")
+ )
+
+let prefixed_name_test_case2 =
+ test_case "prefixed_name2" `Quick
+ (fun () ->
+ check (result Rdf_alcotest.ast_prefixed_name string)
+ "can parse"
+ (parse Parser.prefixed_name ":first")
+ (Result.ok @@ Turtle.Prefixed_name.of_strings "" "first")
+ )
+
+
+let blank_node_test_case =
+ test_case "blank_node" `Quick
+ (fun () ->
+ check (result Rdf_alcotest.ast_blank_node string)
+ "can parse"
+ (parse Parser.blank_node "_:alice")
+ (Result.ok @@ Turtle.Blank_node.of_string "alice")
+ )
+
+let iri_test_case =
+ test_case "iri" `Quick
+ (fun () ->
+ check (result Rdf_alcotest.ast_iri string)
+ "can parse"
+ (parse Parser.iri "<http://one.example/subject1>")
+ (Result.ok @@ Turtle.Iri.of_iriref @@ Turtle.Iriref.of_string "http://one.example/subject1")
+ )
+
+let iri_test_case2 =
+ test_case "iri2" `Quick
+ (fun () ->
+ check (result Rdf_alcotest.ast_iri string)
+ "can parse"
+ (parse Parser.iri "p:subject3")
+ (Result.ok @@ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "p" "subject3")
+ )
+
+let literal_test_case =
+ test_case "literal" `Quick
+ (fun () ->
+ check (result Rdf_alcotest.ast_literal string)
+ "can parse"
+ (parse Parser.literal "\"That Seventies Show\"^^xsd:string")
+ (Result.ok @@ (Turtle.Literal.make
+ ("That Seventies Show")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")))
+ )
+
+let () =
+ Alcotest.run "Turtle" [
+ "Basic parsers", [
+ iriref_test_case;
+ language_test_case;
+ prefixed_name_test_case;
+ prefixed_name_test_case2;
+ blank_node_test_case;
+ iri_test_case;
+ iri_test_case2;
+ literal_test_case;
+ ]
+ ]