Add missing files
This commit is contained in:
parent
da66b35ce5
commit
141063177f
10
lib/farmbot/celery_script/ast/node/scope_decleration.ex
Normal file
10
lib/farmbot/celery_script/ast/node/scope_decleration.ex
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
defmodule Farmbot.CeleryScript.AST.Node.ScopeDeclaration do
|
||||||
|
@moduledoc false
|
||||||
|
use Farmbot.CeleryScript.AST.Node
|
||||||
|
allow_args []
|
||||||
|
|
||||||
|
def execute(_, _, env) do
|
||||||
|
env = mutate_env(env)
|
||||||
|
{:ok, env}
|
||||||
|
end
|
||||||
|
end
|
85
test/farmbot/celery_script/ast/heap_test.exs
Normal file
85
test/farmbot/celery_script/ast/heap_test.exs
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
defmodule Farmbot.CeleryScript.AST.HeapTest do
|
||||||
|
use ExUnit.Case
|
||||||
|
alias Farmbot.CeleryScript.AST
|
||||||
|
alias AST.Heap
|
||||||
|
alias AST.Heap.Address
|
||||||
|
|
||||||
|
describe "Address" do
|
||||||
|
test "inspect gives nice stuff" do
|
||||||
|
assert inspect(Address.new(100)) == "HeapAddress(100)"
|
||||||
|
end
|
||||||
|
|
||||||
|
test "increments an address" do
|
||||||
|
base = Address.new(123)
|
||||||
|
assert Address.inc(base) == Address.new(124)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "decrements an address" do
|
||||||
|
base = Address.new(123)
|
||||||
|
assert Address.dec(base) == Address.new(122)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
test "initializes a new heap" do
|
||||||
|
heap = Heap.new()
|
||||||
|
assert is_null?(heap.here)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
test "alots one kind on the heap" do
|
||||||
|
heap = Heap.new()
|
||||||
|
aloted = Heap.alot(heap, "abc")
|
||||||
|
assert aloted.here == Address.new(1)
|
||||||
|
assert match?(%{:"🔗kind" => "abc"}, aloted.entries[Address.new(1)])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Heap access with address" do
|
||||||
|
heap =
|
||||||
|
Heap.new()
|
||||||
|
|> Heap.alot("abc")
|
||||||
|
|> Heap.alot("def")
|
||||||
|
|> Heap.alot("ghi")
|
||||||
|
assert is_null?(heap.entries[Address.new(0)])
|
||||||
|
assert match?(%{:"🔗kind" => "abc"}, heap.entries[Address.new(1)])
|
||||||
|
assert match?(%{:"🔗kind" => "def"}, heap.entries[Address.new(2)])
|
||||||
|
assert match?(%{:"🔗kind" => "ghi"}, heap.entries[Address.new(3)])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "puts a key value pair on an existing aloted slot" do
|
||||||
|
heap =
|
||||||
|
Heap.new()
|
||||||
|
|> Heap.alot("abc")
|
||||||
|
|> Heap.put("key", "value")
|
||||||
|
assert match?(%{:"🔗kind" => "abc", key: "value"}, heap.entries[Address.new(1)])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Puts key/value pairs at arbitrary addresses" do
|
||||||
|
heap =
|
||||||
|
Heap.new()
|
||||||
|
|> Heap.alot("abc")
|
||||||
|
|> Heap.alot("def")
|
||||||
|
|> Heap.alot("ghi")
|
||||||
|
mutated = Heap.put(heap, Address.new(2), "abc_key", "value")
|
||||||
|
assert match?(%{:"🔗kind" => "def", abc_key: "value"}, mutated.entries[Address.new(2)])
|
||||||
|
end
|
||||||
|
|
||||||
|
test "Can't update on bad a address" do
|
||||||
|
heap =
|
||||||
|
Heap.new()
|
||||||
|
|> Heap.alot("abc")
|
||||||
|
|> Heap.alot("def")
|
||||||
|
|> Heap.alot("ghi")
|
||||||
|
assert_raise RuntimeError, fn() ->
|
||||||
|
Heap.put(heap, Address.new(200), "abc_key", "value")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
defp is_null?(%Address{value: 0}), do: true
|
||||||
|
defp is_null?(%Address{value: _}), do: false
|
||||||
|
defp is_null?(%{"🔗body": %Address{value: 0},
|
||||||
|
"🔗kind": Farmbot.CeleryScript.AST.Node.Nothing,
|
||||||
|
"🔗next": %Address{value: 0},
|
||||||
|
"🔗parent": %Address{value: 0} }), do: true
|
||||||
|
defp is_null?(_), do: false
|
||||||
|
end
|
Loading…
Reference in a new issue