diff --git a/config/.credo.exs b/.credo.exs similarity index 100% rename from config/.credo.exs rename to .credo.exs diff --git a/.gitignore b/.gitignore index f6278de..38b9586 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,4 @@ erl_crash.dump *.ez *.beam .DS_Store -mix.lock .mix diff --git a/.tool-versions b/.tool-versions index d5fb44a..05efa3e 100644 --- a/.tool-versions +++ b/.tool-versions @@ -1,2 +1,2 @@ -erlang 22.0.5 -elixir 1.9.4 +erlang 24.2 +elixir 1.13.2 \ No newline at end of file diff --git a/config/config.exs b/config/config.exs deleted file mode 100644 index 285785c..0000000 --- a/config/config.exs +++ /dev/null @@ -1,30 +0,0 @@ -# This file is responsible for configuring your application -# and its dependencies with the aid of the Mix.Config module. -use Mix.Config - -# This configuration is loaded before any dependency and is restricted -# to this project. If another project depends on this project, this -# file won't be loaded nor affect the parent project. For this reason, -# if you want to provide default values for your application for -# 3rd-party users, it should be done in your "mix.exs" file. - -# You can configure for your application as: -# -# config :algae, key: :value -# -# And access this configuration in your application as: -# -# Application.get_env(:algae, :key) -# -# Or configure a 3rd-party app: -# -# config :logger, level: :info -# - -# It is also possible to import configuration files, relative to this -# directory. For example, you can emulate configuration per environment -# by uncommenting the line below and defining dev.exs, test.exs and such. -# Configuration from the imported file will override the ones defined -# here (which is why it is important to import them last). -# -# import_config "#{Mix.env}.exs" diff --git a/lib/algae/reader.ex b/lib/algae/reader.ex index b91a173..5e36724 100644 --- a/lib/algae/reader.ex +++ b/lib/algae/reader.ex @@ -12,21 +12,21 @@ defmodule Algae.Reader do iex> use Witchcraft ...> - ...> correct = + iex> correct = ...> monad %Algae.Reader{} do ...> count <- ask &Map.get(&1, :count) ...> bindings <- ask() - ...> return (count == Map.size(bindings)) + ...> return (count == map_size(bindings)) ...> end ...> - ...> sample_bindings = %{count: 3, a: 1, b: 2} - ...> correct_count = run(correct, sample_bindings) - ...> "Correct count for #{inspect sample_bindings}? #{correct_count}" + iex> sample_bindings = %{count: 3, a: 1, b: 2} + iex> correct_count = run(correct, sample_bindings) + iex> "Correct count for #{inspect sample_bindings}? #{correct_count}" "Correct count for %{a: 1, b: 2, count: 3}? true" ...> - ...> bad_bindings = %{count: 100, a: 1, b: 2} - ...> bad_count = run(correct, bad_bindings) - ...> "Correct count for #{inspect bad_bindings}? #{bad_count}" + iex> bad_bindings = %{count: 100, a: 1, b: 2} + iex> bad_count = run(correct, bad_bindings) + iex> "Correct count for #{inspect bad_bindings}? #{bad_count}" "Correct count for %{a: 1, b: 2, count: 100}? false" Example adapted from diff --git a/lib/algae/state.ex b/lib/algae/state.ex index a9b5366..eee13df 100644 --- a/lib/algae/state.ex +++ b/lib/algae/state.ex @@ -76,7 +76,7 @@ defmodule Algae.State do defstruct [runner: &State.default/1] @spec default(any()) :: {integer(), any()} - defp default(s), do: {s, s} + def default(s), do: {s, s} @doc """ Construct a new `Algae.State` struct from a state runner in the form diff --git a/mix.exs b/mix.exs index 5664d58..b16a55c 100644 --- a/mix.exs +++ b/mix.exs @@ -6,10 +6,12 @@ defmodule Algae.Mixfile do app: :algae, aliases: aliases(), deps: deps(), + preferred_cli_env: [quality: :test], # Versions - version: "1.3.0", + version: "1.3.1", elixir: "~> 1.9", + elixirc_paths: elixirc_paths(Mix.env()), # Docs name: "Algae", @@ -30,6 +32,9 @@ defmodule Algae.Mixfile do ] end + defp elixirc_paths(:test), do: ["lib", "test/support"] + defp elixirc_paths(_), do: ["lib"] + defp deps do [ {:credo, "~> 1.5", only: [:dev, :test], runtime: false}, diff --git a/mix.lock b/mix.lock new file mode 100644 index 0000000..2e8e459 --- /dev/null +++ b/mix.lock @@ -0,0 +1,21 @@ +%{ + "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, + "credo": {:hex, :credo, "1.6.2", "2f82b29a47c0bb7b72f023bf3a34d151624f1cbe1e6c4e52303b05a11166a701", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "ae9dc112bc368e7b145c547bec2ed257ef88955851c15057c7835251a17211c6"}, + "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, + "earmark": {:hex, :earmark, "1.4.20", "d5097b1c7417a03c73a2985fcf01c3f72192c427b8a498719737dca5273938cb", [:mix], [{:earmark_parser, "== 1.4.18", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "7be744242dbde74c858279f4a65d9d31f37d163190d739340015c30038c1edb3"}, + "earmark_parser": {:hex, :earmark_parser, "1.4.18", "e1b2be73eb08a49fb032a0208bf647380682374a725dfb5b9e510def8397f6f2", [:mix], [], "hexpm", "114a0e85ec3cf9e04b811009e73c206394ffecfcc313e0b346de0d557774ee97"}, + "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, + "ex_doc": {:hex, :ex_doc, "0.26.0", "1922164bac0b18b02f84d6f69cab1b93bc3e870e2ad18d5dacb50a9e06b542a3", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "2775d66e494a9a48355db7867478ffd997864c61c65a47d31c4949459281c78d"}, + "exceptional": {:hex, :exceptional, "2.1.3", "cb17cb9b7c4882e763b82db08ba317678157ca95970fae96b31b3c90f5960c3d", [:mix], [], "hexpm", "59d67ae2df6784e7a957087742ae9011f220c3d1523706c5cd7ee0741bca5897"}, + "file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"}, + "inch_ex": {:hex, :inch_ex, "2.0.0", "24268a9284a1751f2ceda569cd978e1fa394c977c45c331bb52a405de544f4de", [:mix], [{:bunt, "~> 0.2", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "96d0ec5ecac8cf63142d02f16b7ab7152cf0f0f1a185a80161b758383c9399a8"}, + "jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"}, + "makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.15.2", "dc72dfe17eb240552857465cc00cce390960d9a0c055c4ccd38b70629227e97c", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "fd23ae48d09b32eff49d4ced2b43c9f086d402ee4fd4fcb2d7fad97fa8823e75"}, + "makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"}, + "nimble_parsec": {:hex, :nimble_parsec, "1.2.1", "264fc6864936b59fedb3ceb89998c64e9bb91945faf1eb115d349b96913cc2ef", [:mix], [], "hexpm", "23c31d0ec38c97bf9adde35bc91bc8e1181ea5202881f48a192f4aa2d2cf4d59"}, + "operator": {:hex, :operator, "0.2.1", "4572312bbd3e63a5c237bf15c3a7670d568e3651ea744289130780006e70e5f5", [:mix], [], "hexpm", "1990cc6dc651d7fff04636eef06fc64e6bc1da83a1da890c08ca3432e17e267a"}, + "quark": {:hex, :quark, "2.3.2", "066e0d431440d077684469967f54d732443ea2a48932e0916e974633e8b39c95", [:mix], [], "hexpm", "2f6423779b02afe7e3e4af3cfecfcd94572f2051664d4d8329ffa872d24b10a8"}, + "type_class": {:hex, :type_class, "1.2.8", "349db84be8c664e119efaae1a09a44b113bc8e81af1d032f4e3e38feef4fac32", [:mix], [{:exceptional, "~> 2.1", [hex: :exceptional, repo: "hexpm", optional: false]}], "hexpm", "bb93de2cacfd6f0ee43f4616f7a139816a73deba4ae8ee3364bcfa4abe3eef3e"}, + "witchcraft": {:hex, :witchcraft, "1.0.4", "8733ac0ee769d4d2f73610de5a2b601a4ccbe385d1fca6419280f2511d21d0c9", [:mix], [{:exceptional, "~> 2.1", [hex: :exceptional, repo: "hexpm", optional: false]}, {:operator, "~> 0.2", [hex: :operator, repo: "hexpm", optional: false]}, {:quark, "~> 2.2", [hex: :quark, repo: "hexpm", optional: false]}, {:type_class, "~> 1.2", [hex: :type_class, repo: "hexpm", optional: false]}], "hexpm", "a380f439f1962d2e56cdad874ed7eb4612ddd6ec5ee3c6ad0c5d63e60539e6b0"}, +} diff --git a/test/support.exs b/test/support/example.ex similarity index 89% rename from test/support.exs rename to test/support/example.ex index d6b70fe..70c5164 100644 --- a/test/support.exs +++ b/test/support/example.ex @@ -1,6 +1,8 @@ import Algae defmodule Example do + @moduledoc false + defdata Complex :: ([{:ok, integer()}] | number()) \\ 22 defdata Any :: any() @@ -8,10 +10,14 @@ defmodule Example do defdata None :: none() defmodule Embedded.One do + @moduledoc false + defdata do: quux :: any() \\ 22 end defmodule Embedded.Many do + @moduledoc false + defdata do first :: any() second :: integer() \\ 42 @@ -25,10 +31,14 @@ defmodule Example do end defmodule Simple do + @moduledoc false + defdata any() end defmodule Sum.Lights do + @moduledoc false + defsum do defdata Red :: any() \\ 22 defdata Yellow :: any() @@ -37,6 +47,8 @@ defmodule Example do end defmodule Sum.Maybe do + @moduledoc false + defsum do defdata Just do value :: any() @@ -47,6 +59,8 @@ defmodule Example do end defmodule Player do + @moduledoc false + # =============== # # Data Definition # # =============== # @@ -72,12 +86,16 @@ defmodule Example do end defmodule Id do + @moduledoc false + defdata any() end defdata Wrapper :: any() defmodule Person do + @moduledoc false + defdata do name :: String.t() age :: non_neg_integer() @@ -85,6 +103,8 @@ defmodule Example do end defmodule Animal do + @moduledoc false + defdata do name :: String.t() leg_count :: non_neg_integer() \\ 4 @@ -96,16 +116,22 @@ defmodule Example do end defmodule Constant do + @moduledoc false + defdata fun() def new(value), do: %Constant{constant: fn _ -> value end} end defmodule Nothing do + @moduledoc false + defdata none() end defmodule Light do + @moduledoc false + # ============== # # Sum Definition # # ============== # @@ -127,6 +153,8 @@ defmodule Example do end defmodule Pet do + @moduledoc false + defsum do defdata Cat do name :: String.t() @@ -141,6 +169,8 @@ defmodule Example do end defmodule Option do + @moduledoc false + defsum do defdata None :: none() defdata Some :: any() @@ -151,6 +181,8 @@ defmodule Example do defdata Video :: String.t() \\ "2001: A Space Odyssey" defmodule Media do + @moduledoc false + defsum do defdata Paper :: Example.Book.t() \\ Example.Book.new() defdata Film :: Example.Video.t() \\ Example.Video.new("A Clockwork Orange") diff --git a/test/test_helper.exs b/test/test_helper.exs index 5d2d1e4..869559e 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -1,2 +1 @@ ExUnit.start() -Code.load_file("test/support.exs")