Fix detection of vocabulary namespaces
This commit is contained in:
parent
bee98f3e75
commit
15961b8fef
3 changed files with 16 additions and 1 deletions
|
@ -41,7 +41,7 @@ defmodule RDF.PrefixMap do
|
|||
do: normalize({prefix, IRI.new(namespace)})
|
||||
|
||||
defp normalize({prefix, namespace}) when is_atom(namespace) do
|
||||
if function_exported?(namespace, :__base_iri__, 0) do
|
||||
if RDF.Vocabulary.Namespace.vocabulary_namespace?(namespace) do
|
||||
normalize({prefix, apply(namespace, :__base_iri__, [])})
|
||||
else
|
||||
raise ArgumentError,
|
||||
|
|
|
@ -572,4 +572,9 @@ defmodule RDF.Vocabulary.Namespace do
|
|||
def term_to_iri(base_iri, term),
|
||||
do: RDF.iri(base_iri <> term)
|
||||
|
||||
@doc false
|
||||
def vocabulary_namespace?(name) do
|
||||
Code.ensure_loaded?(name) && function_exported?(name, :__base_iri__, 0)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -70,12 +70,22 @@ defmodule RDF.PrefixMapTest do
|
|||
assert PrefixMap.add(@example1, :ex, EX) == {:ok, @example4}
|
||||
end
|
||||
|
||||
test "when the IRI namespace is given as a RDF.Vocabulary.Namespace which is not loaded yet" do
|
||||
assert {:ok, prefix_map} = PrefixMap.new |> PrefixMap.add(:rdfs, RDF.NS.RDFS)
|
||||
assert PrefixMap.has_prefix?(prefix_map, :rdfs)
|
||||
end
|
||||
|
||||
test "when the IRI namespace is given as an atom" do
|
||||
assert_raise ArgumentError, "Invalid prefix mapping for :ex, :foo is not a vocabulary namespace", fn ->
|
||||
PrefixMap.add(@example1, :ex, :foo)
|
||||
end
|
||||
end
|
||||
|
||||
@tag skip: "TODO: "
|
||||
test "when a default namespace is given" do
|
||||
assert PrefixMap.add(@example1, :_, @ex_ns2) == {:ok, @example5}
|
||||
end
|
||||
|
||||
test "when a mapping of the given prefix to the same namespace already exists" do
|
||||
assert PrefixMap.add(@example2, :ex2, "http://example.com/bar#") == {:ok, @example2}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue