defmodule Temple.Parser.DoExpressionsTest do
use ExUnit.Case, async: true
alias Temple.Parser.DoExpressions
describe "applicable?/1" do
test "returns true when the node contains a do expression" do
raw_ast =
quote do
for big <- boys do
"bob"
end
assert DoExpressions.applicable?(raw_ast)
describe "run/2" do
test "adds a node to the buffer" do
ast = DoExpressions.run(raw_ast)
assert %DoExpressions{
content: _,
children: [
[%Temple.Parser.Text{content: "bob", children: []}], nil
]
} = ast
describe "to_eex/1" do
test "emits eex" do
result =
|> DoExpressions.run()
|> Temple.EEx.to_eex()
assert result |> :erlang.iolist_to_binary() ==
~s|<%= for(big <- boys) do %>\nbob\n<% end %>|
test "emits eex for that includes in else clause" do
if foo? do
else
"carol"
~s|<%= if(foo?) do %>\nbob\n<% else %>\ncarol\n<% end %>|