Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/ruby2ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,11 @@ def process_in exp # :nodoc:
_, lhs, *rhs = exp

cond = process lhs
body = rhs.compact.map { |sexp| indent process sexp }
body = rhs.compact.map { |sexp|
in_context :in_body do
indent process sexp
end
}

body << indent("# do nothing") if body.empty?
body = body.join "\n"
Expand Down
10 changes: 10 additions & 0 deletions test/test_ruby2ruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1002,6 +1002,16 @@ def test_case_in__hash_pat_14
assert_case_in "Object[b: 1]", s(:hash_pat, s(:const, :Object), s(:lit, :b), s(:lit, 1))
end

def test_case_in_body_does_not_pin_variables
inn = s(:case, s(:call, nil, :x),
s(:in,
s(:array_pat, nil, s(:lasgn, :a), s(:lasgn, :b)),
s(:lvar, :a)),
nil)
out = "case x\nin [a, b] then\n a\nend"
assert_parse inn, out
end

def test_interpolation_and_escapes
# log_entry = " \e[#{message_color}m#{message}\e[0m "
inn = s(:lasgn, :log_entry,
Expand Down