2018-11-04 21:27:25 +00:00
|
|
|
defmodule RDF.StatementTest do
|
|
|
|
use RDF.Test.Case
|
|
|
|
|
|
|
|
doctest RDF.Statement
|
|
|
|
|
2018-11-11 01:30:25 +00:00
|
|
|
describe "valid?/1" do
|
|
|
|
@iri ~I<http://example.com/Foo>
|
|
|
|
@bnode ~B<foo>
|
|
|
|
@valid_literal ~L"foo"
|
2020-05-05 21:58:44 +00:00
|
|
|
@invalid_literal XSD.integer("foo")
|
2018-11-11 01:30:25 +00:00
|
|
|
|
|
|
|
@valid_triples [
|
2020-06-29 08:37:42 +00:00
|
|
|
{@iri, @iri, @iri},
|
2018-11-11 01:30:25 +00:00
|
|
|
{@bnode, @iri, @iri},
|
2020-06-29 08:37:42 +00:00
|
|
|
{@iri, @iri, @bnode},
|
2018-11-11 01:30:25 +00:00
|
|
|
{@bnode, @iri, @bnode},
|
2020-06-29 08:37:42 +00:00
|
|
|
{@iri, @iri, @valid_literal},
|
2018-11-11 01:30:25 +00:00
|
|
|
{@bnode, @iri, @valid_literal},
|
2020-06-29 08:37:42 +00:00
|
|
|
{@iri, @iri, @invalid_literal},
|
|
|
|
{@bnode, @iri, @invalid_literal}
|
2018-11-11 01:30:25 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
@valid_quads [
|
2020-06-29 08:37:42 +00:00
|
|
|
{@iri, @iri, @iri, @iri},
|
|
|
|
{@bnode, @iri, @iri, @iri},
|
|
|
|
{@iri, @iri, @bnode, @iri},
|
|
|
|
{@bnode, @iri, @bnode, @iri},
|
|
|
|
{@iri, @iri, @valid_literal, @iri},
|
|
|
|
{@bnode, @iri, @valid_literal, @iri},
|
|
|
|
{@iri, @iri, @invalid_literal, @iri},
|
|
|
|
{@bnode, @iri, @invalid_literal, @iri}
|
2018-11-11 01:30:25 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
test "valid triples" do
|
2020-06-29 08:37:42 +00:00
|
|
|
Enum.each(@valid_triples, fn argument ->
|
2018-11-11 01:30:25 +00:00
|
|
|
assert RDF.Statement.valid?(argument) == true
|
|
|
|
assert RDF.Triple.valid?(argument) == true
|
|
|
|
refute RDF.Quad.valid?(argument)
|
2020-06-29 08:37:42 +00:00
|
|
|
end)
|
2018-11-11 01:30:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "valid quads" do
|
2020-06-29 08:37:42 +00:00
|
|
|
Enum.each(@valid_quads, fn argument ->
|
2018-11-11 01:30:25 +00:00
|
|
|
assert RDF.Statement.valid?(argument) == true
|
|
|
|
assert RDF.Quad.valid?(argument) == true
|
|
|
|
refute RDF.Triple.valid?(argument)
|
2020-06-29 08:37:42 +00:00
|
|
|
end)
|
2018-11-11 01:30:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "with invalid triples" do
|
|
|
|
[
|
2020-06-29 08:37:42 +00:00
|
|
|
{@iri, @bnode, @iri},
|
|
|
|
{@valid_literal, @iri, @iri},
|
|
|
|
{@iri, @valid_literal, @iri}
|
2018-11-11 01:30:25 +00:00
|
|
|
]
|
|
|
|
|> Enum.each(fn argument ->
|
2020-06-29 08:37:42 +00:00
|
|
|
assert RDF.Statement.valid?(argument) == false
|
|
|
|
assert RDF.Triple.valid?(argument) == false
|
|
|
|
assert RDF.Quad.valid?(argument) == false
|
|
|
|
end)
|
2018-11-11 01:30:25 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "with invalid quads" do
|
|
|
|
[
|
2020-06-29 08:37:42 +00:00
|
|
|
{@iri, @bnode, @iri, @iri},
|
|
|
|
{@iri, @iri, @iri, @bnode},
|
|
|
|
{@valid_literal, @iri, @iri, @iri},
|
|
|
|
{@iri, @valid_literal, @iri, @iri},
|
|
|
|
{@iri, @iri, @iri, @valid_literal}
|
2018-11-11 01:30:25 +00:00
|
|
|
]
|
|
|
|
|> Enum.each(fn argument ->
|
2020-06-29 08:37:42 +00:00
|
|
|
assert RDF.Statement.valid?(argument) == false
|
|
|
|
assert RDF.Triple.valid?(argument) == false
|
|
|
|
assert RDF.Quad.valid?(argument) == false
|
2018-11-11 01:30:25 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with invalid statements by number of elements" do
|
|
|
|
refute RDF.Statement.valid?({@iri, @iri})
|
|
|
|
refute RDF.Triple.valid?({@iri, @iri})
|
|
|
|
refute RDF.Quad.valid?({@iri, @iri})
|
|
|
|
|
|
|
|
refute RDF.Statement.valid?({@iri, @iri, @iri, @iri, @iri})
|
|
|
|
refute RDF.Triple.valid?({@iri, @iri, @iri, @iri, @iri})
|
|
|
|
refute RDF.Quad.valid?({@iri, @iri, @iri, @iri, @iri})
|
|
|
|
|
|
|
|
refute RDF.Triple.valid?({@iri, @iri, @iri, @iri})
|
|
|
|
refute RDF.Quad.valid?({@iri, @iri, @iri})
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with non-tuples" do
|
|
|
|
[
|
|
|
|
42,
|
|
|
|
"foo",
|
|
|
|
@iri,
|
2020-06-29 08:37:42 +00:00
|
|
|
@bnode
|
2018-11-11 01:30:25 +00:00
|
|
|
]
|
|
|
|
|> Enum.each(fn arg ->
|
2020-06-29 08:37:42 +00:00
|
|
|
refute RDF.Statement.valid?(arg)
|
|
|
|
refute RDF.Triple.valid?(arg)
|
|
|
|
refute RDF.Quad.valid?(arg)
|
2018-11-11 01:30:25 +00:00
|
|
|
end)
|
|
|
|
end
|
|
|
|
end
|
2018-11-04 21:27:25 +00:00
|
|
|
end
|