Fix bad naming in some test functions
This commit is contained in:
parent
a367438f9d
commit
b0cdb62598
5 changed files with 85 additions and 69 deletions
|
@ -208,26 +208,31 @@ defmodule RDF.Test.Case do
|
||||||
end
|
end
|
||||||
|
|
||||||
###############################
|
###############################
|
||||||
# RDF.Star annotations
|
# RDF.Star
|
||||||
|
|
||||||
@star_statement {@statement, EX.ap(), EX.ao()}
|
@star_statement {@statement, EX.ap(), EX.ao()}
|
||||||
def star_statement(), do: @star_statement
|
def star_statement(), do: @star_statement
|
||||||
|
|
||||||
@empty_annotation Description.new(@statement)
|
@empty_annotation_description Description.new(@statement)
|
||||||
def empty_annotation(), do: @empty_annotation
|
def empty_annotation_description(), do: @empty_annotation_description
|
||||||
|
|
||||||
@annotation Description.new(@statement, init: {EX.ap(), EX.ao()})
|
@annotation_description Description.new(@statement, init: {EX.ap(), EX.ao()})
|
||||||
def annotation(), do: @annotation
|
def annotation_description(), do: @annotation_description
|
||||||
|
|
||||||
@object_annotation Description.new(EX.As, init: {EX.ap(), @statement})
|
@description_with_quoted_triple_object Description.new(EX.As, init: {EX.ap(), @statement})
|
||||||
def object_annotation(), do: @object_annotation
|
def description_with_quoted_triple_object(), do: @description_with_quoted_triple_object
|
||||||
|
|
||||||
@graph_with_annotation Graph.new(init: @annotation)
|
@graph_with_annotation Graph.new(init: @annotation_description)
|
||||||
def graph_with_annotation(), do: @graph_with_annotation
|
def graph_with_annotation(), do: @graph_with_annotation
|
||||||
|
|
||||||
@graph_with_annotations Graph.new(init: [@annotation, @object_annotation])
|
@graph_with_quoted_triples Graph.new(
|
||||||
def graph_with_annotations(), do: @graph_with_annotations
|
init: [
|
||||||
|
@annotation_description,
|
||||||
|
@description_with_quoted_triple_object
|
||||||
|
]
|
||||||
|
)
|
||||||
|
def graph_with_quoted_triples(), do: @graph_with_quoted_triples
|
||||||
|
|
||||||
@dataset_with_annotation Dataset.new(init: @annotation)
|
@dataset_with_annotation Dataset.new(init: @annotation_description)
|
||||||
def dataset_with_annotation(), do: @dataset_with_annotation
|
def dataset_with_annotation(), do: @dataset_with_annotation
|
||||||
end
|
end
|
||||||
|
|
|
@ -34,8 +34,8 @@ defmodule RDF.InspectTest do
|
||||||
|> String.trim()) <> "\n>"
|
|> String.trim()) <> "\n>"
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it encodes the RDF-star graphs ands descriptions in Turtle-star" do
|
test "it encodes the RDF-star graphs and descriptions in Turtle-star" do
|
||||||
{_, triples} = inspect_parts(annotation(), limit: 2)
|
{_, triples} = inspect_parts(annotation_description(), limit: 2)
|
||||||
assert triples =~ "<< <http://example.com/S> <http://example.com/P> \"Foo\" >>"
|
assert triples =~ "<< <http://example.com/S> <http://example.com/P> \"Foo\" >>"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ defmodule RDF.Star.Dataset.Test do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete/3" do
|
test "delete/3" do
|
||||||
assert Dataset.delete(dataset_with_annotation(), annotation()) == dataset()
|
assert Dataset.delete(dataset_with_annotation(), annotation_description()) == dataset()
|
||||||
end
|
end
|
||||||
|
|
||||||
test ":filter_star opt on statements/1" do
|
test ":filter_star opt on statements/1" do
|
||||||
|
|
|
@ -24,7 +24,7 @@ defmodule RDF.Star.Description.Test do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "subject/1" do
|
test "subject/1" do
|
||||||
assert Description.subject(empty_annotation()) == statement()
|
assert Description.subject(empty_annotation_description()) == statement()
|
||||||
end
|
end
|
||||||
|
|
||||||
test "change_subject/2" do
|
test "change_subject/2" do
|
||||||
|
@ -35,7 +35,7 @@ defmodule RDF.Star.Description.Test do
|
||||||
|
|
||||||
describe "add/3" do
|
describe "add/3" do
|
||||||
test "with a proper triple as a subject" do
|
test "with a proper triple as a subject" do
|
||||||
assert empty_annotation()
|
assert empty_annotation_description()
|
||||||
|> Description.add({statement(), EX.ap(), EX.ao()})
|
|> Description.add({statement(), EX.ap(), EX.ao()})
|
||||||
|> description_includes_predication({EX.ap(), EX.ao()})
|
|> description_includes_predication({EX.ap(), EX.ao()})
|
||||||
end
|
end
|
||||||
|
@ -47,7 +47,7 @@ defmodule RDF.Star.Description.Test do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "with a proper triple as a subject and object" do
|
test "with a proper triple as a subject and object" do
|
||||||
assert empty_annotation()
|
assert empty_annotation_description()
|
||||||
|> Description.add({statement(), EX.ap(), statement()})
|
|> Description.add({statement(), EX.ap(), statement()})
|
||||||
|> description_includes_predication({EX.ap(), statement()})
|
|> description_includes_predication({EX.ap(), statement()})
|
||||||
end
|
end
|
||||||
|
@ -62,81 +62,87 @@ defmodule RDF.Star.Description.Test do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "with a list of predicate-object tuples" do
|
test "with a list of predicate-object tuples" do
|
||||||
assert empty_annotation()
|
assert empty_annotation_description()
|
||||||
|> Description.add([{EX.ap(), statement()}])
|
|> Description.add([{EX.ap(), statement()}])
|
||||||
|> description_includes_predication({EX.ap(), statement()})
|
|> description_includes_predication({EX.ap(), statement()})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "with a description map" do
|
test "with a description map" do
|
||||||
assert empty_annotation()
|
assert empty_annotation_description()
|
||||||
|> Description.add(%{EX.ap() => statement()})
|
|> Description.add(%{EX.ap() => statement()})
|
||||||
|> description_includes_predication({EX.ap(), statement()})
|
|> description_includes_predication({EX.ap(), statement()})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "with coercible triples" do
|
test "with coercible triples" do
|
||||||
assert empty_annotation()
|
assert empty_annotation_description()
|
||||||
|> Description.add({coercible_statement(), EX.ap(), coercible_statement()})
|
|> Description.add({coercible_statement(), EX.ap(), coercible_statement()})
|
||||||
|> description_includes_predication({EX.ap(), statement()})
|
|> description_includes_predication({EX.ap(), statement()})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "put/3" do
|
test "put/3" do
|
||||||
assert annotation()
|
assert annotation_description()
|
||||||
|> Description.put({statement(), EX.ap(), EX.ao2()})
|
|> Description.put({statement(), EX.ap(), EX.ao2()})
|
||||||
|> description_includes_predication({EX.ap(), EX.ao2()})
|
|> description_includes_predication({EX.ap(), EX.ao2()})
|
||||||
|
|
||||||
assert annotation()
|
assert annotation_description()
|
||||||
|> Description.put({statement(), EX.ap(), statement()})
|
|> Description.put({statement(), EX.ap(), statement()})
|
||||||
|> description_includes_predication({EX.ap(), statement()})
|
|> description_includes_predication({EX.ap(), statement()})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete/3" do
|
test "delete/3" do
|
||||||
assert Description.delete(annotation(), {statement(), EX.ap(), EX.ao()}) ==
|
assert Description.delete(annotation_description(), {statement(), EX.ap(), EX.ao()}) ==
|
||||||
empty_annotation()
|
empty_annotation_description()
|
||||||
|
|
||||||
assert Description.delete(object_annotation(), {EX.As, EX.ap(), statement()}) ==
|
assert Description.delete(
|
||||||
|
description_with_quoted_triple_object(),
|
||||||
|
{EX.As, EX.ap(), statement()}
|
||||||
|
) ==
|
||||||
Description.new(EX.As)
|
Description.new(EX.As)
|
||||||
|
|
||||||
assert Description.delete(object_annotation(), {EX.ap(), statement()}) ==
|
assert Description.delete(description_with_quoted_triple_object(), {EX.ap(), statement()}) ==
|
||||||
Description.new(EX.As)
|
Description.new(EX.As)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "delete_predicates/2" do
|
test "delete_predicates/2" do
|
||||||
assert Description.delete_predicates(annotation(), EX.ap()) ==
|
assert Description.delete_predicates(annotation_description(), EX.ap()) ==
|
||||||
empty_annotation()
|
empty_annotation_description()
|
||||||
|
|
||||||
assert Description.delete_predicates(object_annotation(), EX.ap()) ==
|
assert Description.delete_predicates(description_with_quoted_triple_object(), EX.ap()) ==
|
||||||
Description.new(EX.As)
|
Description.new(EX.As)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "fetch/2" do
|
test "fetch/2" do
|
||||||
assert Description.fetch(annotation(), EX.ap()) == {:ok, [EX.ao()]}
|
assert Description.fetch(annotation_description(), EX.ap()) == {:ok, [EX.ao()]}
|
||||||
assert Description.fetch(object_annotation(), EX.ap()) == {:ok, [statement()]}
|
|
||||||
|
assert Description.fetch(description_with_quoted_triple_object(), EX.ap()) ==
|
||||||
|
{:ok, [statement()]}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get/2" do
|
test "get/2" do
|
||||||
assert Description.get(annotation(), EX.ap()) == [EX.ao()]
|
assert Description.get(annotation_description(), EX.ap()) == [EX.ao()]
|
||||||
assert Description.get(object_annotation(), EX.ap()) == [statement()]
|
assert Description.get(description_with_quoted_triple_object(), EX.ap()) == [statement()]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "first/2" do
|
test "first/2" do
|
||||||
assert Description.first(annotation(), EX.ap()) == EX.ao()
|
assert Description.first(annotation_description(), EX.ap()) == EX.ao()
|
||||||
assert Description.first(object_annotation(), EX.ap()) == statement()
|
assert Description.first(description_with_quoted_triple_object(), EX.ap()) == statement()
|
||||||
end
|
end
|
||||||
|
|
||||||
test "pop/2" do
|
test "pop/2" do
|
||||||
assert Description.pop(annotation(), EX.ap()) == {[EX.ao()], empty_annotation()}
|
assert Description.pop(annotation_description(), EX.ap()) ==
|
||||||
|
{[EX.ao()], empty_annotation_description()}
|
||||||
|
|
||||||
assert Description.pop(object_annotation(), EX.ap()) ==
|
assert Description.pop(description_with_quoted_triple_object(), EX.ap()) ==
|
||||||
{[statement()], Description.new(EX.As)}
|
{[statement()], Description.new(EX.As)}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update/4" do
|
test "update/4" do
|
||||||
assert (description =
|
assert (description =
|
||||||
Description.update(empty_annotation(), EX.ap(), statement(), fn _ ->
|
Description.update(empty_annotation_description(), EX.ap(), statement(), fn _ ->
|
||||||
raise "unexpected"
|
raise "unexpected"
|
||||||
end)) ==
|
end)) ==
|
||||||
empty_annotation()
|
empty_annotation_description()
|
||||||
|> Description.add(%{EX.ap() => statement()})
|
|> Description.add(%{EX.ap() => statement()})
|
||||||
|
|
||||||
assert Description.update(description, EX.ap(), statement(), fn
|
assert Description.update(description, EX.ap(), statement(), fn
|
||||||
|
@ -144,7 +150,7 @@ defmodule RDF.Star.Description.Test do
|
||||||
assert statement == statement()
|
assert statement == statement()
|
||||||
[statement, {s, p, EX.O}]
|
[statement, {s, p, EX.O}]
|
||||||
end) ==
|
end) ==
|
||||||
empty_annotation()
|
empty_annotation_description()
|
||||||
|> Description.add(%{EX.ap() => statement()})
|
|> Description.add(%{EX.ap() => statement()})
|
||||||
|> Description.add(%{EX.ap() => {EX.S, EX.P, EX.O}})
|
|> Description.add(%{EX.ap() => {EX.S, EX.P, EX.O}})
|
||||||
end
|
end
|
||||||
|
@ -195,8 +201,8 @@ defmodule RDF.Star.Description.Test do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "describes?/2" do
|
test "describes?/2" do
|
||||||
assert Description.describes?(annotation(), statement())
|
assert Description.describes?(annotation_description(), statement())
|
||||||
assert Description.describes?(annotation(), coercible_statement())
|
assert Description.describes?(annotation_description(), coercible_statement())
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "without_quoted_triples/1" do
|
describe "without_quoted_triples/1" do
|
||||||
|
|
|
@ -5,7 +5,7 @@ defmodule RDF.Star.GraphTest do
|
||||||
assert Graph.new(init: {statement(), EX.ap(), EX.ao()})
|
assert Graph.new(init: {statement(), EX.ap(), EX.ao()})
|
||||||
|> graph_includes_statement?({statement(), EX.ap(), EX.ao()})
|
|> graph_includes_statement?({statement(), EX.ap(), EX.ao()})
|
||||||
|
|
||||||
assert Graph.new(init: annotation())
|
assert Graph.new(init: annotation_description())
|
||||||
|> graph_includes_statement?({statement(), EX.ap(), EX.ao()})
|
|> graph_includes_statement?({statement(), EX.ap(), EX.ao()})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1691,57 +1691,60 @@ defmodule RDF.Star.GraphTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "update/3" do
|
test "update/3" do
|
||||||
assert Graph.update(graph(), statement(), annotation(), fn _ -> raise "unexpected" end) ==
|
assert Graph.update(graph(), statement(), annotation_description(), fn _ ->
|
||||||
|
raise "unexpected"
|
||||||
|
end) ==
|
||||||
graph_with_annotation()
|
graph_with_annotation()
|
||||||
|
|
||||||
assert graph()
|
assert graph()
|
||||||
|> Graph.add({statement(), EX.foo(), EX.bar()})
|
|> Graph.add({statement(), EX.foo(), EX.bar()})
|
||||||
|> Graph.update(statement(), fn _ -> annotation() end) ==
|
|> Graph.update(statement(), fn _ -> annotation_description() end) ==
|
||||||
graph_with_annotation()
|
graph_with_annotation()
|
||||||
end
|
end
|
||||||
|
|
||||||
test "fetch/2" do
|
test "fetch/2" do
|
||||||
assert graph_with_annotation() |> Graph.fetch(statement()) == {:ok, annotation()}
|
assert graph_with_annotation() |> Graph.fetch(statement()) == {:ok, annotation_description()}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get/3" do
|
test "get/3" do
|
||||||
assert graph_with_annotation() |> Graph.get(statement()) == annotation()
|
assert graph_with_annotation() |> Graph.get(statement()) == annotation_description()
|
||||||
end
|
end
|
||||||
|
|
||||||
test "get_and_update/3" do
|
test "get_and_update/3" do
|
||||||
assert Graph.get_and_update(graph_with_annotation(), statement(), fn description ->
|
assert Graph.get_and_update(graph_with_annotation(), statement(), fn description ->
|
||||||
{description, object_annotation()}
|
{description, description_with_quoted_triple_object()}
|
||||||
end) ==
|
end) ==
|
||||||
{annotation(), Graph.new(init: {statement(), EX.ap(), statement()})}
|
{annotation_description(), Graph.new(init: {statement(), EX.ap(), statement()})}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "pop/2" do
|
test "pop/2" do
|
||||||
assert Graph.pop(graph_with_annotation(), statement()) == {annotation(), graph()}
|
assert Graph.pop(graph_with_annotation(), statement()) == {annotation_description(), graph()}
|
||||||
end
|
end
|
||||||
|
|
||||||
test "subject_count/1" do
|
test "subject_count/1" do
|
||||||
assert Graph.subject_count(graph_with_annotations()) == 2
|
assert Graph.subject_count(graph_with_quoted_triples()) == 2
|
||||||
end
|
end
|
||||||
|
|
||||||
test "subjects/1" do
|
test "subjects/1" do
|
||||||
assert Graph.subjects(graph_with_annotations()) == MapSet.new([statement(), RDF.iri(EX.As)])
|
assert Graph.subjects(graph_with_quoted_triples()) ==
|
||||||
|
MapSet.new([statement(), RDF.iri(EX.As)])
|
||||||
end
|
end
|
||||||
|
|
||||||
test "objects/1" do
|
test "objects/1" do
|
||||||
assert Graph.objects(graph_with_annotations()) == MapSet.new([statement(), EX.ao()])
|
assert Graph.objects(graph_with_quoted_triples()) == MapSet.new([statement(), EX.ao()])
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "statements/1" do
|
describe "statements/1" do
|
||||||
test "without the filter_star flag" do
|
test "without the filter_star flag" do
|
||||||
assert Graph.statements(graph_with_annotations()) == [
|
assert Graph.statements(graph_with_quoted_triples()) == [
|
||||||
star_statement(),
|
star_statement(),
|
||||||
{RDF.iri(EX.As), EX.ap(), statement()}
|
{RDF.iri(EX.As), EX.ap(), statement()}
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "with the filter_star flag" do
|
test "with the filter_star flag" do
|
||||||
assert Graph.statements(graph_with_annotations(), filter_star: true) == []
|
assert Graph.statements(graph_with_quoted_triples(), filter_star: true) == []
|
||||||
assert Graph.statements(graph_with_annotations(), filter_star: true) == []
|
assert Graph.statements(graph_with_quoted_triples(), filter_star: true) == []
|
||||||
|
|
||||||
assert Graph.new(
|
assert Graph.new(
|
||||||
init: [
|
init: [
|
||||||
|
@ -1785,11 +1788,13 @@ defmodule RDF.Star.GraphTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "quoted triples on object position" do
|
test "quoted triples on object position" do
|
||||||
assert Graph.without_annotations(graph_with_annotations()) == RDF.graph(object_annotation())
|
assert Graph.without_annotations(graph_with_quoted_triples()) ==
|
||||||
|
RDF.graph(description_with_quoted_triple_object())
|
||||||
|
|
||||||
assert graph_with_annotations()
|
assert graph_with_quoted_triples()
|
||||||
|> Graph.add(statement())
|
|> Graph.add(statement())
|
||||||
|> Graph.without_annotations() == RDF.graph([statement(), object_annotation()])
|
|> Graph.without_annotations() ==
|
||||||
|
RDF.graph([statement(), description_with_quoted_triple_object()])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1808,29 +1813,29 @@ defmodule RDF.Star.GraphTest do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "quoted triples on object position" do
|
test "quoted triples on object position" do
|
||||||
assert Graph.without_quoted_triples(graph_with_annotations()) == RDF.graph()
|
assert Graph.without_quoted_triples(graph_with_quoted_triples()) == RDF.graph()
|
||||||
|
|
||||||
assert graph_with_annotations()
|
assert graph_with_quoted_triples()
|
||||||
|> Graph.add(statement())
|
|> Graph.add(statement())
|
||||||
|> Graph.without_quoted_triples() == RDF.graph(statement())
|
|> Graph.without_quoted_triples() == RDF.graph(statement())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "include?/3" do
|
test "include?/3" do
|
||||||
assert Graph.include?(graph_with_annotations(), star_statement())
|
assert Graph.include?(graph_with_quoted_triples(), star_statement())
|
||||||
assert Graph.include?(graph_with_annotations(), {EX.As, EX.ap(), statement()})
|
assert Graph.include?(graph_with_quoted_triples(), {EX.As, EX.ap(), statement()})
|
||||||
end
|
end
|
||||||
|
|
||||||
test "describes?/2" do
|
test "describes?/2" do
|
||||||
assert Graph.describes?(graph_with_annotations(), statement())
|
assert Graph.describes?(graph_with_quoted_triples(), statement())
|
||||||
end
|
end
|
||||||
|
|
||||||
test "values/2" do
|
test "values/2" do
|
||||||
assert graph_with_annotations() |> Graph.values() == %{}
|
assert graph_with_quoted_triples() |> Graph.values() == %{}
|
||||||
|
|
||||||
assert Graph.new(
|
assert Graph.new(
|
||||||
init: [
|
init: [
|
||||||
annotation(),
|
annotation_description(),
|
||||||
{EX.s(), EX.p(), ~L"Foo"},
|
{EX.s(), EX.p(), ~L"Foo"},
|
||||||
{EX.s(), EX.ap(), statement()}
|
{EX.s(), EX.ap(), statement()}
|
||||||
]
|
]
|
||||||
|
@ -1848,13 +1853,13 @@ defmodule RDF.Star.GraphTest do
|
||||||
RDF.Term.value(term)
|
RDF.Term.value(term)
|
||||||
end
|
end
|
||||||
|
|
||||||
assert graph_with_annotations() |> Graph.map(mapping) == %{}
|
assert graph_with_quoted_triples() |> Graph.map(mapping) == %{}
|
||||||
|
|
||||||
assert Graph.new([
|
assert Graph.new([
|
||||||
annotation(),
|
annotation_description(),
|
||||||
{EX.s1(), EX.p(), EX.o1()},
|
{EX.s1(), EX.p(), EX.o1()},
|
||||||
{EX.s2(), EX.p(), EX.o2()},
|
{EX.s2(), EX.p(), EX.o2()},
|
||||||
object_annotation()
|
description_with_quoted_triple_object()
|
||||||
])
|
])
|
||||||
|> Graph.map(mapping) ==
|
|> Graph.map(mapping) ==
|
||||||
%{
|
%{
|
||||||
|
|
Loading…
Reference in a new issue