Skip to content

Commit

Permalink
Add exception parsing. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
asummers authored Nov 7, 2018
1 parent 464e522 commit cd0aad5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dialyzer.ignore_warnings.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
{"lib/erlex.ex", :no_return, 140},
{"lib/erlex.ex", :no_return, 159},
{"lib/erlex.ex", :no_return, 180},
{"lib/erlex.ex", :no_return, 536},
{"lib/erlex.ex", :no_return, 547},
]
11 changes: 11 additions & 0 deletions lib/erlex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,17 @@ defmodule Erlex do
"struct()"
end

defp do_pretty_print(
{:map,
[
{:map_entry, {:atom, '\'__exception__\''}, {:atom, '\'true\''}},
{:map_entry, {:atom, '\'__struct__\''}, {:atom, [:_]}},
{:map_entry, {:atom, [:_]}, {:atom, [:_]}}
]}
) do
"Exception.t()"
end

defp do_pretty_print({:map, map_keys}) do
%{struct_name: struct_name, entries: entries} = struct_parts(map_keys)

Expand Down
11 changes: 11 additions & 0 deletions test/pretty_print_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -562,4 +562,15 @@ defmodule Erlex.Test.PretyPrintTest do
expected_output = "_ :: <<_::1>>"
assert pretty_printed == expected_output
end

test "Exceptions are pretty printed appropriately" do
input = ~S"""
(__@5::#{'__exception__':='true', '__struct__':=_, _=>_})
"""

pretty_printed = Erlex.pretty_print_contract(input)

expected_output = "(_ :: Exception.t())"
assert pretty_printed == expected_output
end
end

0 comments on commit cd0aad5

Please sign in to comment.