-
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.
WIP - Adds Machine to process a Statechart
This adds a test and functionality around processing the basic Statechart in the first Statifier spec. Relates #19
- Loading branch information
Showing
2 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,29 @@ | ||
defmodule Statifier.Machine do | ||
@moduledoc """ | ||
A reactive system. | ||
This corresponds to the SCXML Interpreter (also called SCXML Processor) | ||
""" | ||
|
||
alias Statifier.{Statechart} | ||
|
||
# This allows code to use the name of the module instead of __MODULE__ | ||
alias __MODULE__ | ||
|
||
# ID of a State | ||
@type state_id :: String.t() | ||
|
||
# The id(s) of the initial state(s) for the document. | ||
# If not specified, the first child state in document order is used. | ||
@type configuration :: [state_id] | ||
|
||
@type t :: %Machine{ | ||
statechart: Statechart.t(), | ||
configuration: configuration | ||
} | ||
|
||
defstruct statechart: nil, | ||
configuration: [] | ||
|
||
def interpret(%Machine{} = machine), do: machine | ||
end |
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 |
---|---|---|
@@ -1,2 +1,19 @@ | ||
defmodule Statifier.MachineTest do | ||
use ExUnit.Case | ||
|
||
alias Statifier.{Machine, Statechart} | ||
|
||
test "initial config of basic statechart" do | ||
test_path = Path.join(File.cwd!(), "test/fixtures/basic.yml") | ||
|
||
{:ok, test_config} = YamlElixir.read_from_file(test_path) | ||
|
||
sc = Statechart.build(test_config["statechart"]) | ||
|
||
machine = | ||
%Machine{statechart: sc} | ||
|> Machine.interpret() | ||
|
||
assert %Machine{configuration: ["greeting"]} = machine | ||
end | ||
end |