diff --git a/examples/left-right-trim.html.erb b/examples/left-right-trim.html.erb
new file mode 100644
index 000000000..81b4faadc
--- /dev/null
+++ b/examples/left-right-trim.html.erb
@@ -0,0 +1,3 @@
+<%- if true -%>
+
Content
+<%- end -%>
diff --git a/examples/left-trim.html.erb b/examples/left-trim.html.erb
new file mode 100644
index 000000000..944e93c93
--- /dev/null
+++ b/examples/left-trim.html.erb
@@ -0,0 +1,3 @@
+<%- if true %>
+ Content
+<%- end %>
diff --git a/examples/right-trim.html.erb b/examples/right-trim.html.erb
new file mode 100644
index 000000000..1c9f8e566
--- /dev/null
+++ b/examples/right-trim.html.erb
@@ -0,0 +1,3 @@
+<% if true -%>
+ Content
+<% end -%>
diff --git a/test/engine/evaluation_test.rb b/test/engine/evaluation_test.rb
index acbb01f45..0885f7f79 100644
--- a/test/engine/evaluation_test.rb
+++ b/test/engine/evaluation_test.rb
@@ -434,5 +434,23 @@ class EvaluationTest < Minitest::Spec
assert_evaluated_snapshot(template, { more: "ignored" }, { escape: false })
end
+
+ test "left trim" do
+ template = File.read("examples/left-trim.html.erb")
+
+ assert_evaluated_snapshot(template, {}, { escape: false })
+ end
+
+ test "right trim" do
+ template = File.read("examples/right-trim.html.erb")
+
+ assert_evaluated_snapshot(template, {}, { escape: false })
+ end
+
+ test "left and right trim" do
+ template = File.read("examples/left-right-trim.html.erb")
+
+ assert_evaluated_snapshot(template, {}, { escape: false })
+ end
end
end
diff --git a/test/snapshots/engine/evaluation_test/test_0031_left_trim_0487ac667a435a75abae76d26bc3184c.txt b/test/snapshots/engine/evaluation_test/test_0031_left_trim_0487ac667a435a75abae76d26bc3184c.txt
new file mode 100644
index 000000000..d1e5637db
--- /dev/null
+++ b/test/snapshots/engine/evaluation_test/test_0031_left_trim_0487ac667a435a75abae76d26bc3184c.txt
@@ -0,0 +1,5 @@
+---
+source: "Engine::EvaluationTest#test_0031_left trim"
+input: "{source: \"<%- if true %>\\n Content
\\n<%- end %>\\n\", locals: {}, options: {escape: false}}"
+---
+ Content
diff --git a/test/snapshots/engine/evaluation_test/test_0032_right_trim_009d413f1066d04acea88ea6ff36cbe2.txt b/test/snapshots/engine/evaluation_test/test_0032_right_trim_009d413f1066d04acea88ea6ff36cbe2.txt
new file mode 100644
index 000000000..41a26cfd9
--- /dev/null
+++ b/test/snapshots/engine/evaluation_test/test_0032_right_trim_009d413f1066d04acea88ea6ff36cbe2.txt
@@ -0,0 +1,5 @@
+---
+source: "Engine::EvaluationTest#test_0032_right trim"
+input: "{source: \"<% if true -%>\\n Content
\\n<% end -%>\\n\", locals: {}, options: {escape: false}}"
+---
+ Content
diff --git a/test/snapshots/engine/evaluation_test/test_0033_left_and_right_trim_1ab048e2a4ad2c02bdd61e558180d866.txt b/test/snapshots/engine/evaluation_test/test_0033_left_and_right_trim_1ab048e2a4ad2c02bdd61e558180d866.txt
new file mode 100644
index 000000000..79cd636b9
--- /dev/null
+++ b/test/snapshots/engine/evaluation_test/test_0033_left_and_right_trim_1ab048e2a4ad2c02bdd61e558180d866.txt
@@ -0,0 +1,5 @@
+---
+source: "Engine::EvaluationTest#test_0033_left and right trim"
+input: "{source: \"<%- if true -%>\\n Content
\\n<%- end -%>\\n\", locals: {}, options: {escape: false}}"
+---
+ Content
diff --git a/test/snapshots/engine/examples_compilation_test/test_0015_left_right_trim_compilation_0416edce0119986c84ba03c645b50717.txt b/test/snapshots/engine/examples_compilation_test/test_0015_left_right_trim_compilation_0416edce0119986c84ba03c645b50717.txt
new file mode 100644
index 000000000..fc696fa98
--- /dev/null
+++ b/test/snapshots/engine/examples_compilation_test/test_0015_left_right_trim_compilation_0416edce0119986c84ba03c645b50717.txt
@@ -0,0 +1,8 @@
+---
+source: "Engine::ExamplesCompilationTest#test_0015_left right trim compilation"
+input: "{source: \"<%- if true -%>\\n Content
\\n<%- end -%>\\n\", options: {escape: false}}"
+---
+_buf = ::String.new; if true
+ _buf << ' Content
+'.freeze; end
+_buf.to_s
diff --git a/test/snapshots/engine/examples_compilation_test/test_0016_left_trim_compilation_12bf92840853103be656f8d585205a84.txt b/test/snapshots/engine/examples_compilation_test/test_0016_left_trim_compilation_12bf92840853103be656f8d585205a84.txt
new file mode 100644
index 000000000..f4fec7274
--- /dev/null
+++ b/test/snapshots/engine/examples_compilation_test/test_0016_left_trim_compilation_12bf92840853103be656f8d585205a84.txt
@@ -0,0 +1,8 @@
+---
+source: "Engine::ExamplesCompilationTest#test_0016_left trim compilation"
+input: "{source: \"<%- if true %>\\n Content
\\n<%- end %>\\n\", options: {escape: false}}"
+---
+_buf = ::String.new; if true
+ _buf << ' Content
+'.freeze; end
+_buf.to_s
diff --git a/test/snapshots/engine/examples_compilation_test/test_0015_line_wrap_compilation_ba78b92bec7a4692a2043f2ba2ebe057.txt b/test/snapshots/engine/examples_compilation_test/test_0017_line_wrap_compilation_ba78b92bec7a4692a2043f2ba2ebe057.txt
similarity index 92%
rename from test/snapshots/engine/examples_compilation_test/test_0015_line_wrap_compilation_ba78b92bec7a4692a2043f2ba2ebe057.txt
rename to test/snapshots/engine/examples_compilation_test/test_0017_line_wrap_compilation_ba78b92bec7a4692a2043f2ba2ebe057.txt
index 22e51ef67..76bef36d9 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0015_line_wrap_compilation_ba78b92bec7a4692a2043f2ba2ebe057.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0017_line_wrap_compilation_ba78b92bec7a4692a2043f2ba2ebe057.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0015_line wrap compilation"
+source: "Engine::ExamplesCompilationTest#test_0017_line wrap compilation"
input: "{source: \"\\n\", options: {escape: false}}"
---
_buf = ::String.new; _buf << '
diff --git a/test/snapshots/engine/examples_compilation_test/test_0016_link_to_with_block_compilation_4ddb2a17755d3e775e3225970bc60a96.txt b/test/snapshots/engine/examples_compilation_test/test_0018_link_to_with_block_compilation_4ddb2a17755d3e775e3225970bc60a96.txt
similarity index 82%
rename from test/snapshots/engine/examples_compilation_test/test_0016_link_to_with_block_compilation_4ddb2a17755d3e775e3225970bc60a96.txt
rename to test/snapshots/engine/examples_compilation_test/test_0018_link_to_with_block_compilation_4ddb2a17755d3e775e3225970bc60a96.txt
index 0f64ddf7b..8cfcd3bf0 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0016_link_to_with_block_compilation_4ddb2a17755d3e775e3225970bc60a96.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0018_link_to_with_block_compilation_4ddb2a17755d3e775e3225970bc60a96.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0016_link to with block compilation"
+source: "Engine::ExamplesCompilationTest#test_0018_link to with block compilation"
input: "{source: \"<%= link_to root_path do %>\\n \\n Test\\n
\\n<% end %>\\n\", options: {escape: false}}"
---
_buf = ::String.new; _buf << link_to root_path do; _buf << '
diff --git a/test/snapshots/engine/examples_compilation_test/test_0017_nested_if_and_blocks_compilation_aa8aed9ef61b138a28efed42f4b72251.txt b/test/snapshots/engine/examples_compilation_test/test_0019_nested_if_and_blocks_compilation_aa8aed9ef61b138a28efed42f4b72251.txt
similarity index 96%
rename from test/snapshots/engine/examples_compilation_test/test_0017_nested_if_and_blocks_compilation_aa8aed9ef61b138a28efed42f4b72251.txt
rename to test/snapshots/engine/examples_compilation_test/test_0019_nested_if_and_blocks_compilation_aa8aed9ef61b138a28efed42f4b72251.txt
index c34e32da0..0177d43ec 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0017_nested_if_and_blocks_compilation_aa8aed9ef61b138a28efed42f4b72251.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0019_nested_if_and_blocks_compilation_aa8aed9ef61b138a28efed42f4b72251.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0017_nested if and blocks compilation"
+source: "Engine::ExamplesCompilationTest#test_0019_nested if and blocks compilation"
input: "{source: \"\\n <%= tag.div class: \\\"div\\\" do %>\\n <% if Date.today.friday? %>\\n
\\n Happy\\n <% current_hour = Time.now.hour %>\\n\\n <% if current_hour < 12 %>\\n Early Friday\\n <% elsif current_hour >= 18 %>\\n Late Friday\\n <% else %>\\n Friday\\n <% end %>\\n
\\n <% elsif Date.today.saturday? %>\\n \\n It's\\n Saturday\\n <%= \\\" - Time to relax!\\\" %>\\n
\\n <% else %>\\n \\n Oh no, it's\\n Not Friday\\n <%= \\\" - Keep going!\\\" %>\\n
\\n <% end %>\\n <% end %>\\n\\n\", options: {escape: false}}"
---
_buf = ::String.new; _buf << '
diff --git a/test/snapshots/engine/examples_compilation_test/test_0020_right_trim_compilation_a702ca89e5a7ccec9e80bfc422053ffd.txt b/test/snapshots/engine/examples_compilation_test/test_0020_right_trim_compilation_a702ca89e5a7ccec9e80bfc422053ffd.txt
new file mode 100644
index 000000000..046bdec75
--- /dev/null
+++ b/test/snapshots/engine/examples_compilation_test/test_0020_right_trim_compilation_a702ca89e5a7ccec9e80bfc422053ffd.txt
@@ -0,0 +1,8 @@
+---
+source: "Engine::ExamplesCompilationTest#test_0020_right trim compilation"
+input: "{source: \"<% if true -%>\\n
Content
\\n<% end -%>\\n\", options: {escape: false}}"
+---
+_buf = ::String.new; if true
+ _buf << ' Content
+'.freeze; end
+_buf.to_s
diff --git a/test/snapshots/engine/examples_compilation_test/test_0018_simple_block_compilation_1729fad3a77618acdc687c9fb671b75b.txt b/test/snapshots/engine/examples_compilation_test/test_0021_simple_block_compilation_1729fad3a77618acdc687c9fb671b75b.txt
similarity index 83%
rename from test/snapshots/engine/examples_compilation_test/test_0018_simple_block_compilation_1729fad3a77618acdc687c9fb671b75b.txt
rename to test/snapshots/engine/examples_compilation_test/test_0021_simple_block_compilation_1729fad3a77618acdc687c9fb671b75b.txt
index 83a2fb689..757bbce34 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0018_simple_block_compilation_1729fad3a77618acdc687c9fb671b75b.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0021_simple_block_compilation_1729fad3a77618acdc687c9fb671b75b.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0018_simple block compilation"
+source: "Engine::ExamplesCompilationTest#test_0021_simple block compilation"
input: "{source: \"<% tag.div do %>\\n <% if true %>\\n Hello1\\n <% else %>\\n Hello2\\n <% end %>\\n<% end %>\\n\", options: {escape: false}}"
---
_buf = ::String.new; tag.div do
diff --git a/test/snapshots/engine/examples_compilation_test/test_0019_simple_erb_compilation_d81de4ca83482c4836215ef7177d9eec.txt b/test/snapshots/engine/examples_compilation_test/test_0022_simple_erb_compilation_d81de4ca83482c4836215ef7177d9eec.txt
similarity index 65%
rename from test/snapshots/engine/examples_compilation_test/test_0019_simple_erb_compilation_d81de4ca83482c4836215ef7177d9eec.txt
rename to test/snapshots/engine/examples_compilation_test/test_0022_simple_erb_compilation_d81de4ca83482c4836215ef7177d9eec.txt
index a4ab4c419..af9afc2f0 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0019_simple_erb_compilation_d81de4ca83482c4836215ef7177d9eec.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0022_simple_erb_compilation_d81de4ca83482c4836215ef7177d9eec.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0019_simple erb compilation"
+source: "Engine::ExamplesCompilationTest#test_0022_simple erb compilation"
input: "{source: \"<% title %>\\n\", options: {escape: false}}"
---
_buf = ::String.new; title
diff --git a/test/snapshots/engine/examples_compilation_test/test_0020_test_compilation_9c22f391d1d03fa66b3d18095354a236.txt b/test/snapshots/engine/examples_compilation_test/test_0023_test_compilation_9c22f391d1d03fa66b3d18095354a236.txt
similarity index 86%
rename from test/snapshots/engine/examples_compilation_test/test_0020_test_compilation_9c22f391d1d03fa66b3d18095354a236.txt
rename to test/snapshots/engine/examples_compilation_test/test_0023_test_compilation_9c22f391d1d03fa66b3d18095354a236.txt
index 8f6911d65..568891df8 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0020_test_compilation_9c22f391d1d03fa66b3d18095354a236.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0023_test_compilation_9c22f391d1d03fa66b3d18095354a236.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0020_test compilation"
+source: "Engine::ExamplesCompilationTest#test_0023_test compilation"
input: "{source: \"\\n\\n\\n Hello World <%= RUBY_VERSION %>\\n
\\n\", options: {escape: false}}"
---
_buf = ::String.new; _buf << '
diff --git a/test/snapshots/engine/examples_compilation_test/test_0021_until_compilation_0b1269c00fd15a74df125278ed6a9fc4.txt b/test/snapshots/engine/examples_compilation_test/test_0024_until_compilation_0b1269c00fd15a74df125278ed6a9fc4.txt
similarity index 84%
rename from test/snapshots/engine/examples_compilation_test/test_0021_until_compilation_0b1269c00fd15a74df125278ed6a9fc4.txt
rename to test/snapshots/engine/examples_compilation_test/test_0024_until_compilation_0b1269c00fd15a74df125278ed6a9fc4.txt
index 3ccfa1d23..7868a7551 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0021_until_compilation_0b1269c00fd15a74df125278ed6a9fc4.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0024_until_compilation_0b1269c00fd15a74df125278ed6a9fc4.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0021_until compilation"
+source: "Engine::ExamplesCompilationTest#test_0024_until compilation"
input: "{source: \"<% i = 0 %>\\n\\n<% until i == 10 %>\\n <%= i %> is less than 10\\n <% i += 1 %>\\n<% end %>\\n\", options: {escape: false}}"
---
_buf = ::String.new; i = 0
diff --git a/test/snapshots/engine/examples_compilation_test/test_0022_utf8_compilation_45fa7aa654c0dc06d1a1b9504002dfba.txt b/test/snapshots/engine/examples_compilation_test/test_0025_utf8_compilation_45fa7aa654c0dc06d1a1b9504002dfba.txt
similarity index 86%
rename from test/snapshots/engine/examples_compilation_test/test_0022_utf8_compilation_45fa7aa654c0dc06d1a1b9504002dfba.txt
rename to test/snapshots/engine/examples_compilation_test/test_0025_utf8_compilation_45fa7aa654c0dc06d1a1b9504002dfba.txt
index 4acb59e6d..8e77e0f28 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0022_utf8_compilation_45fa7aa654c0dc06d1a1b9504002dfba.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0025_utf8_compilation_45fa7aa654c0dc06d1a1b9504002dfba.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0022_utf8 compilation"
+source: "Engine::ExamplesCompilationTest#test_0025_utf8 compilation"
input: "{source: \"Sitename • Title\\n\\n<% @title = \\\"Home\\\" %>\\n\\n<%= [@title, \\\"Sitename\\\"].compact.join(\\\" • \\\") %>\\n\", options: {escape: false}}"
---
_buf = ::String.new; _buf << 'Sitename • Title
diff --git a/test/snapshots/engine/examples_compilation_test/test_0023_while_compilation_a705eb5ed83b4db368d7204baa136b36.txt b/test/snapshots/engine/examples_compilation_test/test_0026_while_compilation_a705eb5ed83b4db368d7204baa136b36.txt
similarity index 82%
rename from test/snapshots/engine/examples_compilation_test/test_0023_while_compilation_a705eb5ed83b4db368d7204baa136b36.txt
rename to test/snapshots/engine/examples_compilation_test/test_0026_while_compilation_a705eb5ed83b4db368d7204baa136b36.txt
index e19cd211b..cc5198504 100644
--- a/test/snapshots/engine/examples_compilation_test/test_0023_while_compilation_a705eb5ed83b4db368d7204baa136b36.txt
+++ b/test/snapshots/engine/examples_compilation_test/test_0026_while_compilation_a705eb5ed83b4db368d7204baa136b36.txt
@@ -1,5 +1,5 @@
---
-source: "Engine::ExamplesCompilationTest#test_0023_while compilation"
+source: "Engine::ExamplesCompilationTest#test_0026_while compilation"
input: "{source: \"<% while i < 10 %>\\n <%= i %> is less than 10\\n <% i += 1 %>\\n<% end %>\\n\", options: {escape: false}}"
---
_buf = ::String.new; while i < 10