diff --git a/lib/rdf/graph.ex b/lib/rdf/graph.ex index c9039fc..8f57154 100644 --- a/lib/rdf/graph.ex +++ b/lib/rdf/graph.ex @@ -177,8 +177,13 @@ defmodule RDF.Graph do end) end - def add(%__MODULE__{} = graph, %Description{subject: subject} = description), - do: do_add(graph, subject, description) + def add(%__MODULE__{} = graph, %Description{subject: subject} = description) do + if Description.count(description) > 0 do + do_add(graph, subject, description) + else + graph + end + end def add(graph, %__MODULE__{descriptions: descriptions, prefixes: prefixes}) do graph = diff --git a/test/unit/graph_test.exs b/test/unit/graph_test.exs index b947b02..decf1bd 100644 --- a/test/unit/graph_test.exs +++ b/test/unit/graph_test.exs @@ -98,6 +98,11 @@ defmodule RDF.GraphTest do assert graph_includes_statement?(g, {EX.Subject, EX.predicate(), EX.Object}) end + test "creating an unnamed graph with an empty description" do + g = Graph.new(Description.new(EX.Subject)) + assert empty_graph?(g) + end + test "creating a named graph from another graph" do g = Graph.new(Graph.new({EX.Subject, EX.predicate(), EX.Object}),