Handle resolving of terms from undefined modules consistently

This commit is contained in:
Marcel Otto 2017-08-21 21:06:57 +02:00
parent 5c7efe4cbd
commit 19457d61b9
3 changed files with 11 additions and 1 deletions

View file

@ -24,6 +24,12 @@ This project adheres to [Semantic Versioning](http://semver.org/) and
- `RDF.Literal.InvalidError` instead of `RDF.InvalidLiteralError`
- `RDF.Namespace.InvalidVocabBaseIRIError` instead of `RDF.Namespace.InvalidVocabBaseURIError`
### Fixed
- when trying to resolve a term from an undefined module a `RDF.Namespace.UndefinedTermError`
exception
[Compare v0.2.0...HEAD](https://github.com/marcelotto/rdf-ex/compare/v0.2.0...HEAD)

View file

@ -52,7 +52,8 @@ defmodule RDF.Namespace do
defp do_resolve_term(RDF, term), do: do_resolve_term(RDF.NS.RDF, term)
defp do_resolve_term(namespace, term) do
if Keyword.has_key?(namespace.__info__(:functions), :__resolve_term__) do
if Code.ensure_compiled?(namespace) and
Keyword.has_key?(namespace.__info__(:functions), :__resolve_term__)do
namespace.__resolve_term__(term)
else
raise RDF.Namespace.UndefinedTermError,

View file

@ -738,6 +738,9 @@ defmodule RDF.Vocabulary.NamespaceTest do
assert_raise RDF.Namespace.UndefinedTermError, fn -> RDF.iri(ExUnit.Test) end
end
test "resolving an non-existing RDF.Namespace module" do
assert_raise RDF.Namespace.UndefinedTermError, fn -> RDF.iri(NonExisting.Test) end
end
describe "term resolution in a strict vocab namespace" do
alias TestNS.{ExampleFromGraph, ExampleFromNTriplesFile, StrictExampleFromTerms}