Current section

Files

Jump to
finitomata lib mix tasks test_template.eex
Raw

lib/mix/tasks/test_template.eex

defmodule <%= inspect(@test_module) %> do
use ExUnit.Case
import Finitomata.ExUnit
import Mox
@moduletag :finitomata
<%= for {{path_def, path}, number} <- Enum.with_index(@paths) do %>
describe "<%= path_def |> inspect() |> String.replace(~r/⇥ \"[\w!?]+\" /, "") %>" do
setup_finitomata do
# *************************************
# **** PUT THE INITIALIZATION HERE ****
# *************************************
# **** context example:
parent = self()
[
fsm: [
implementation: <%= inspect(@module) %>,
payload: %{parent: parent},
options: [transition_count: <%= path |> List.flatten() |> length() %>]
],
context: [parent: parent]
]
end
test_path "path #<%= number %>", %{finitomata: %{}, parent: _} = _ctx do
<%= for [{event, state} | states] <- path do %>
<%= if event == :__start__ do %>
:* ->
# these validations allow `assert_payload/2` calls only
#
# also one might pattern match to entry events with payloads directly
# %{finitomata: %{auto_init_msgs: [idle: :foo, started: :bar]} = _ctx
assert_state <%= inspect(state) %> <%= for {_event, state} <- states do %>
assert_state <%= inspect(state) %> do
# assert_payload %{}
end <% end %>
<% else %>
{<%= inspect(event) %>, nil} ->
assert_state <%= inspect(state) %> do
# assert_payload %{foo: :bar}
end
<%= for {_event, state} <- states do %>
assert_state <%= inspect(state) %> do
assert_payload do
# foo.bar.baz ~> ^parent
end
end
<% end %>
<% end %>
<% end %>
end
end <% end %>
end