farmbot_os/farmbot_celery_script/test/farmbot_celery_script/ast_test.exs

29 lines
806 B
Elixir

defmodule Farmbot.CeleryScript.ASTTest do
use ExUnit.Case, async: true
alias Farmbot.CeleryScript.AST
@nothing_json "{\"kind\": \"nothing\", \"args\": {}}"
|> Jason.decode!()
@nothing_json_with_body "{\"kind\": \"nothing\", \"args\": {}, \"body\":[#{
Jason.encode!(@nothing_json)
}]}"
|> Jason.decode!()
@bad_json "{\"whoops\": "
test "decodes ast from json" do
res = AST.decode(@nothing_json)
assert match?(%AST{}, res)
end
test "decodes ast with sub asts in the body" do
res = AST.decode(@nothing_json_with_body)
assert match?(%AST{}, res)
end
test "won't decode ast from bad json" do
assert_raise RuntimeError, fn ->
AST.decode(@bad_json)
end
end
end