aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorpukkamustard <pukkamustard@posteo.net>2021-04-26 13:56:04 +0200
committerpukkamustard <pukkamustard@posteo.net>2021-04-26 13:56:04 +0200
commit9bb64b745bf73dd9dd83173071b8f77dedda1078 (patch)
tree982072742ec01d63e7b49f08848cc3598b2bcc57 /test
parent23b0369fce9a9f7e023790e14e52cb17781afa2d (diff)
guix.scm: Update ocaml-cbor for bugfix
test/cbor: Add property-based tests for the CBOR encoding
Diffstat (limited to 'test')
-rw-r--r--test/cbor/dune9
-rw-r--r--test/cbor/main.ml28
-rw-r--r--test/core/dune7
-rw-r--r--test/core/main.ml9
-rw-r--r--test/gen/dune3
-rw-r--r--test/gen/rdf_gen.ml39
6 files changed, 95 insertions, 0 deletions
diff --git a/test/cbor/dune b/test/cbor/dune
new file mode 100644
index 0000000..26a2f33
--- /dev/null
+++ b/test/cbor/dune
@@ -0,0 +1,9 @@
+(executables
+ (names main)
+ (libraries rdf rdf_cbor
+ rdf_gen
+ alcotest qcheck qcheck-alcotest))
+
+(rule
+ (alias runtest)
+ (action (run ./main.exe)))
diff --git a/test/cbor/main.ml b/test/cbor/main.ml
new file mode 100644
index 0000000..216719b
--- /dev/null
+++ b/test/cbor/main.ml
@@ -0,0 +1,28 @@
+(*
+ * SPDX-FileCopyrightText: 2021 petites singularités <ps-dream@lesoiseaux.io>
+ * SPDX-FileCopyrightText: 2021 pukkamustard <pukkamustard@posteo.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *)
+
+module Iri = Rdf.Iri
+module Term = Rdf.Term
+
+let encode_decode_test =
+ QCheck.Test.make
+ ~count:1000
+ ~name:"encode/decode"
+ Rdf_gen.term
+ (fun term ->
+ Term.equal term
+ (term
+ |> Rdf_cbor.encode_term
+ |> Rdf_cbor.decode_term
+ ))
+
+let () =
+ Alcotest.run "rdf_cbor" [
+ "property based", [
+ QCheck_alcotest.to_alcotest encode_decode_test
+ ]
+ ]
diff --git a/test/core/dune b/test/core/dune
new file mode 100644
index 0000000..4d8d3b4
--- /dev/null
+++ b/test/core/dune
@@ -0,0 +1,7 @@
+(executables
+ (names main)
+ (libraries rdf))
+
+(rule
+ (alias runtest)
+ (action (run ./main.exe)))
diff --git a/test/core/main.ml b/test/core/main.ml
new file mode 100644
index 0000000..0b98968
--- /dev/null
+++ b/test/core/main.ml
@@ -0,0 +1,9 @@
+(*
+ * SPDX-FileCopyrightText: 2021 petites singularités <ps-dream@lesoiseaux.io>
+ * SPDX-FileCopyrightText: 2021 pukkamustard <pukkamustard@posteo.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *)
+
+(* TODO *)
+print_endline "crickets..."
diff --git a/test/gen/dune b/test/gen/dune
new file mode 100644
index 0000000..24b7256
--- /dev/null
+++ b/test/gen/dune
@@ -0,0 +1,3 @@
+(library
+ (name rdf_gen)
+ (libraries rdf qcheck))
diff --git a/test/gen/rdf_gen.ml b/test/gen/rdf_gen.ml
new file mode 100644
index 0000000..12a7692
--- /dev/null
+++ b/test/gen/rdf_gen.ml
@@ -0,0 +1,39 @@
+(*
+ * SPDX-FileCopyrightText: 2021 petites singularités <ps-dream@lesoiseaux.io>
+ * SPDX-FileCopyrightText: 2021 pukkamustard <pukkamustard@posteo.net>
+ *
+ * SPDX-License-Identifier: AGPL-3.0-or-later
+ *)
+
+module Iri = Rdf.Iri
+module Blank_node = Rdf.Blank_node
+module Literal = Rdf.Literal
+module Term = Rdf.Term
+
+
+let iri =
+ QCheck.Gen.(
+ (fun scheme host -> Iri.make ~scheme ~host ())
+ <$> (oneofl ["http"; "https"])
+ <*> (oneofl ["example.com"; "test.com"; "dream.cat"]))
+ |> QCheck.make ~print:Iri.to_string
+
+let blank_node =
+ QCheck.Gen.(
+ Blank_node.of_string
+ <$> oneofl ["a"])
+ |> QCheck.make ~print:Blank_node.identifier
+
+let literal =
+ QCheck.Gen.(
+ (fun s -> Literal.make s (Rdf.Namespace.xsd "string"))
+ <$> oneofl ["b"]
+ )
+ |> QCheck.make ~print:Literal.canonical
+
+let term =
+ QCheck.(
+ [iri |> map Term.of_iri;
+ blank_node |> map Term.of_blank_node;
+ literal |> map Term.of_literal]
+ |> choose)