Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support negative integer literals in types #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions lib/spect.ex
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ defmodule Spect do
to_kind!(data, module, type, params)
end

defp to_kind!(data, _module, {:op, _, :-, {:integer, _, value}}, _params) do
to_lit!(data, :integer, -value)
end

defp to_kind!(data, _module, {kind, _line, value}, _params) do
to_lit!(data, kind, value)
end
Expand Down
3 changes: 3 additions & 0 deletions test/spect_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ defmodule Spect.Test do
assert to_spec(1, Specs, :literal_1) === {:ok, 1}
{:error, %ConvertError{}} = to_spec(2, Specs, :literal_1)

assert to_spec(-1, Specs, :literal_minus_1) === {:ok, -1}
{:error, %ConvertError{}} = to_spec(-2, Specs, :literal_minus_1)

assert to_spec([], Specs, :literal_list) === {:ok, []}
{:error, %ConvertError{}} = to_spec(1, Specs, :literal_list)

Expand Down
1 change: 1 addition & 0 deletions test/support/specs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ defmodule Spect.Support.Specs do
@type literal_true :: true
@type literal_false :: false
@type literal_1 :: 1
@type literal_minus_1 :: -1
@type literal_list :: []
@type literal_map :: %{}

Expand Down