Skip to content

Commit

Permalink
Get the ball rolling on writing tests
Browse files Browse the repository at this point in the history
Separate loading story file and starting state server.
Add test for op_add
  • Loading branch information
daph committed Aug 27, 2016
1 parent 3d0383c commit beef768
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/xyzzy/machine/state.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ defmodule Xyzzy.Machine.State do
static_mem: 0,
high_mem: 0,
dictionary: 0,
object_table: %{},
object_table: 0,
abbr_table: 0,
global_vars: %{},
global_vars: 0,
flags1: 0,
flags2: 0
end
3 changes: 1 addition & 2 deletions lib/xyzzy/machine/state/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ defmodule Xyzzy.Machine.State.Server do

def init(story) do
:rand.seed(:exsplus, :os.timestamp)
state = Xyzzy.Machine.open_story(story)
{:ok, state}
{:ok, story}
end

def handle_call(:pop_stack, _from, state = %State{stack: [h|t]}) do
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ defmodule Xyzzy.Mixfile do
#
# Type "mix help deps" for more examples and options
defp deps do
[{:credo, "~> 0.4", only: [:dev, :test]}]
[]
end
end
2 changes: 0 additions & 2 deletions mix.lock

This file was deleted.

30 changes: 30 additions & 0 deletions test/opcode_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
defmodule OpcodeTest do
alias Xyzzy.Machine.OpFuncs
alias Xyzzy.Machine.OpInfo
alias Xyzzy.Machine.State

use ExUnit.Case
doctest Xyzzy

setup do
{:ok, _pid} = State.Registry.start_link
{:ok, _pid} = State.Supervisor.start_link
:ok
end

test "op_add" do
info = %OpInfo{operands: [2, 2],
next_pc: 0xBEEF,
return_store: 0x02}

state = %State{locals: %{2 => 0}}
State.Supervisor.start_game(state, "op_add_test")

OpFuncs.op_add("op_add_test", info)

state = State.Server.get_state("op_add_test")

assert state.pc == 0xBEEF
assert state.locals |> Map.get(2) == 4
end
end
8 changes: 0 additions & 8 deletions test/xyzzy_test.exs

This file was deleted.

0 comments on commit beef768

Please sign in to comment.