This repository has been archived on 2023-08-07. You can view files and clone it, but cannot push or open issues or pull requests.
temple/test/parser/do_expressions_test.exs
Mitchell Hanberg c965048f40
Better whitespace handling and control (#145)
* Fine tune whitespace

The EEx outut now emits more human-readable and predictable formatting.
This includes proper indenting, at least for each "root" template.

* Internal whitespace control

You can now use a bang version of any nonvoid tag to emit the markup
witout the internal whitespace. This means that there will not be a
newline emitted after the opening tag and before the closing tag.
2021-08-29 17:45:07 -04:00

109 lines
2.2 KiB
Elixir

defmodule Temple.Parser.DoExpressionsTest do
use ExUnit.Case, async: true
alias Temple.Parser.DoExpressions
alias Temple.Support.Utils
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
end
assert DoExpressions.applicable?(raw_ast)
end
end
describe "run/2" do
test "adds a node to the buffer" do
raw_ast =
quote do
for big <- boys do
"bob"
end
end
ast = DoExpressions.run(raw_ast)
assert %DoExpressions{
elixir_ast: _,
children: [
[%Temple.Parser.Text{text: "bob"}],
nil
]
} = ast
end
end
describe "to_eex/1" do
test "emits eex" do
result =
quote do
for big <- boys do
"bob"
end
end
|> DoExpressions.run()
|> Temple.Generator.to_eex()
|> Utils.iolist_to_binary()
assert result ==
~s"""
<%= for(big <- boys) do %>
bob
<% end %>
"""
end
test "emits eex for that includes in else clause" do
result =
quote do
if foo? do
"bob"
"bobby"
else
"carol"
end
end
|> DoExpressions.run()
|> Temple.Generator.to_eex()
|> Utils.iolist_to_binary()
assert result ==
~s"""
<%= if(foo?) do %>
bob
bobby
<% else %>
carol
<% end %>
"""
end
test "emits eex for a case expression" do
result =
quote do
case foo? do
:bing ->
:bong
end
end
|> DoExpressions.run()
|> Temple.Generator.to_eex()
|> Utils.iolist_to_binary()
assert result ==
~s"""
<%= case(foo?) do %>
<% :bing -> %>
<%= :bong %>
<% end %>
"""
end
end
end