summaryrefslogtreecommitdiff
path: root/test/irb
diff options
context:
space:
mode:
authorBen <kanobt61@gmail.com>2020-01-05 14:44:38 -0500
committeraycabta <aycabta@gmail.com>2020-01-14 15:40:38 +0900
commitc94025b63091be5b5e83a2f5ab5dc8d6c6147b84 (patch)
treeeaee6c40fb128d764e5fcc297a0da822e03ab76c /test/irb
parent9994eb8a5e72ff68ee2a13ddeff8d9307ba7cd84 (diff)
[ruby/irb] Fix crashing when multiple open braces per line
https://github.com/ruby/irb/issues/55 If we had put multiple open braces on a line the with no closing brace spaces_of_nest array keeps getting '0' added to it. This means that when we pop off of this array we are saying that we should be in position zero for the next line. This is an issue because we don't always want to be in position 0 after a closing brace. Example: ``` [[[ ] ] ] ``` In the above example the 'spaces_of_nest' array looks like this after the first line is entered: [0,0,0]. We really want to be indented 4 spaces for the 1st closing brace 2 for the 2nd and 0 for the 3rd. i.e. we want it to be: [0,2,4]. We also saw this issue with a heredoc inside of an array. ``` [<<FOO] hello FOO ``` https://github.com/ruby/irb/commit/80c69c8272
Diffstat (limited to 'test/irb')
-rw-r--r--test/irb/test_ruby_lex.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb
index ae25b1d501..65fc7d431a 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -93,5 +93,24 @@ module TestIRB
assert_indenting(lines, row.new_line_spaces, true)
end
end
+
+ def test_multiple_braces_in_a_line
+ input_with_correct_indents = [
+ Row.new(%q([[[), nil, 6),
+ Row.new(%q( ]), 4, 4),
+ Row.new(%q( ]), 2, 2),
+ Row.new(%q(]), 0, 0),
+ Row.new(%q([<<FOO]), nil, 0),
+ Row.new(%q(hello), nil, 0),
+ Row.new(%q(FOO), nil, 0),
+ ]
+
+ lines = []
+ input_with_correct_indents.each do |row|
+ lines << row.content
+ assert_indenting(lines, row.current_line_spaces, false)
+ assert_indenting(lines, row.new_line_spaces, true)
+ end
+ end
end
end