From b75024baf5aa6fc912945ce3d37cd691e560e3d1 Mon Sep 17 00:00:00 2001 From: Marcel Otto Date: Fri, 29 Mar 2019 21:01:51 +0100 Subject: [PATCH] Let RDF.PrefixMap.merge/2 return the list conflicts in the error case --- lib/rdf/prefix_map.ex | 15 +++++++++------ test/unit/prefix_map_test.exs | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/rdf/prefix_map.ex b/lib/rdf/prefix_map.ex index 2ed57e6..9fd119e 100644 --- a/lib/rdf/prefix_map.ex +++ b/lib/rdf/prefix_map.ex @@ -92,8 +92,10 @@ defmodule RDF.PrefixMap do The second prefix map can also be given as any structure which can converted to a `RDF.PrefixMap` via `new/1`. - If there are conflicts between the prefix maps, that is prefixes mapped to - different namespaces and error tuple is returned, otherwise an ok tuple. + If the prefix maps can be merged without conflicts, that is there are no + prefixes mapped to different namespaces an `:ok` tuple is returned. + Otherwise an `:error` tuple with the list of prefixes with conflicting + namespaces is returned. """ def merge(prefix_map1, prefix_map2) @@ -101,9 +103,7 @@ defmodule RDF.PrefixMap do with [] <- merge_conflicts(map1, map2) do {:ok, %__MODULE__{map: Map.merge(map1, map2)}} else - conflicts -> - {:error, - "conflicting prefix mappings: #{conflicts |> Stream.map(&inspect/1) |> Enum.join(", ")}"} + conflicts -> {:error, conflicts} end end @@ -135,7 +135,10 @@ defmodule RDF.PrefixMap do with {:ok, new_prefix_map} <- merge(prefix_map1, prefix_map2) do new_prefix_map else - {:error, error} -> raise error + {:error, conflicts} -> + raise "conflicting prefix mappings: #{ + conflicts |> Stream.map(&inspect/1) |> Enum.join(", ") + }" end end diff --git a/test/unit/prefix_map_test.exs b/test/unit/prefix_map_test.exs index bbc0e8d..9ff1a34 100644 --- a/test/unit/prefix_map_test.exs +++ b/test/unit/prefix_map_test.exs @@ -112,7 +112,8 @@ defmodule RDF.PrefixMapTest do test "when the prefix maps share some prefixes and both map to different namespaces" do other_prefix_map = PrefixMap.new(ex3: @ex_ns4) - assert PrefixMap.merge(@example3, other_prefix_map) == {:error, "conflicting prefix mappings: :ex3"} + assert PrefixMap.merge(@example3, other_prefix_map) == + {:error, [:ex3]} end test "when the second prefix map is given as a structure convertible to a prefix map" do