From d548073f68ae719933c328686df224f74a60d366 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Sun, 7 Jul 2019 15:45:10 +0900 Subject: Enable indentation warning against `if` just after `else` ```ruby if false puts 'false' else if true puts 'true' end # -:5: warning: mismatched indentations at 'end' with 'if' at 3 end ``` [Feature #15990] --- test/ruby/test_rubyoptions.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/ruby/test_rubyoptions.rb b/test/ruby/test_rubyoptions.rb index 2f78461f2f..d63ca5da4d 100644 --- a/test/ruby/test_rubyoptions.rb +++ b/test/ruby/test_rubyoptions.rb @@ -491,14 +491,17 @@ class TestRubyOptions < Test::Unit::TestCase ["begin", "ensure ; end"], [" case nil", "when true; end"], ["case nil; when true", "end"], + ["if false;", "end", "if true\nelse ", "end"], ].each do - |b, e = 'end'| - src = ["#{b}\n", " #{e}\n"] + |b, e = 'end', pre = nil, post = nil| + src = ["#{pre}#{b}\n", " #{e}\n#{post}"] k = b[/\A\s*(\S+)/, 1] e = e[/\A\s*(\S+)/, 1] + n = 2 + n += pre.count("\n") if pre a.for("no directives with #{b}") do - err = ["#{t.path}:2: warning: mismatched indentations at '#{e}' with '#{k}' at 1"] + err = ["#{t.path}:#{n}: warning: mismatched indentations at '#{e}' with '#{k}' at #{n-1}"] t.rewind t.truncate(0) t.puts src @@ -517,7 +520,7 @@ class TestRubyOptions < Test::Unit::TestCase end a.for("false and true directives with #{b}") do - err = ["#{t.path}:4: warning: mismatched indentations at '#{e}' with '#{k}' at 3"] + err = ["#{t.path}:#{n+2}: warning: mismatched indentations at '#{e}' with '#{k}' at #{n+1}"] t.rewind t.truncate(0) t.puts "# -*- warn-indent: false -*-" @@ -539,7 +542,7 @@ class TestRubyOptions < Test::Unit::TestCase end a.for("BOM with #{b}") do - err = ["#{t.path}:2: warning: mismatched indentations at '#{e}' with '#{k}' at 1"] + err = ["#{t.path}:#{n}: warning: mismatched indentations at '#{e}' with '#{k}' at #{n-1}"] t.rewind t.truncate(0) t.print "\u{feff}" -- cgit v1.2.3