8000 Fix auto indent with closed brace · ruby/irb@fbe59e3 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit fbe59e3

Browse files
committed
Fix auto indent with closed brace
A closed brace in auto-indent shouldn't affect the next brace in the same line, but it behaves like below: p() { } It's a bug.
1 parent ab2f6b8 commit fbe59e3

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/irb/ruby-lex.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,7 @@ def check_corresponding_token_depth
394394
spaces_of_nest.pop
395395
corresponding_token_depth = nil
396396
end
397+
open_brace_on_line -= 1
397398
when :on_kw
398399
next if index > 0 and @tokens[index - 1][3].allbits?(Ripper::EXPR_FNAME)
399400
case t[2]

test/irb/test_ruby_lex.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,5 +112,19 @@ def test_multiple_braces_in_a_line
112112
assert_indenting(lines, row.new_line_spaces, true)
113113
end
114114
end
115+
116+
def test_a_closed_brace_and_not_closed_brace_in_a_line
117+
input_with_correct_indents = [
118+
Row.new(%q(p() {), nil, 2),
119+
Row.new(%q(}), 0, 0),
120+
]
121+
122+
lines = []
123+
input_with_correct_indents.each do |row|
124+
lines << row.content
125+
assert_indenting(lines, row.current_line_spaces, false)
126+
assert_indenting(lines, row.new_line_spaces, true)
127+
end
128+
end
115129
end
116130
end

0 commit comments

Comments
 (0)
0