Add argument to koan to allow it to be tested

This commit is contained in:
Felipe Sere
2016-03-09 23:31:27 +00:00
parent a212f674e0
commit fdb87b529f
5 changed files with 83 additions and 2 deletions

View File

@@ -1,11 +1,17 @@
defmodule Koans do
defmacro koan(name, body) do
compiled_name = String.to_atom(name)
x = quote do: answer
mangled_body = ASTMangler.expand(body, x)
quote do
@koans unquote(compiled_name)
def unquote(compiled_name)() do
def unquote(compiled_name)(answer \\ :nothing) do
try do
unquote(body)
if answer == :nothing do
unquote(body)
else
unquote(mangled_body)
end
:ok
rescue
e in _ -> e