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/right_arrow_test.exs

79 lines
1.6 KiB
Elixir
Raw Normal View History

2021-03-25 03:01:13 +00:00
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)
end
test "returns false when the node is anything other than an anonymous function as an argument to a function" do
raw_asts = [
quote do
Temple.div do
"foo"
end
end,
quote do
link to: "/the/route" do
"Label"
end
end
]
for raw_ast <- raw_asts do
refute RightArrow.applicable?(raw_ast)
end
end
end
describe "run/2" do
test "adds a node to the buffer" do
[raw_ast] =
quote do
:bing ->
:bong
end
bong =
quote do
:bong
end
ast = RightArrow.run(raw_ast)
2021-04-09 03:04:26 +00:00
assert %RightArrow{
elixir_ast: :bing,
2021-03-25 03:01:13 +00:00
children: [
2021-04-09 03:04:26 +00:00
%Temple.Parser.Default{
elixir_ast: ^bong
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
:bing ->
:bong
end
|> List.first()
|> RightArrow.run()
2021-04-11 21:27:02 +00:00
|> Temple.Generator.to_eex()
2021-04-09 03:04:26 +00:00
assert result |> :erlang.iolist_to_binary() ==
~s|<% :bing -> %>\n<%= :bong %>\n|
2021-04-09 03:04:26 +00:00
end
end
2021-03-25 03:01:13 +00:00
end