Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/inspect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defimpl Inspect, for: DG do
[inspect_node(dg, v), "-->", inspect_node(dg, n)]

{_e, ^v, n, label} ->
[inspect_node(dg, v), "--", label, "-->", inspect_node(dg, n)]
[inspect_node(dg, v), "--", inspect_term(label), "-->", inspect_node(dg, n)]
end)
|> Enum.intersperse([line()])
end
Expand Down Expand Up @@ -49,8 +49,11 @@ defimpl Inspect, for: DG do
defp label(dg, v, prefix) do
case :digraph.vertex(dg, v) do
{^v, []} -> [prefix]
{^v, l} -> [prefix, "[", l, "]"]
{^v, l} -> [prefix, "[", inspect_term(l), "]"]
end
|> concat
end

defp inspect_term(term) when is_binary(term), do: term
defp inspect_term(term), do: inspect(term)
end
12 changes: 12 additions & 0 deletions test/dg_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ defmodule DG.Test do
1--one to two-->2[two]
""")
end

test "fancy labels", %{dg: dg} do
DG.add_vertex(dg, 1)
DG.add_vertex(dg, 2, :c.pid(0, 42, 42))
DG.add_edge(dg, 1, 2, :"one to two")

assert inspect(dg) ==
String.trim("""
graph LR
1--:\"one to two\"-->2[#PID<0.42.42>]
""")
end
end

describe "collectable" do
Expand Down