summaryrefslogtreecommitdiff
path: root/test/irb
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-12-31 19:10:50 +0900
committeraycabta <aycabta@gmail.com>2021-01-05 18:06:10 +0900
commit5012512398daed11e65113310c212d50ad51fd16 (patch)
treeee5b1fad91e149d0e0fde3ad29bb6a4eb3741be8 /test/irb
parente72a6ed45f6ba844f15523b9f1250c22601c0011 (diff)
[ruby/irb] Handle indentations related to keyword "do" correctly
This fixes ruby/irb#158. https://github.com/ruby/irb/commit/964643400b
Diffstat (limited to 'test/irb')
-rw-r--r--test/irb/test_ruby_lex.rb70
1 files changed, 70 insertions, 0 deletions
diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb
index 30bae1e..fa2f049 100644
--- a/test/irb/test_ruby_lex.rb
+++ b/test/irb/test_ruby_lex.rb
@@ -263,6 +263,76 @@ module TestIRB
end
end
+ def test_corresponding_syntax_to_keyword_do_in_class
+ input_with_correct_indents = [
+ Row.new(%q(class C), nil, 2, 1),
+ Row.new(%q( while method_name do), nil, 4, 2),
+ Row.new(%q( 3), nil, 4, 2),
+ Row.new(%q( end), 2, 2, 1),
+ Row.new(%q( foo do), nil, 4, 2),
+ Row.new(%q( 3), nil, 4, 2),
+ Row.new(%q( end), 2, 2, 1),
+ Row.new(%q(end), 0, 0, 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)
+ assert_nesting_level(lines, row.nesting_level)
+ end
+ end
+
+ def test_corresponding_syntax_to_keyword_do
+ input_with_correct_indents = [
+ Row.new(%q(while i > 0), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(while true), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(while ->{i > 0}.call), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(while ->{true}.call), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(while i > 0 do), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(while true do), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(while ->{i > 0}.call do), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(while ->{true}.call do), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(foo do), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(foo true do), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(foo ->{true} do), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 0),
+ Row.new(%q(foo ->{i > 0} do), nil, 2, 1),
+ Row.new(%q( 3), nil, 2, 1),
+ Row.new(%q(end), 0, 0, 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)
+ assert_nesting_level(lines, row.nesting_level)
+ end
+ end
+
def test_oneliner_def_in_multiple_lines
input_with_correct_indents = [
Row.new(%q(def a()=[), nil, 4, 2),