@@ -35,11 +35,44 @@ def test_erb_code_with_non_ascii
3535 assert_instance_of ( SyntaxTree ::ERB ::ErbNode , parsed . elements . first )
3636 end
3737
38+ def test_if_and_end_in_same_output_tag_short
39+ source = "<%= if true\n what\n end %>"
40+ expected = "<%= what if true %>\n "
41+
42+ assert_formatting ( source , expected )
43+ end
44+
45+ def test_if_and_end_in_same_tag
46+ source = "<% if true then this elsif false then that else maybe end %>"
47+ expected =
48+ "<% if true\n this\n elsif false\n that\n else\n maybe\n end %>\n "
49+
50+ assert_formatting ( source , expected )
51+ end
52+
3853 def test_long_if_statement
3954 source =
4055 "<%=number_to_percentage(@reports&.first&.stability*100,precision: 1) if @reports&.first&.other&.stronger&.longer %>"
4156 expected =
42- "<%= number_to_percentage(@reports&.first&.stability * 100, precision: 1) if @reports&.first&.other&.stronger&.longer %>\n "
57+ "<%= if @reports&.first&.other&.stronger&.longer\n number_to_percentage(@reports&.first&.stability * 100, precision: 1)\n end %>\n "
58+
59+ assert_formatting ( source , expected )
60+ end
61+
62+ def test_erb_else_if_statement
63+ source =
64+ "<%if this%>\n <h1>A</h1>\n <%elsif that%>\n <h1>B</h1>\n <%else%>\n <h1>C</h1>\n <%end%>"
65+ expected =
66+ "<% if this %>\n <h1>A</h1>\n <% elsif that %>\n <h1>B</h1>\n <% else %>\n <h1>C</h1>\n <% end %>\n "
67+
68+ assert_formatting ( source , expected )
69+ end
70+
71+ def test_long_ternary
72+ source =
73+ "<%= number_to_percentage(@reports&.first&.stability * 100, precision: @reports&.first&.stability ? 'Stable' : 'Unstable') %>"
74+ expected =
75+ "<%= number_to_percentage(\n @reports&.first&.stability * 100,\n precision: @reports&.first&.stability ? \" Stable\" : \" Unstable\" \n ) %>\n "
4376
4477 assert_formatting ( source , expected )
4578 end
@@ -73,9 +106,9 @@ def test_erb_only_erb_comment
73106
74107 def test_erb_ternary_as_argument_without_parentheses
75108 source =
76- "<%= f.submit f.object.id.present? ? t('buttons.titles.save'):t('buttons.titles.create') %>"
109+ "<%= f.submit( f.object.id.present? ? t('buttons.titles.save'):t('buttons.titles.create') ) %>"
77110 expected =
78- "<%= f.submit f.object.id.present? ? t(\" buttons.titles.save\" ) : t(\" buttons.titles.create\" ) %>\n "
111+ "<%= f.submit( \n f.object.id.present? ? t(\" buttons.titles.save\" ) : t(\" buttons.titles.create\" ) \n ) %>\n "
79112
80113 assert_formatting ( source , expected )
81114 end
0 commit comments