diff --git a/lib/rdf/graph.ex b/lib/rdf/graph.ex index 9ffa005..2410307 100644 --- a/lib/rdf/graph.ex +++ b/lib/rdf/graph.ex @@ -753,6 +753,8 @@ defmodule RDF.Graph do @doc """ Sets the base IRI of the given `graph`. + + The `base_iri` can be given as anything accepted by `RDF.IRI.coerce_base/1`. """ def set_base_iri(graph, base_iri) @@ -761,7 +763,7 @@ defmodule RDF.Graph do end def set_base_iri(%RDF.Graph{} = graph, base_iri) do - %RDF.Graph{graph | base_iri: RDF.IRI.new(base_iri)} + %RDF.Graph{graph | base_iri: RDF.IRI.coerce_base(base_iri)} end @doc """ diff --git a/test/unit/graph_test.exs b/test/unit/graph_test.exs index 9c3cc42..25b6e8d 100644 --- a/test/unit/graph_test.exs +++ b/test/unit/graph_test.exs @@ -544,11 +544,16 @@ defmodule RDF.GraphTest do assert graph.base_iri == ~I end - test "when given a vocabulary namespace atom" do + test "when given a term atom under a vocabulary namespace" do graph = Graph.new() |> Graph.set_base_iri(EX.Base) assert graph.base_iri == RDF.iri(EX.Base) end + test "when given a vocabulary namespace module" do + graph = Graph.new() |> Graph.set_base_iri(EX) + assert graph.base_iri == RDF.iri(EX.__base_iri__) + end + test "when given nil" do graph = Graph.new() |> Graph.set_base_iri(nil) assert graph.base_iri == nil