2016-10-15 16:26:56 +00:00
|
|
|
defmodule RDF.TripleTest do
|
2017-06-16 22:44:11 +00:00
|
|
|
use RDF.Test.Case
|
2016-10-15 16:26:56 +00:00
|
|
|
|
2017-04-10 01:06:20 +00:00
|
|
|
doctest RDF.Triple
|
2018-10-21 22:52:22 +00:00
|
|
|
|
|
|
|
alias RDF.Triple
|
|
|
|
|
|
|
|
describe "values/1" do
|
|
|
|
test "with a valid RDF.Triple" do
|
2020-06-29 08:37:42 +00:00
|
|
|
assert Triple.values({~I<http://example.com/S>, ~I<http://example.com/p>, XSD.integer(42)}) ==
|
|
|
|
{"http://example.com/S", "http://example.com/p", 42}
|
2018-10-21 22:52:22 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "with an invalid RDF.Triple" do
|
|
|
|
refute Triple.values({self(), self(), self()})
|
|
|
|
end
|
|
|
|
end
|
2018-11-04 21:27:25 +00:00
|
|
|
|
2020-10-10 13:45:25 +00:00
|
|
|
describe "values/2" do
|
|
|
|
test "with a valid RDF.Triple and RDF.PropertyMap" do
|
|
|
|
assert Triple.values(
|
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, XSD.integer(42)},
|
2020-10-13 09:38:22 +00:00
|
|
|
context: PropertyMap.new(p: ~I<http://example.com/p>)
|
2020-10-10 13:45:25 +00:00
|
|
|
) ==
|
|
|
|
{"http://example.com/S", :p, 42}
|
|
|
|
|
|
|
|
assert Triple.values(
|
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, XSD.integer(42)},
|
2020-10-13 09:38:22 +00:00
|
|
|
context: [p: ~I<http://example.com/p>]
|
|
|
|
) ==
|
|
|
|
{"http://example.com/S", :p, 42}
|
|
|
|
|
|
|
|
assert Triple.values(
|
|
|
|
{~I<http://example.com/S>, ~I<http://example.com/p>, XSD.integer(42)},
|
|
|
|
context: []
|
2020-10-10 13:45:25 +00:00
|
|
|
) ==
|
|
|
|
{"http://example.com/S", "http://example.com/p", 42}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "with an invalid RDF.Triple" do
|
2020-10-13 09:38:22 +00:00
|
|
|
refute Triple.values({self(), self(), self()}, context: PropertyMap.new())
|
2020-10-10 13:45:25 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "map/2" do
|
2020-05-05 21:58:44 +00:00
|
|
|
assert {~I<http://example.com/S>, ~I<http://example.com/p>, XSD.integer(42)}
|
2020-10-10 13:45:25 +00:00
|
|
|
|> Triple.map(fn
|
2020-06-29 08:37:42 +00:00
|
|
|
{:object, object} -> object |> RDF.Term.value() |> Kernel.+(1)
|
|
|
|
{_, term} -> term |> to_string() |> String.last()
|
|
|
|
end) ==
|
|
|
|
{"S", "p", 43}
|
2018-11-04 21:27:25 +00:00
|
|
|
end
|
2016-10-15 16:26:56 +00:00
|
|
|
end
|