Fix RDF.PrefixMap.merge/3 when the merged prefixes are not a PrefixMap

This commit is contained in:
Marcel Otto 2019-03-30 20:12:39 +01:00
parent 15961b8fef
commit ec33614880
2 changed files with 9 additions and 0 deletions

View file

@ -138,6 +138,8 @@ defmodule RDF.PrefixMap do
If everything could be merged, an `:ok` tuple is returned.
"""
def merge(prefix_map1, prefix_map2, fun)
def merge(%__MODULE__{map: map1}, %__MODULE__{map: map2}, fun) when is_function(fun) do
conflict_resolution = fn prefix, namespace1, namespace2 ->
case fun.(prefix, namespace1, namespace2) do
@ -154,6 +156,10 @@ defmodule RDF.PrefixMap do
end
end
def merge(%__MODULE__{} = prefix_map1, prefix_map2, fun) when is_function(fun) do
merge(prefix_map1, new(prefix_map2), fun)
end
def merge(prefix_map1, prefix_map2, nil), do: merge(prefix_map1, prefix_map2)
defp resolved_merge_rest_conflicts(map) do

View file

@ -142,6 +142,9 @@ defmodule RDF.PrefixMapTest do
other_prefix_map = PrefixMap.new(ex3: @ex_ns4)
assert PrefixMap.merge(@example3, other_prefix_map,
fn _prefix, ns1, _ns2 -> ns1 end) == {:ok, @example3}
assert PrefixMap.merge(@example1, %{ex1: EX},
fn _prefix, _ns1, ns2 -> ns2 end) == {:ok, PrefixMap.new(ex1: EX)}
end
test "with a function which does not resolve by returning nil" do