Add RDF.Diff.empty?/1

This commit is contained in:
Marcel Otto 2019-11-20 01:56:43 +01:00
parent a1cbbd24b6
commit a77fe7c56e
2 changed files with 17 additions and 0 deletions

View file

@ -150,6 +150,15 @@ defmodule RDF.Diff do
)
end
@doc """
Determines if a diff is empty.
A `RDF.Diff` is empty, if its `additions` and `deletions` graphs are empty.
"""
def empty?(%__MODULE__{} = diff) do
Enum.empty?(diff.additions) and Enum.empty?(diff.deletions)
end
@doc """
Applies a diff to a `RDF.Graph` or `RDF.Description` by deleting the `deletions` and adding the `additions` of the `diff`.

View file

@ -198,6 +198,14 @@ defmodule RDF.DiffTest do
)
end
test "empty?/1" do
assert Diff.empty?(Diff.new()) == true
assert Diff.empty?(Diff.new(additions: EX.p(EX.S, EX.O),
deletions: EX.p(EX.S, EX.O))) == false
assert Diff.empty?(Diff.new(additions: EX.p(EX.S, EX.O))) == false
assert Diff.empty?(Diff.new(deletions: EX.p(EX.S, EX.O))) == false
end
describe "apply/2" do
test "on a graph" do
assert Diff.new(