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

71 lines
1.5 KiB
Elixir
Raw Normal View History

2021-03-25 03:01:13 +00:00
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
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)
2021-04-09 03:04:26 +00:00
assert %DoExpressions{
2021-03-25 03:01:13 +00:00
content: _,
children: [
2021-04-09 03:04:26 +00:00
[%Temple.Parser.Text{content: "bob", children: []}], nil
2021-03-25 03:01:13 +00:00
]
} = ast
end
end
2021-04-09 03:04:26 +00:00
describe "to_eex/1" do
test "emits eex" do
result =
quote do
for big <- boys do
"bob"
end
end
|> DoExpressions.run()
|> Temple.EEx.to_eex()
assert result |> :erlang.iolist_to_binary() ==
~s|<%= for(big <- boys) do %>\nbob\n<% end %>|
end
test "emits eex for that includes in else clause" do
result =
quote do
if foo? do
"bob"
else
"carol"
end
end
|> DoExpressions.run()
|> Temple.EEx.to_eex()
assert result |> :erlang.iolist_to_binary() ==
~s|<%= if(foo?) do %>\nbob\n<% else %>\ncarol\n<% end %>|
end
end
2021-03-25 03:01:13 +00:00
end