mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Indent 'while/until do' loops correctly [Fixes #787]
This commit is contained in:
parent
3add7abc1e
commit
cf1137932f
2 changed files with 9 additions and 1 deletions
|
@ -54,6 +54,9 @@ class Pry
|
|||
# a single-line.
|
||||
SINGLELINE_TOKENS = %w(if while until unless rescue)
|
||||
|
||||
# Which tokens can be followed by an optional "do" keyword.
|
||||
OPTIONAL_DO_TOKENS = %(for while until)
|
||||
|
||||
# Collection of token types that should be ignored. Without this list
|
||||
# keywords such as "class" inside strings would cause the code to be
|
||||
# indented incorrectly.
|
||||
|
@ -224,7 +227,7 @@ class Pry
|
|||
|
||||
track_module_nesting(token, kind)
|
||||
|
||||
seen_for_at << add_after if token == "for"
|
||||
seen_for_at << add_after if OPTIONAL_DO_TOKENS.include?(token)
|
||||
|
||||
if kind == :delimiter
|
||||
track_delimiter(token)
|
||||
|
|
|
@ -150,6 +150,11 @@ TXT
|
|||
@indent.indent(input).should == output
|
||||
end
|
||||
|
||||
it "should correctly handle while <foo> do" do
|
||||
input = "while 5 do\n5\nend"
|
||||
@indent.indent(input).should == "while 5 do\n 5\nend"
|
||||
end
|
||||
|
||||
it "should ident case statements" do
|
||||
input = <<TXT.strip
|
||||
case foo
|
||||
|
|
Loading…
Reference in a new issue