Optimize RDF.PrefixMap.new/1 creation from another PrefixMap

This commit is contained in:
Marcel Otto 2019-03-30 22:11:04 +01:00
parent 6c9f580cab
commit c2e6ffdebb
2 changed files with 6 additions and 0 deletions

View file

@ -23,6 +23,8 @@ defmodule RDF.PrefixMap do
"""
def new(map)
def new(%__MODULE__{} = prefix_map), do: prefix_map
def new(map) when is_map(map) do
%__MODULE__{map: Map.new(map, &normalize/1)}
end

View file

@ -45,6 +45,10 @@ defmodule RDF.PrefixMapTest do
) == @example2
end
test "with another prefix map" do
assert PrefixMap.new(@example2) == @example2
end
test "when the IRI namespace is given as a RDF.Vocabulary.Namespace" do
assert PrefixMap.new(
ex1: "http://example.com/foo/",