Skip to content

Commit

Permalink
WIP - Adds Machine to process a Statechart
Browse files Browse the repository at this point in the history
This adds a test and functionality around processing the basic
Statechart in the first Statifier spec.

Relates #19
  • Loading branch information
johnnyt committed Apr 25, 2020
1 parent f819fb5 commit 7023ee1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
27 changes: 27 additions & 0 deletions statifier-ex/lib/statifier/machine.ex
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
17 changes: 17 additions & 0 deletions statifier-ex/test/statifier/machine_test.exs
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

0 comments on commit 7023ee1

Please sign in to comment.