70 lines
1.7 KiB
Elixir
70 lines
1.7 KiB
Elixir
defmodule Temple.Parser.AnonymousFunctionsTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias Temple.Parser.AnonymousFunctions
|
|
|
|
describe "applicable?/1" do
|
|
test "returns true when the node contains an anonymous function as an argument to a function" do
|
|
raw_asts = [
|
|
quote do
|
|
form_for changeset, Routes.foo_path(conn, :create), fn form ->
|
|
Does.something!(form)
|
|
end
|
|
end
|
|
]
|
|
|
|
for raw_ast <- raw_asts do
|
|
assert AnonymousFunctions.applicable?(raw_ast)
|
|
end
|
|
end
|
|
|
|
test "returns false when the node is anything other than an anonymous function as an argument to a function" do
|
|
raw_asts = [
|
|
quote do
|
|
Temple.div do
|
|
"foo"
|
|
end
|
|
end,
|
|
quote do
|
|
link to: "/the/route" do
|
|
"Label"
|
|
end
|
|
end
|
|
]
|
|
|
|
for raw_ast <- raw_asts do
|
|
refute AnonymousFunctions.applicable?(raw_ast)
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "run/2" do
|
|
test "adds a node to the buffer" do
|
|
expected_child =
|
|
quote do
|
|
Does.something!(form)
|
|
end
|
|
|
|
raw_ast =
|
|
quote do
|
|
form_for changeset, Routes.foo_path(conn, :create), fn form ->
|
|
unquote(expected_child)
|
|
end
|
|
end
|
|
|
|
ast = AnonymousFunctions.run(raw_ast)
|
|
|
|
assert %Temple.Ast{
|
|
meta: %{type: :anonymous_functions},
|
|
content: _,
|
|
children: [
|
|
%Temple.Ast{
|
|
meta: %{type: :default},
|
|
content: ^expected_child,
|
|
children: []
|
|
}
|
|
]
|
|
} = ast
|
|
end
|
|
end
|
|
end
|