defmodule Temple.Parser.RightArrowTest do
use ExUnit.Case, async: true
alias Temple.Parser.RightArrow
describe "applicable?/1" do
test "returns true when the node contains a right arrow" do
[raw_ast] =
quote do
:bar ->
:bang
end
assert RightArrow.applicable?(raw_ast)
test "returns false when the node is anything other than an anonymous function as an argument to a function" do
raw_asts = [
Temple.div do
"foo"
end,
link to: "/the/route" do
"Label"
]
for raw_ast <- raw_asts do
refute RightArrow.applicable?(raw_ast)
describe "run/2" do
test "adds a node to the buffer" do
:bing ->
:bong
bong =
ast = RightArrow.run(raw_ast)
assert %RightArrow{
elixir_ast: :bing,
children: [
%Temple.Parser.Default{
elixir_ast: ^bong
}
} = ast
describe "to_eex/1" do
test "emits eex" do
result =
|> List.first()
|> RightArrow.run()
|> Temple.Generator.to_eex()
assert result |> :erlang.iolist_to_binary() ==
~s|<% :bing -> %>\n<%= :bong %>\n|