Skip to content

Commit 7679304

Browse files
authored
Handles self-closing new lines (#54)
1 parent 0a513a5 commit 7679304

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

lib/syntax_tree/erb/nodes.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ def new_line
164164

165165
def without_new_line
166166
self.class.new(
167-
**deconstruct_keys([]).merge(closing: closing.without_new_line)
167+
**deconstruct_keys([]).merge(closing: closing&.without_new_line)
168168
)
169169
end
170170

@@ -253,6 +253,15 @@ def deconstruct_keys(keys)
253253
end
254254
end
255255

256+
def without_new_line
257+
self.class.new(
258+
**deconstruct_keys([]).merge(
259+
opening: closing.nil? ? opening.without_new_line : opening,
260+
closing: closing&.without_new_line
261+
)
262+
)
263+
end
264+
256265
# The HTML-closing tag is responsible for new lines after the node.
257266
def new_line
258267
closing.nil? ? opening.new_line : closing&.new_line

test/html_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,5 +180,12 @@ def test_breakable_on_char_data_white_space
180180

181181
assert_formatting(source, expected)
182182
end
183+
184+
def test_self_closing_group
185+
source = "<link />\n<link />\n<meta />"
186+
expected = "<link />\n<link />\n<meta />\n"
187+
188+
assert_formatting(source, expected)
189+
end
183190
end
184191
end

test/test_helper.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,10 @@ class TestCase < Minitest::Test
1212
def assert_formatting(source, expected)
1313
formatted = SyntaxTree::ERB.format(source)
1414

15-
if (expected != formatted)
16-
binding.irb if debug
17-
end
18-
1915
assert_equal(formatted, expected, "Failed first")
2016

2117
formatted_twice = SyntaxTree::ERB.format(formatted)
2218

23-
if (expected != formatted_twice)
24-
binding.irb if debug
25-
end
26-
2719
assert_equal(formatted_twice, expected, "Failed second")
2820

2921
# Check that pretty_print works

0 commit comments

Comments
 (0)