Get rid of the koan prefix
This commit is contained in:
@@ -8,7 +8,7 @@ defmodule Display do
|
|||||||
IO.puts("Now meditate upon #{display_module(module)}")
|
IO.puts("Now meditate upon #{display_module(module)}")
|
||||||
IO.puts("---------------------------------------")
|
IO.puts("---------------------------------------")
|
||||||
IO.puts(format_cyan(last_failure_location))
|
IO.puts(format_cyan(last_failure_location))
|
||||||
IO.puts(display_koan(name))
|
IO.puts(name)
|
||||||
IO.puts(format_red(Macro.to_string(expr)))
|
IO.puts(format_red(Macro.to_string(expr)))
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -55,8 +55,4 @@ defmodule Display do
|
|||||||
defp display_module(module) do
|
defp display_module(module) do
|
||||||
Module.split(module) |> List.last
|
Module.split(module) |> List.last
|
||||||
end
|
end
|
||||||
|
|
||||||
defp display_koan(name) do
|
|
||||||
String.replace(to_string(name), Koans.prefix, "")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
13
lib/koans.ex
13
lib/koans.ex
@@ -1,9 +1,6 @@
|
|||||||
defmodule Koans do
|
defmodule Koans do
|
||||||
@prefix "koan: "
|
|
||||||
|
|
||||||
defmacro koan(name, body) do
|
defmacro koan(name, body) do
|
||||||
compiled_name = :"#{prefix}#{name}"
|
compiled_name = String.to_atom(name)
|
||||||
|
|
||||||
quote do
|
quote do
|
||||||
@koans unquote(compiled_name)
|
@koans unquote(compiled_name)
|
||||||
def unquote(compiled_name)() do
|
def unquote(compiled_name)() do
|
||||||
@@ -24,16 +21,10 @@ defmodule Koans do
|
|||||||
import Koans
|
import Koans
|
||||||
import BlankAssertions
|
import BlankAssertions
|
||||||
|
|
||||||
@before_compile KoansBuilder
|
@before_compile Koans
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def prefix do
|
|
||||||
@prefix
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
defmodule KoansBuilder do
|
|
||||||
defmacro __before_compile__(env) do
|
defmacro __before_compile__(env) do
|
||||||
koans = Module.get_attribute(env.module, :koans) |> Enum.reverse
|
koans = Module.get_attribute(env.module, :koans) |> Enum.reverse
|
||||||
quote do
|
quote do
|
||||||
|
|||||||
@@ -28,8 +28,7 @@ defmodule Runner do
|
|||||||
def run_module(module) do
|
def run_module(module) do
|
||||||
Display.considering(module)
|
Display.considering(module)
|
||||||
|
|
||||||
koans = extract_koans_from(module)
|
koans = module.all_koans
|
||||||
|
|
||||||
passed = Enum.take_while(koans, fn(name) ->
|
passed = Enum.take_while(koans, fn(name) ->
|
||||||
run_koan(module, name) == :passed
|
run_koan(module, name) == :passed
|
||||||
end)
|
end)
|
||||||
@@ -49,13 +48,4 @@ defmodule Runner do
|
|||||||
:failed
|
:failed
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
defp extract_koans_from(module) do
|
|
||||||
module.all_koans
|
|
||||||
|> Enum.filter(&koan?/1)
|
|
||||||
end
|
|
||||||
|
|
||||||
defp koan?(fun_name) do
|
|
||||||
String.starts_with?(to_string(fun_name), Koans.prefix)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user