Skip to content

Commit 18bb402

Browse files
authored
Indent multiline percent literals (#643)
1 parent b0f650a commit 18bb402

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

lib/irb/ruby-lex.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,9 @@ def calc_indent_level(opens)
368368
end
369369
end
370370
when :on_tstring_beg, :on_regexp_beg, :on_symbeg, :on_backtick
371-
# can be indented if t.tok starts with `%`
372-
when :on_words_beg, :on_qwords_beg, :on_symbols_beg, :on_qsymbols_beg, :on_embexpr_beg
373-
# can be indented but not indented in current implementation
371+
# No indent: "", //, :"", ``
372+
# Indent: %(), %r(), %i(), %x()
373+
indent_level += 1 if t.tok.start_with? '%'
374374
when :on_embdoc_beg
375375
indent_level = 0
376376
else

test/irb/test_ruby_lex.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -256,13 +256,13 @@ def test_heredoc_with_embexpr
256256
PromptRow.new('001:0:":* ', %q(<<A+%W[#{<<B)),
257257
PromptRow.new('002:0:":* ', %q(#{<<C+%W[)),
258258
PromptRow.new('003:0:":* ', %q(a)),
259-
PromptRow.new('004:0:]:* ', %q(C)),
260-
PromptRow.new('005:0:]:* ', %q(a)),
259+
PromptRow.new('004:2:]:* ', %q(C)),
260+
PromptRow.new('005:2:]:* ', %q(a)),
261261
PromptRow.new('006:0:":* ', %q(]})),
262262
PromptRow.new('007:0:":* ', %q(})),
263263
PromptRow.new('008:0:":* ', %q(A)),
264-
PromptRow.new('009:0:]:* ', %q(B)),
265-
PromptRow.new('010:0:]:* ', %q(})),
264+
PromptRow.new('009:2:]:* ', %q(B)),
265+
PromptRow.new('010:1:]:* ', %q(})),
266266
PromptRow.new('011:0: :> ', %q(])),
267267
PromptRow.new('012:0: :> ', %q()),
268268
]
@@ -737,16 +737,16 @@ def test_pasted_code_keep_base_indent_spaces_with_heredoc
737737
Row.new(%q( [1), 10, 12, 3),
738738
Row.new(%q( ]+[["a), 10, 14, 4),
739739
Row.new(%q(b" + <<~A + <<-B + <<C), 0, 16, 5),
740-
Row.new(%q( a#{), 16, 16, 5),
741-
Row.new(%q( 1), 16, 16, 5),
740+
Row.new(%q( a#{), 16, 18, 6),
741+
Row.new(%q( 1), 18, 18, 6),
742742
Row.new(%q( }), 16, 16, 5),
743743
Row.new(%q( A), 14, 16, 5),
744-
Row.new(%q( b#{), 16, 16, 5),
745-
Row.new(%q( 1), 16, 16, 5),
744+
Row.new(%q( b#{), 16, 18, 6),
745+
Row.new(%q( 1), 18, 18, 6),
746746
Row.new(%q( }), 16, 16, 5),
747747
Row.new(%q( B), 14, 0, 0),
748-
Row.new(%q(c#{), 0, 0, 0),
749-
Row.new(%q(1), 0, 0, 0),
748+
Row.new(%q(c#{), 0, 2, 1),
749+
Row.new(%q( 1), 2, 2, 1),
750750
Row.new(%q(}), 0, 0, 0),
751751
Row.new(%q(C), 0, 14, 4),
752752
Row.new(%q( ]), 12, 12, 3),
@@ -799,7 +799,7 @@ def test_dynamic_prompt
799799
def test_dynamic_prompt_with_double_newline_breaking_code
800800
input_with_prompt = [
801801
PromptRow.new('001:1: :* ', %q(if true)),
802-
PromptRow.new('002:1: :* ', %q(%)),
802+
PromptRow.new('002:2: :* ', %q(%)),
803803
PromptRow.new('003:1: :* ', %q(;end)),
804804
PromptRow.new('004:1: :* ', %q(;hello)),
805805
PromptRow.new('005:0: :> ', %q(end)),
@@ -813,12 +813,12 @@ def test_dynamic_prompt_with_double_newline_breaking_code
813813
def test_dynamic_prompt_with_multiline_literal
814814
input_with_prompt = [
815815
PromptRow.new('001:1: :* ', %q(if true)),
816-
PromptRow.new('002:1:]:* ', %q( %w[)),
817-
PromptRow.new('003:1:]:* ', %q( a)),
816+
PromptRow.new('002:2:]:* ', %q( %w[)),
817+
PromptRow.new('003:2:]:* ', %q( a)),
818818
PromptRow.new('004:1: :* ', %q( ])),
819819
PromptRow.new('005:1: :* ', %q( b)),
820-
PromptRow.new('006:1:]:* ', %q( %w[)),
821-
PromptRow.new('007:1:]:* ', %q( c)),
820+
PromptRow.new('006:2:]:* ', %q( %w[)),
821+
PromptRow.new('007:2:]:* ', %q( c)),
822822
PromptRow.new('008:1: :* ', %q( ])),
823823
PromptRow.new('009:0: :> ', %q(end)),
824824
]
@@ -830,8 +830,8 @@ def test_dynamic_prompt_with_multiline_literal
830830

831831
def test_dynamic_prompt_with_blank_line
832832
input_with_prompt = [
833-
PromptRow.new('001:0:]:* ', %q(%w[)),
834-
PromptRow.new('002:0:]:* ', %q()),
833+
PromptRow.new('001:1:]:* ', %q(%w[)),
834+
PromptRow.new('002:1:]:* ', %q()),
835835
PromptRow.new('003:0: :> ', %q(])),
836836
]
837837

0 commit comments

Comments
 (0)