From e3e712f9ad83fa1968c6fd316372a1b86af3c70a Mon Sep 17 00:00:00 2001 From: Wojtek Mach Date: Wed, 16 Feb 2022 14:43:43 +0000 Subject: [PATCH] Support negative integer literals in types --- lib/spect.ex | 4 ++++ test/spect_test.exs | 3 +++ test/support/specs.ex | 1 + 3 files changed, 8 insertions(+) diff --git a/lib/spect.ex b/lib/spect.ex index d54a774..5b48512 100644 --- a/lib/spect.ex +++ b/lib/spect.ex @@ -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 diff --git a/test/spect_test.exs b/test/spect_test.exs index 4ea4407..dbaf09f 100644 --- a/test/spect_test.exs +++ b/test/spect_test.exs @@ -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) diff --git a/test/support/specs.ex b/test/support/specs.ex index 1ee4b03..f45ca62 100644 --- a/test/support/specs.ex +++ b/test/support/specs.ex @@ -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 :: %{}