-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add union_typep/1 macro * Tests, changelog, docs * Add Run tests step to Build CI workflow
- Loading branch information
1 parent
16856b7
commit b02caae
Showing
9 changed files
with
120 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ erl_crash.dump | |
/config/*.secret.exs | ||
.elixir_ls/ | ||
priv/plts | ||
/tmp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) | ||
|
||
## [0.0.3] - 2024-XX-XX | ||
|
||
### Added | ||
|
||
- `UnionTypespec.union_typep/1` macro. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ExUnit.start() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
defmodule UnionTypespecTest do | ||
use ExUnit.Case, async: true | ||
|
||
alias UnionTypespec.Test.SampleModule | ||
|
||
describe "union_type/1" do | ||
test "creates a valid @type from list" do | ||
assert fetch!(:type, :status) == "status() :: :read | :unread | :deleted" | ||
end | ||
end | ||
|
||
describe "union_type_ast/1" do | ||
test "when unquoted in a @type, creates valid value of type" do | ||
assert fetch!(:type, :permission) == "permission() :: :view | :edit | :admin" | ||
end | ||
end | ||
|
||
describe "union_typep/1" do | ||
test "creates a valid @typep from list" do | ||
assert fetch!(:typep, :role) == "role() :: :user | :admin" | ||
end | ||
end | ||
|
||
defp fetch!(type_of_type, type_name) do | ||
assert {:ok, types} = Code.Typespec.fetch_types(SampleModule) | ||
assert {^type_of_type, type} = Enum.find(types, fn {_, {name, _, _}} -> name == type_name end) | ||
|
||
type | ||
|> Code.Typespec.type_to_quoted() | ||
|> Macro.to_string() | ||
end | ||
end |