Fix non-empty RDF.Graph when adding empty RDF.Description (#8)

This commit is contained in:
pukkamustard 2020-07-03 21:49:06 +00:00 committed by GitHub
parent 0e81f4c02c
commit 2d68a352ed
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -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 =

View file

@ -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}),