2017-02-18 20:35:27 +00:00
|
|
|
defmodule RDF.QuadTest do
|
2017-06-16 22:44:11 +00:00
|
|
|
use RDF.Test.Case
|
2017-04-10 01:06:20 +00:00
|
|
|
|
2017-02-18 20:35:27 +00:00
|
|
|
doctest RDF.Quad
|
2018-10-21 22:52:22 +00:00
|
|
|
|
|
|
|
alias RDF.Quad
|
|
|
|
|
|
|
|
describe "values/1" do
|
|
|
|
test "with a valid RDF.Quad" do
|
2020-06-29 08:37:42 +00:00
|
|
|
assert Quad.values(
|
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, XSD.integer(42),
|
|
|
|
~I<http://example.com/Graph>}
|
|
|
|
) ==
|
|
|
|
{"http://example.com/S", "http://example.com/p", 42, "http://example.com/Graph"}
|
|
|
|
|
|
|
|
assert Quad.values(
|
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, XSD.integer(42), nil}
|
|
|
|
) ==
|
|
|
|
{"http://example.com/S", "http://example.com/p", 42, nil}
|
2018-10-21 22:52:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "with an invalid RDF.Quad" do
|
|
|
|
refute Quad.values({~I<http://example.com/S>, ~I<http://example.com/p>})
|
|
|
|
refute Quad.values({self(), self(), self(), self()})
|
|
|
|
end
|
|
|
|
end
|
2018-11-04 21:27:25 +00:00
|
|
|
|
|
|
|
test "values/2" do
|
2020-06-29 08:37:42 +00:00
|
|
|
assert {~I<http://example.com/S>, ~I<http://example.com/p>, XSD.integer(42),
|
|
|
|
~I<http://example.com/Graph>}
|
2018-11-04 21:27:25 +00:00
|
|
|
|> Quad.values(fn
|
|
|
|
{:subject, subject} -> subject |> to_string() |> String.last() |> String.to_atom()
|
2020-06-29 08:37:42 +00:00
|
|
|
{:predicate, _} -> :p
|
|
|
|
{:object, object} -> object |> RDF.Term.value() |> Kernel.+(1)
|
|
|
|
{:graph_name, _} -> nil
|
|
|
|
end) ==
|
|
|
|
{:S, :p, 43, nil}
|
2018-11-04 21:27:25 +00:00
|
|
|
end
|
2017-02-18 20:35:27 +00:00
|
|
|
end
|