Remove newlines from inspect string of empty descriptions

This commit is contained in:
Marcel Otto 2022-03-30 21:40:18 +02:00
parent 458e5b4540
commit 8dcd949d24
2 changed files with 11 additions and 6 deletions

View file

@ -32,12 +32,16 @@ defimpl Inspect, for: RDF.Description do
header = "#RDF.Description<subject: #{inspect(description.subject)}"
body =
description
|> RDF.Turtle.write_string!(only: :triples, indent: 2)
|> String.trim_trailing()
if Enum.empty?(description) do
header <> ">"
else
body =
description
|> RDF.Turtle.write_string!(only: :triples, indent: 2)
|> String.trim_trailing()
"#{header}\n#{body}#{if limit, do: "..\n..."}\n>"
"#{header}\n#{body}#{if limit, do: "..\n..."}\n>"
end
rescue
caught_exception ->
message =

View file

@ -35,7 +35,8 @@ defmodule RDF.InspectTest do
end
test "it includes the subject when empty" do
assert inspect(Description.new(EX.Foo)) =~ IRI.to_string(EX.Foo)
assert inspect(Description.new(EX.Foo)) =~
"#RDF.Description<subject: #{inspect(RDF.iri(EX.Foo))}>"
end
test "it encodes the RDF-star graphs and descriptions in Turtle-star" do