Skip to content

Commit e52bb3a

Browse files
committed
WIP
1 parent ab42f01 commit e52bb3a

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

test/ham/utils_test.exs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,24 @@ defmodule Ham.UtilsTest do
22
use ExUnit.Case, async: true
33
alias Ham.Utils
44

5+
defp fetch_test_type(type_name) do
6+
{:ok, types} =
7+
Code.Typespec.fetch_types(Ham.Test.TestModule)
8+
9+
Enum.find_value(types, fn
10+
{:type, {^type_name, type, _}} -> type
11+
_ -> nil
12+
end)
13+
end
14+
515
describe "type_to_string/1" do
616
test "complex type" do
7-
{:ok, [type: {:complex_with_name, type_with_name, _}, type: {:complex, type, _}]} =
8-
Code.Typespec.fetch_types(Complex)
9-
10-
assert Utils.type_to_string(type) ==
17+
assert :complex |> fetch_test_type() |> Utils.type_to_string() ==
1118
"{:ok, binary(), req :: binary()} | {:more, binary(), req :: binary()}"
19+
end
1220

13-
assert Utils.type_to_string(type_with_name) ==
21+
test "complex type with annotation" do
22+
assert :complex_annotated |> fetch_test_type() |> Utils.type_to_string() ==
1423
"{:ok, binary(), req :: binary()} | {:more, binary(), req :: binary()} (\"result\")"
1524
end
1625
end

test/support/module.ex

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,13 @@ defmodule Ham.Test.TestModule do
244244
@spec map_type_with_underscore() :: :test.req()
245245
def map_type_with_underscore, do: %{method: "GET"}
246246

247-
@spec foo_multiple_options_annotated ::
247+
@type complex :: {:ok, binary(), req :: binary()} | {:more, binary(), req :: binary()}
248+
@type complex_annotated ::
248249
result :: {:ok, binary(), req :: binary()} | {:more, binary(), req :: binary()}
250+
251+
@spec foo_multiple_options_annotated :: complex_annotated
249252
def foo_multiple_options_annotated, do: {:ok, "a", "b"}
250253

251-
@spec foo_multiple_options ::
252-
result :: {:ok, binary(), req :: binary()} | {:more, binary(), req :: binary()}
254+
@spec foo_multiple_options :: complex
253255
def foo_multiple_options, do: {:ok, "a", "b"}
254256
end
255-
256-
defmodule Complex do
257-
@type complex :: {:ok, binary(), req :: binary()} | {:more, binary(), req :: binary()}
258-
@type complex_with_name ::
259-
result :: {:ok, binary(), req :: binary()} | {:more, binary(), req :: binary()}
260-
end

0 commit comments

Comments
 (0)