aboutsummaryrefslogtreecommitdiff
path: root/test/turtle/main.ml
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-05-27 22:48:58 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:02:44 +0200
commit69ae7300da09315ffec8b3699b032dbfc3863e4f (patch)
treed6f83cbae937780c6ac193f5d1cc878a93dcb633 /test/turtle/main.ml
parent8c9bc8478842a393f85259f1350bf04711c190fa (diff)
Rdf_turtle:
improve tests for parsers, and include more. Add equality functions and pp functions for more types, especially the recursive ones. Not polished at all (a lot of copy paste), but dune build works (that's a start I guess).
Diffstat (limited to 'test/turtle/main.ml')
-rw-r--r--test/turtle/main.ml106
1 files changed, 63 insertions, 43 deletions
diff --git a/test/turtle/main.ml b/test/turtle/main.ml
index 7f96981..e6ee3c3 100644
--- a/test/turtle/main.ml
+++ b/test/turtle/main.ml
@@ -9,13 +9,19 @@ let parse p =
p
let iriref_test_case =
+ let cases = [
+ "<http://one.example/subject1>",
+ Turtle.Iriref.of_string "http://one.example/subject1" ;
+ ] in
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")
- )
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_iriref string)
+ "can parse"
+ (parse Parser.iriref enc)
+ (Result.ok @@ v))
+ cases)
let language_test_case =
test_case "language" `Quick
@@ -27,23 +33,21 @@ let language_test_case =
)
let prefixed_name_test_case =
+ let cases = [
+ "rdf:first",
+ Turtle.Prefixed_name.of_strings "rdf" "first" ;
+ ":first",
+ Turtle.Prefixed_name.of_strings "" "first" ;
+ ] in
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")
- )
-
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_prefixed_name string)
+ "can parse"
+ (parse Parser.prefixed_name enc)
+ (Result.ok @@ v))
+ cases)
let blank_node_test_case =
test_case "blank_node" `Quick
@@ -55,33 +59,51 @@ let blank_node_test_case =
)
let iri_test_case =
+ let cases = [
+ "<http://one.example/subject1>",
+ Turtle.Iri.of_iriref @@ Turtle.Iriref.of_string "http://one.example/subject1" ;
+ "p:subject3",
+ Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "p" "subject3" ;
+ ] in
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")
- )
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_iri string)
+ "can parse"
+ (parse Parser.iri enc)
+ (Result.ok @@ v))
+ cases)
let literal_test_case =
+ let cases = [
+ "\"That Seventies Show\"^^xsd:string",
+ Turtle.Literal.make
+ ("That Seventies Show")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string") ;
+ "\"That Seventies Show\"^^<http://www.w3.org/2001/XMLSchema#string>",
+ Turtle.Literal.make
+ ("That Seventies Show")
+ (Turtle.Iri.of_iriref @@ Turtle.Iriref.of_string "http://www.w3.org/2001/XMLSchema#string");
+ "\"That Seventies Show\"",
+ Turtle.Literal.make
+ ("That Seventies Show")
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string") ;
+ "\"Cette Série des Années Septantei\"@fr-be",
+ Turtle.Literal.make
+ "Cette Série des Années Septantei"
+ (Turtle.Iri.of_prefixed_name @@ Turtle.Prefixed_name.of_strings "xsd" "string")
+ ~language:"fr-be" ;
+ ] in
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")))
- )
+ List.iter
+ (fun (enc, v) ->
+ check (result Rdf_alcotest.ast_literal string)
+ "can parse"
+ (parse Parser.literal enc)
+ (Result.ok @@ v))
+ cases)
let () =
Alcotest.run "Turtle" [
@@ -89,10 +111,8 @@ let () =
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;
]
]