From b4c05d13e01ad19d807328173e16c243dc8ef556 Mon Sep 17 00:00:00 2001 From: Rick Carlino Date: Thu, 28 Mar 2019 11:12:53 -0500 Subject: [PATCH] Test case: passing default value in a sequence --- .../farmbot_celery_script/scheduler_test.exs | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/farmbot_celery_script/test/farmbot_celery_script/scheduler_test.exs b/farmbot_celery_script/test/farmbot_celery_script/scheduler_test.exs index e7334f85..c363f8b0 100644 --- a/farmbot_celery_script/test/farmbot_celery_script/scheduler_test.exs +++ b/farmbot_celery_script/test/farmbot_celery_script/scheduler_test.exs @@ -9,6 +9,66 @@ defmodule FarmbotCeleryScript.SchedulerTest do [shim: shim, sch: sch] end + test "uses default values when no parameter is found", %{sch: sch} do + sequence_ast = + %{ + kind: :sequence, + args: %{ + version: 1, + locals: %{ + kind: :scope_declaration, + args: %{}, + body: [ + %{ + kind: :parameter_declaration, + args: %{ + label: "foo", + default_value: %{ + kind: :coordinate, + args: %{x: 129, y: 129, z: 129} + } + } + } + ] + } + }, + body: [ + %{ + kind: :move_absolute, + args: %{ + speed: 921, + location: %{ + kind: :identifier, + args: %{label: "foo"} + }, + offset: %{ + kind: :coordinate, + args: %{x: 0, y: 0, z: 0} + } + } + } + ] + } + |> AST.decode() + + executed = Compiler.compile(sequence_ast) + me = self() + + :ok = + TestSysCalls.handle(TestSysCalls, fn + :move_absolute, args -> + send(me, {:move_absolute, args}) + :ok + + :coordinate, [x, y, z] -> + %{x: x, y: y, z: z} + end) + + {:ok, execute_ref} = Scheduler.schedule(sch, executed) + assert_receive {Scheduler, ^execute_ref, :ok} + assert_receive {:move_absolute, [129, 129, 129, 921]} + end + test "syscall errors", %{sch: sch} do execute_ast = %{ @@ -274,7 +334,7 @@ defmodule FarmbotCeleryScript.SchedulerTest do task_1 = Task.async(fn -> {:ok, schedule_ref_1} = Scheduler.schedule(sch, schedule_1) - # TODO(Connor) Literally any function call will + # TODO(Connor) Literally any function call will # make this not a race condition??? IO.inspect(schedule_ref_1, label: "task_1") assert_receive {Scheduler, ^schedule_ref_1, :ok}, 3000