aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorarie <arie@alleycat.cc>2021-05-27 12:10:05 +0200
committerarie <arie@alleycat.cc>2021-06-28 21:02:39 +0200
commit8c9bc8478842a393f85259f1350bf04711c190fa (patch)
tree2cb8bf74dd07fbd38e8353075cc0e20c3136c146
parent253809af6f90cc86bba9e0510b524918c1c4d01e (diff)
Rdf_turtle test
forgot to add these files in the last commit. See previous commit for comments.
-rw-r--r--lib/turtle/rdf_turtle.ml101
-rw-r--r--lib/turtle/rdf_turtle.mli38
-rw-r--r--test/alcotest/dune3
-rw-r--r--test/alcotest/rdf_alcotest.ml21
-rw-r--r--test/alcotest/rdf_alcotest.mli14
5 files changed, 173 insertions, 4 deletions
diff --git a/lib/turtle/rdf_turtle.ml b/lib/turtle/rdf_turtle.ml
index df468b3..af55784 100644
--- a/lib/turtle/rdf_turtle.ml
+++ b/lib/turtle/rdf_turtle.ml
@@ -7,8 +7,11 @@
*)
module Ordered_string = struct
+
type t = string
+
let compare = String.compare
+
end
module SMap = Map.Make (Ordered_string)
@@ -16,29 +19,97 @@ module SMap = Map.Make (Ordered_string)
module AST = struct
module Iriref = struct
+
type t = string
+
let of_string s = s
+
+ let to_string s = s
+
+ let equal a b =
+ String.equal
+ (to_string a)
+ (to_string b)
+
+ let pp ppf iriref =
+ Fmt.pf ppf "@[<h 1><iriref@ %s>@]" (to_string iriref)
+
end
module Language = struct
+
type t = string
+
let of_string s = s
+
+ let to_string s = s
+
+ let equal a b =
+ String.equal
+ (to_string a)
+ (to_string b)
+
+ let pp ppf language =
+ Fmt.pf ppf "@[<h 1><language@ %s>@]" (to_string language)
+
end
module Prefixed_name = struct
+
type t = string * string
+
let of_strings s1 s2 = (s1, s2)
+
+ let equal a b =
+ String.equal (fst a) (fst b)
+ &&
+ String.equal (snd a) (snd b)
+
+(* TODO check whether this is nice *)
+ let pp ppf prefixed_name =
+ Fmt.pf ppf "@[<8> 1><prefixed_name fst@ %s snd@ %s>@"
+ (fst prefixed_name)
+ (snd prefixed_name)
+
end
module Blank_node = struct
+
type t = string
+
let of_string s = s
+
+ let to_string s = s
+
+ let equal a b =
+ String.equal
+ (to_string a)
+ (to_string b)
+
+(* TODO check whether this is nice (for all the pp functions)*)
+ let pp ppf blank_node =
+ Fmt.pf ppf "@[<h 1><blank_node@ %s>@]" (to_string blank_node)
+
end
module Iri = struct
+
type t = Iriref of Iriref.t | Prefixed_name of Prefixed_name.t
+
let of_iriref ref = Iriref ref
+
let of_prefixed_name pname = Prefixed_name pname
+
+ let equal a b =
+ match (a, b) with
+ | (Iriref refa), (Iriref refb) -> Iriref.equal refa refb
+ | (Prefixed_name pa), (Prefixed_name pb) -> Prefixed_name.equal pa pb
+ | _ -> false
+
+ let pp ppf = function
+ | Iriref iriref -> Iriref.pp ppf iriref
+ | Prefixed_name pname -> Prefixed_name.pp ppf pname
+
end
module Literal = struct
@@ -54,16 +125,42 @@ module AST = struct
let canonical literal =
literal.value
+ let language literal =
+ literal.language
+
let datatype literal =
literal.datatype
- let language literal =
- literal.language
+ let equal a b =
+ (String.equal a.value b.value)
+ &&
+ (Option.equal String.equal a.language b.language)
+ &&
+ (Iri.equal a.datatype b.datatype)
+
+ let pp ppf literal =
+ (* TODO print the datatype and language *)
+ Fmt.pf ppf
+ "@[<8><literal@ value@ %s>@]" (canonical literal)
+
end
module Predicate = struct
+
type t = Pred_iri of Iri.t | Pred_a
+
let of_iri iri = Pred_iri iri
+
+ let equal a b =
+ match (a, b) with
+ | (Pred_a, Pred_a) -> true
+ | (Pred_iri ia, Pred_iri ib) -> Iri.equal ia ib
+ | _ -> false
+
+ let pp ppf = function
+ | Pred_a -> Fmt.pf ppf "@<pred_a>@]"
+ | Pred_iri i -> Fmt.pf ppf "@[<4><predicate@ %a>@]" Iri.pp i
+
end
type object' =
diff --git a/lib/turtle/rdf_turtle.mli b/lib/turtle/rdf_turtle.mli
index 941f039..6df01c7 100644
--- a/lib/turtle/rdf_turtle.mli
+++ b/lib/turtle/rdf_turtle.mli
@@ -17,6 +17,13 @@ module AST : sig
val of_string : string -> t
+ val to_string : t -> string
+
+ val equal : t -> t -> bool
+
+ val pp : t Fmt.t
+ [@@ocaml.toplevel_printer]
+
end
module Language : sig
@@ -25,6 +32,11 @@ module AST : sig
val of_string : string -> t
+ val equal : t -> t -> bool
+
+ val pp : t Fmt.t
+ [@@ocaml.toplevel_printer]
+
end
(* The prefixed name is given by a PNAME_NS and PNAME_LN *)
@@ -35,6 +47,11 @@ module AST : sig
val of_strings : string -> string -> t
+ val equal : t -> t -> bool
+
+ val pp : t Fmt.t
+ [@@ocaml.toplevel_printer]
+
end
module Blank_node : sig
@@ -43,6 +60,11 @@ module AST : sig
val of_string : string -> t
+ val equal : t -> t -> bool
+
+ val pp : t Fmt.t
+ [@@ocaml.toplevel_printer]
+
end
module Iri : sig
@@ -53,6 +75,11 @@ module AST : sig
val of_prefixed_name : Prefixed_name.t -> t
+ val equal : t -> t -> bool
+
+ val pp : t Fmt.t
+ [@@ocaml.toplevel_printer]
+
end
(* The language option indicates a language, the iri option inidicates the data type *)
@@ -75,6 +102,12 @@ module AST : sig
val language : t -> string option
(** [language literal] returns the language tag of the literal. *)
+
+ val equal : t -> t -> bool
+
+ val pp : t Fmt.t
+ [@@ocaml.toplevel_printer]
+
end
(* We omit the 'verb' type, since this predicate type encompasses the same space *)
@@ -84,6 +117,11 @@ module AST : sig
val of_iri : Iri.t -> t
+ val equal : t -> t -> bool
+
+ val pp : t Fmt.t
+ [@@ocaml.toplevel_printer]
+
end
(* The types below are (recursive, what is it called?). The 'and' indicates this. *)
diff --git a/test/alcotest/dune b/test/alcotest/dune
index 53a1268..3462348 100644
--- a/test/alcotest/dune
+++ b/test/alcotest/dune
@@ -1,4 +1,3 @@
(library
- (name rdf_alcotest)
(public_name rdf_alcotest)
- (libraries rdf alcotest))
+ (libraries rdf rdf_turtle alcotest))
diff --git a/test/alcotest/rdf_alcotest.ml b/test/alcotest/rdf_alcotest.ml
index 9e510eb..7144f27 100644
--- a/test/alcotest/rdf_alcotest.ml
+++ b/test/alcotest/rdf_alcotest.ml
@@ -24,3 +24,24 @@ let triple =
let graph =
Alcotest.testable Rdf.Graph.pp Rdf.Graph.equal
+
+let ast_iriref =
+ Alcotest.testable Rdf_turtle.AST.Iriref.pp Rdf_turtle.AST.Iriref.equal
+
+let ast_language =
+ Alcotest.testable Rdf_turtle.AST.Language.pp Rdf_turtle.AST.Language.equal
+
+let ast_prefixed_name =
+ Alcotest.testable Rdf_turtle.AST.Prefixed_name.pp Rdf_turtle.AST.Prefixed_name.equal
+
+let ast_blank_node =
+ Alcotest.testable Rdf_turtle.AST.Blank_node.pp Rdf_turtle.AST.Blank_node.equal
+
+let ast_iri =
+ Alcotest.testable Rdf_turtle.AST.Iri.pp Rdf_turtle.AST.Iri.equal
+
+let ast_literal =
+ Alcotest.testable Rdf_turtle.AST.Literal.pp Rdf_turtle.AST.Literal.equal
+
+let ast_predicate =
+ Alcotest.testable Rdf_turtle.AST.Predicate.pp Rdf_turtle.AST.Predicate.equal
diff --git a/test/alcotest/rdf_alcotest.mli b/test/alcotest/rdf_alcotest.mli
index dca2170..144c5ec 100644
--- a/test/alcotest/rdf_alcotest.mli
+++ b/test/alcotest/rdf_alcotest.mli
@@ -17,3 +17,17 @@ val term : Rdf.Term.t Alcotest.testable
val triple : Rdf.Triple.t Alcotest.testable
val graph : Rdf.Graph.t Alcotest.testable
+
+val ast_iriref : Rdf_turtle.AST.Iriref.t Alcotest.testable
+
+val ast_language : Rdf_turtle.AST.Language.t Alcotest.testable
+
+val ast_prefixed_name : Rdf_turtle.AST.Prefixed_name.t Alcotest.testable
+
+val ast_blank_node : Rdf_turtle.AST.Blank_node.t Alcotest.testable
+
+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