diff options
author | pukkamustard <pukkamustard@posteo.net> | 2021-06-22 12:19:31 +0200 |
---|---|---|
committer | pukkamustard <pukkamustard@posteo.net> | 2021-06-22 12:19:31 +0200 |
commit | 98456a066d114f7b02fbfb73b7ba5dd6690a94cd (patch) | |
tree | 406992ac88e42d529fb68f76ae91c5e91b98755c /test | |
parent | 67797a14aaf932c7ff6503d062447d8b59e4446e (diff) |
Rdf_fragment_graph: Add of_triples function.
This is especially useful for converting RDF into content-addressable RDF.
Diffstat (limited to 'test')
-rw-r--r-- | test/fragment_graph/main.ml | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/test/fragment_graph/main.ml b/test/fragment_graph/main.ml index 5a168a7..6cffc2b 100644 --- a/test/fragment_graph/main.ml +++ b/test/fragment_graph/main.ml @@ -5,6 +5,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later *) +(* TODO these tests have grown into a mess. needs some cleaning up. *) + module FragmentGraph = Rdf_fragment_graph.Make(struct let hash s = "urn:dummy_hash:" ^ (string_of_int @@ Hashtbl.hash s) @@ -78,8 +80,74 @@ end let fragment_graph_testable = Alcotest.testable FragmentGraph.pp FragmentGraph.equal +let predicate_testable = + Alcotest.testable FragmentGraph.Predicate.pp (=) + let ex = Rdf.Namespace.make_namespace "http://example.com/" +let predicate_of_iri_test = + let open Alcotest in + test_case "Predicate.of_iri" + `Quick + (fun () -> + check predicate_testable + "no base_subject returns the iri" + (FragmentGraph.Predicate.of_iri @@ ex "hello") + (FragmentGraph.Predicate.of_iri @@ ex "hello"); + + check predicate_testable + "with base_subject return a fragment identifier" + (FragmentGraph.Predicate.make_fragment_reference "hello") + (FragmentGraph.Predicate.of_iri + ~base_subject:(Rdf.Iri.of_string "http://example.com/") + @@ ex "hello"); + + Format.printf "%a\n" + Rdf.Iri.pp (Rdf.Iri.with_fragment (ex "hi") (Some "blup"))) + +let of_triples_test = + let open Alcotest in + test_case "of_triples" + `Quick + (fun () -> + let fg_direct = + FragmentGraph.(empty + |> add_statement + (Predicate.make_fragment_reference "prop") + (Object.make_fragment_reference "something") + |> add_fragment_statement "hi" + (Predicate.of_iri @@ Rdf.Iri.of_string "urn:example:foo") + (Object.of_literal @@ Rdf.Literal.make "blups" (ex "type"))) + in + + let fg_of_triples = + [ + Rdf.Triple.(make + (Subject.of_iri @@ Rdf.Iri.of_string "http://example.com/") + (Predicate.of_iri @@ ex "prop") + (Object.of_iri @@ ex "something")); + + Rdf.Triple.(make + (Subject.of_iri @@ Rdf.Iri.of_string "http://example.com/#hi") + (Predicate.of_iri @@ Rdf.Iri.of_string "urn:example:foo") + (* TODO! an intersting case I had not thought about. + What if the literal datatype makes a reference to the + base_subject? *) + (Object.of_literal @@ Rdf.Literal.make "blups" (ex "type"))) + ] + |> List.to_seq + |> FragmentGraph.of_triples + |> List.of_seq + |> List.hd + |> (fun (_,fg) -> fg) + + in + + check fragment_graph_testable + "of_triples and directly creating is equal" + fg_direct + fg_of_triples) + let equal_unit_test = let open Alcotest in test_case "unit tests" @@ -312,6 +380,10 @@ let canonical_unit_test = let () = Alcotest.run "rdf_fragment_graph" [ + "constructors", [ + predicate_of_iri_test; + of_triples_test + ]; "equal", [ equal_unit_test; QCheck_alcotest.to_alcotest equal_property_test |