Skip to content

EEx do/end within a cond macro #1710

@Andy-Richards

Description

@Andy-Richards

Raising this issue as requested as per the mailing list https://groups.google.com/forum/#!topic/elixir-lang-talk/keFkzq-cs18

The issue can be seen when using a nested do/end tag within a cond macro in a EEx template. Its a little tricky to explain so the following unit test shows the problem. Basically the first test "nested cond" passes as expected, the second test "nested cond with end" containing a if/else macro fails returning what seems to be the value in the last case statement containing a do/end macro (in this case if/else/end). Hopefully that makes sense along with the unit test below.

ExUnit.start [trace: "--trace" in System.argv]

defmodule CondTest do
 use ExUnit.Case

 test "nested cond" do
  str = """
   <% y = ["a", "b", "c"] %>
   <% x = [1, 2, 3] %>   
   <%= cond do %>
    <% "a" in y -> %> <%# this matches as expected %>
     Good
    <% 1 in x -> %>
     Weird    
    <% true -> %>
     Bad
   <% end %>
  """
  assert "Good" === String.strip( EEx.eval_string(str, args: []) )
 end

 test "nested cond with end" do
  str = """
   <% y = ["a", "b", "c"] %>
   <% x = [1, 2, 3] %>   
   <%= cond do %>
    <% "a" in y -> %> <%# this doesnt match the last case below conatining an end tag does ? %>
     Good
    <% "b" in y -> %>
     <% if true do %>True<% else %>false<% end %>
     Weird2
    <% 1 in x -> %>
     <% if true do %>True<% else %>false<% end %>
     Weird
    <% 1 == 2 -> %>
     Weird3  
    <% true -> %>
     Bad
   <% end %>
  """
  assert "Good" === String.strip( EEx.eval_string(str, args: []) )
 end
end

Thanks,

Andy.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions