From 18bb4022a99089f257f0adbb3cdad60d88875205 Mon Sep 17 00:00:00 2001 From: tomoya ishida Date: Sun, 16 Jul 2023 03:12:01 +0900 Subject: [PATCH] Indent multiline percent literals (#643) --- lib/irb/ruby-lex.rb | 6 +++--- test/irb/test_ruby_lex.rb | 34 +++++++++++++++++----------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 2297240b4..b9f498614 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -368,9 +368,9 @@ def calc_indent_level(opens) end end when :on_tstring_beg, :on_regexp_beg, :on_symbeg, :on_backtick - # can be indented if t.tok starts with `%` - when :on_words_beg, :on_qwords_beg, :on_symbols_beg, :on_qsymbols_beg, :on_embexpr_beg - # can be indented but not indented in current implementation + # No indent: "", //, :"", `` + # Indent: %(), %r(), %i(), %x() + indent_level += 1 if t.tok.start_with? '%' when :on_embdoc_beg indent_level = 0 else diff --git a/test/irb/test_ruby_lex.rb b/test/irb/test_ruby_lex.rb index 1e6f0f0c4..de1585b9c 100644 --- a/test/irb/test_ruby_lex.rb +++ b/test/irb/test_ruby_lex.rb @@ -256,13 +256,13 @@ def test_heredoc_with_embexpr PromptRow.new('001:0:":* ', %q(< ', %q(])), PromptRow.new('012:0: :> ', %q()), ] @@ -737,16 +737,16 @@ def test_pasted_code_keep_base_indent_spaces_with_heredoc Row.new(%q( [1), 10, 12, 3), Row.new(%q( ]+[["a), 10, 14, 4), Row.new(%q(b" + <<~A + <<-B + < ', %q(end)), @@ -813,12 +813,12 @@ def test_dynamic_prompt_with_double_newline_breaking_code def test_dynamic_prompt_with_multiline_literal input_with_prompt = [ PromptRow.new('001:1: :* ', %q(if true)), - PromptRow.new('002:1:]:* ', %q( %w[)), - PromptRow.new('003:1:]:* ', %q( a)), + PromptRow.new('002:2:]:* ', %q( %w[)), + PromptRow.new('003:2:]:* ', %q( a)), PromptRow.new('004:1: :* ', %q( ])), PromptRow.new('005:1: :* ', %q( b)), - PromptRow.new('006:1:]:* ', %q( %w[)), - PromptRow.new('007:1:]:* ', %q( c)), + PromptRow.new('006:2:]:* ', %q( %w[)), + PromptRow.new('007:2:]:* ', %q( c)), PromptRow.new('008:1: :* ', %q( ])), PromptRow.new('009:0: :> ', %q(end)), ] @@ -830,8 +830,8 @@ def test_dynamic_prompt_with_multiline_literal def test_dynamic_prompt_with_blank_line input_with_prompt = [ - PromptRow.new('001:0:]:* ', %q(%w[)), - PromptRow.new('002:0:]:* ', %q()), + PromptRow.new('001:1:]:* ', %q(%w[)), + PromptRow.new('002:1:]:* ', %q()), PromptRow.new('003:0: :> ', %q(])), ]