2020-11-02 14:17:18 +00:00
|
|
|
defmodule RDF.InspectTest do
|
|
|
|
use RDF.Test.Case
|
|
|
|
|
|
|
|
alias RDF.Turtle
|
|
|
|
alias RDF.NS.RDFS
|
|
|
|
|
|
|
|
@test_description EX.S
|
|
|
|
|> RDF.type(RDFS.Class)
|
|
|
|
|> EX.p("foo", 42)
|
|
|
|
|
|
|
|
@test_graph Graph.new(
|
|
|
|
[
|
|
|
|
EX.S1
|
|
|
|
|> EX.p1(EX.O1)
|
|
|
|
|> EX.p2("foo", 42),
|
|
|
|
EX.S2
|
|
|
|
|> EX.p3(EX.O3)
|
|
|
|
],
|
|
|
|
prefixes: [ex: EX]
|
|
|
|
)
|
|
|
|
|
|
|
|
describe "RDF.Description" do
|
|
|
|
test "it includes a header" do
|
|
|
|
{header, _} = inspect_parts(@test_description)
|
2021-02-28 12:29:10 +00:00
|
|
|
assert header == "#RDF.Description<"
|
2020-11-02 14:17:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it encodes the description in Turtle" do
|
|
|
|
{_, body} = inspect_parts(@test_description)
|
|
|
|
|
|
|
|
assert body ==
|
2021-02-28 12:29:10 +00:00
|
|
|
" " <>
|
|
|
|
(Turtle.write_string!(@test_description, only: :triples, indent: 2)
|
|
|
|
|> String.trim()) <> "\n>"
|
2020-11-02 14:17:18 +00:00
|
|
|
end
|
|
|
|
|
2021-10-09 14:40:07 +00:00
|
|
|
test "it encodes the RDF-star graphs ands descriptions in Turtle-star" do
|
|
|
|
{_, triples} = inspect_parts(annotation(), limit: 2)
|
|
|
|
assert triples =~ "<< <http://example.com/S> <http://example.com/P> \"Foo\" >>"
|
|
|
|
end
|
|
|
|
|
2020-11-02 14:17:18 +00:00
|
|
|
test ":limit option" do
|
|
|
|
{_, triples} = inspect_parts(@test_description, limit: 2)
|
|
|
|
|
|
|
|
assert triples ==
|
2021-02-28 12:29:10 +00:00
|
|
|
" " <>
|
|
|
|
(EX.S
|
|
|
|
|> EX.p("foo", 42)
|
|
|
|
|> Turtle.write_string!(only: :triples, indent: 2)
|
|
|
|
|> String.trim()) <>
|
|
|
|
"..\n...\n>"
|
2020-11-02 14:17:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "RDF.Graph" do
|
|
|
|
test "it includes a header with the graph name" do
|
|
|
|
{header, _} = inspect_parts(@test_graph)
|
2021-02-28 12:29:10 +00:00
|
|
|
assert header == "#RDF.Graph<name: nil"
|
2020-11-02 14:17:18 +00:00
|
|
|
|
|
|
|
graph_name = RDF.iri(EX.Graph)
|
|
|
|
{header, _} = @test_graph |> Graph.change_name(graph_name) |> inspect_parts()
|
2021-02-28 12:29:10 +00:00
|
|
|
assert header == "#RDF.Graph<name: #{inspect(graph_name)}"
|
2020-11-02 14:17:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "it encodes the graph in Turtle" do
|
|
|
|
{_, body} = inspect_parts(@test_graph)
|
2021-02-28 12:29:10 +00:00
|
|
|
|
|
|
|
assert body ==
|
|
|
|
" " <>
|
|
|
|
(Turtle.write_string!(@test_graph, indent: 2) |> String.trim()) <> "\n>"
|
2020-11-02 14:17:18 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test ":limit option" do
|
|
|
|
{_, body} = inspect_parts(@test_graph, limit: 2)
|
|
|
|
|
|
|
|
assert body ==
|
2021-02-28 12:29:10 +00:00
|
|
|
" " <>
|
|
|
|
(Graph.new(
|
|
|
|
EX.S1
|
|
|
|
|> EX.p1(EX.O1)
|
|
|
|
|> EX.p2(42),
|
|
|
|
prefixes: [ex: EX]
|
|
|
|
)
|
|
|
|
|> Turtle.write_string!(indent: 2)
|
|
|
|
|> String.trim()) <>
|
|
|
|
"..\n...\n>"
|
2020-11-02 14:17:18 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect_parts(graph, opts \\ []) do
|
|
|
|
inspect_form = inspect(graph, opts)
|
|
|
|
[header, body] = String.split(inspect_form, "\n", parts: 2)
|
|
|
|
{header, body}
|
|
|
|
end
|
|
|
|
end
|