Fix raised BEAM error warning when namespace resolving top-level modules

This commit is contained in:
Marcel Otto 2020-05-17 00:01:18 +02:00
parent 4d3d60a5f4
commit 76b6f69613
3 changed files with 19 additions and 0 deletions

View file

@ -13,6 +13,11 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
- `RDF.Namespace.resolve_term/1` now returns ok or error tuples, but a new function
`RDF.Namespace.resolve_term!/1` with the old behaviour was added
### Fixed
- BEAM error warnings when trying to use top-level modules as vocabulary terms
[Compare v0.7.1...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.7.1...HEAD)

View file

@ -73,6 +73,14 @@ defmodule RDF.Namespace do
defp do_resolve_term(RDF, term), do: do_resolve_term(RDF.NS.RDF, term)
defp do_resolve_term(Elixir, term) do
{:error,
%RDF.Namespace.UndefinedTermError{message:
"#{term} is not a RDF.Namespace; top-level modules can't be RDF.Namespaces"
}
}
end
defp do_resolve_term(namespace, term) do
is_module =
case Code.ensure_compiled(namespace) do

View file

@ -752,6 +752,12 @@ defmodule RDF.Vocabulary.NamespaceTest do
assert_raise RDF.Namespace.UndefinedTermError, fn -> RDF.iri(ExUnit.Test) end
end
test "resolving an top-level module" do
assert_raise RDF.Namespace.UndefinedTermError,
"ExUnit is not a RDF.Namespace; top-level modules can't be RDF.Namespaces",
fn -> RDF.iri(ExUnit) end
end
test "resolving an non-existing RDF.Namespace module" do
assert_raise RDF.Namespace.UndefinedTermError, fn -> RDF.iri(NonExisting.Test) end
end