Add RDF.PrefixMap.merge!/2
This commit is contained in:
parent
14f7bb5693
commit
4da3a12011
2 changed files with 24 additions and 0 deletions
|
@ -128,6 +128,17 @@ defmodule RDF.PrefixMap do
|
|||
(existing_namespace = Map.get(map, prefix)) && existing_namespace != namespace
|
||||
end
|
||||
|
||||
@doc """
|
||||
Merges two `RDF.PrefixMap`s and raises an exception in error cases.
|
||||
"""
|
||||
def merge!(prefix_map1, prefix_map2) do
|
||||
with {:ok, new_prefix_map} <- merge(prefix_map1, prefix_map2) do
|
||||
new_prefix_map
|
||||
else
|
||||
{:error, error} -> raise error
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a prefix mapping from the given `RDF.PrefixMap`..
|
||||
"""
|
||||
|
|
|
@ -127,6 +127,19 @@ defmodule RDF.PrefixMapTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "merge!/2" do
|
||||
test "when the prefix maps can be merged" do
|
||||
other_prefix_map = PrefixMap.new(ex3: @ex_ns3)
|
||||
assert PrefixMap.merge!(@example2, other_prefix_map) == @example3
|
||||
end
|
||||
|
||||
test "when the prefix maps can not be merged" do
|
||||
assert_raise RuntimeError, "conflicting prefix mappings: :ex2", fn ->
|
||||
PrefixMap.merge!(@example2, ex2: @ex_ns3)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete/2" do
|
||||
test "when a mapping of the given prefix exists" do
|
||||
assert PrefixMap.delete(@example2, :ex2) == @example1
|
||||
|
|
Loading…
Reference in a new issue