1
0
Fork 0
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:
Conrad Irwin 2012-12-28 07:37:55 -08:00
parent 3add7abc1e
commit cf1137932f
2 changed files with 9 additions and 1 deletions

View file

@ -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)

View file

@ -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