From 5d9ddeb7feaeea8a4e1b7a0096724de7115aaaa3 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Sun, 11 Oct 2020 02:48:35 +0200 Subject: [PATCH] Add tests for merging RDF.PropertyMaps Implementation wasn't needed, since the merge already works via the Enumerable protocol implementation. --- test/unit/property_map_test.exs | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/test/unit/property_map_test.exs b/test/unit/property_map_test.exs index 59667d3..24ea5e9 100644 --- a/test/unit/property_map_test.exs +++ b/test/unit/property_map_test.exs @@ -105,6 +105,31 @@ defmodule RDF.PropertyMapTest do }) == {:ok, @example_property_map} end + test "with a disjunctive PropertyMap" do + assert {:ok, property_map} = + PropertyMap.new() + |> PropertyMap.add(PropertyMap.new(foo: ~I)) + + assert PropertyMap.add( + property_map, + PropertyMap.new(%{ + bar: "http://example.com/test/bar", + Baz: EX.Baz + }) + ) == {:ok, @example_property_map} + end + + test "with a conflicting PropertyMap" do + assert {:error, _} = + PropertyMap.add(@example_property_map, PropertyMap.new(foo: EX.other())) + + assert {:error, _} = + PropertyMap.add( + @example_property_map, + PropertyMap.new(other: ~I) + ) + end + test "when a mapping to the same IRI exists" do assert PropertyMap.add(@example_property_map, foo: ~I, @@ -143,6 +168,28 @@ defmodule RDF.PropertyMapTest do }) == @example_property_map end + test "with a disjunctive PropertyMap" do + assert PropertyMap.new() + |> PropertyMap.put(PropertyMap.new(foo: ~I)) + |> PropertyMap.put( + PropertyMap.new(%{ + bar: "http://example.com/test/bar", + Baz: EX.Baz + }) + ) == @example_property_map + end + + test "with a conflicting PropertyMap" do + assert @example_property_map + |> PropertyMap.put(PropertyMap.new(foo: EX.other())) + |> PropertyMap.put(PropertyMap.new(other: ~I)) == + PropertyMap.new( + foo: EX.other(), + other: ~I, + Baz: RDF.iri(EX.Baz) + ) + end + test "when mapping exists" do assert PropertyMap.put(@example_property_map, bar: "http://example.com/test/bar",