Skip to content

Instantly share code, notes, and snippets.

@johnhamelink
Created December 31, 2015 18:57
Show Gist options
  • Save johnhamelink/abfbfe91ef604522a0d2 to your computer and use it in GitHub Desktop.
Save johnhamelink/abfbfe91ef604522a0d2 to your computer and use it in GitHub Desktop.
defmodule FDG.Parsers.GraphvizTest do
use ExSpec, async: true
doctest FDG.Parsers.Graphviz
setup do
on_exit fn ->
# Delete all the test files
Enum.each(["png", "svg", "ps"], fn(fmt) ->
File.rm "graph.#{fmt}"
end)
end
:ok
end
@complex_ast [
{:node, [label: "A", children: [
{:node, [label: "B", children: []]},
{:node, [label: "C", children: []]}
]]}
]
it "Creates hash from label, and adds label to node" do
ast = [{:node, [label: "Lorem Ipsum", children: []]}]
dot_syntax = "digraph G { lorem_ipsum [label=\"Lorem Ipsum\"]; }"
assert FDG.Parsers.Graphviz.to_dot(ast) == dot_syntax
end
it "Parses Tuples into dot syntax recursively" do
dot_syntax = "digraph G { a [label=\"A\"]; b [label=\"B\"]; c [label=\"C\"]; a -> b; a -> c; }"
assert FDG.Parsers.Graphviz.to_dot(@complex_ast) == dot_syntax
end
it "Can produce SVG files using Graphviz's `dot` command" do
assert {:ok, "graph.svg"} = FDG.Parsers.Graphviz.to_dot(@complex_ast)
|> FDG.Parsers.Graphviz.to_svg("graph")
assert File.exists? "graph.svg"
end
it "Can produce PNG files using Graphviz's `dot` command" do
assert {:ok, "graph.png"} = FDG.Parsers.Graphviz.to_dot(@complex_ast)
|> FDG.Parsers.Graphviz.to_png("graph")
assert File.exists? "graph.png"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment