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/slot_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

51 lines
1.1 KiB
Elixir

defmodule Temple.Parser.SlotTest do
use ExUnit.Case, async: false
alias Temple.Parser.Slot
describe "applicable?/1" do
test "runs when using the `c` ast with a block" do
ast =
quote do
slot :header, value: "yolo"
end
assert Slot.applicable?(ast)
end
end
describe "run/2" do
test "adds a node to the buffer" do
raw_ast =
quote do
slot :header, value: "yolo"
end
ast = Slot.run(raw_ast)
assert %Slot{
name: :header,
args: [value: "yolo"]
} == ast
end
end
describe "Temple.Generator.to_eex/1" do
test "emits eex for a slot" do
raw_ast =
quote do
slot :header, value: Form.form_for(changeset, action)
end
result =
raw_ast
|> Slot.run()
|> Temple.Generator.to_eex()
assert result |> :erlang.iolist_to_binary() ==
~s"""
<%= Temple.Component.__render_block__(@inner_block, {:header, Enum.into([value: Form.form_for(changeset, action)], %{})}) %>
"""
end
end
end