mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Indent begin-rescue-end properly
This commit is contained in:
parent
9ba6dfcd32
commit
a1d148199f
2 changed files with 22 additions and 2 deletions
|
@ -30,6 +30,7 @@ class Pry
|
|||
'until' => 'end',
|
||||
'for' => 'end',
|
||||
'case' => 'end',
|
||||
'begin' => 'end',
|
||||
'[' => ']',
|
||||
'{' => '}',
|
||||
'(' => ')'
|
||||
|
@ -37,7 +38,7 @@ class Pry
|
|||
|
||||
# Which tokens can either be open tokens, or appear as modifiers on
|
||||
# a single-line.
|
||||
SINGLELINE_TOKENS = %w(if while until unless)
|
||||
SINGLELINE_TOKENS = %w(if while until unless rescue)
|
||||
|
||||
# Collection of token types that should be ignored. Without this list
|
||||
# keywords such as "class" inside strings would cause the code to be
|
||||
|
@ -51,7 +52,7 @@ class Pry
|
|||
|
||||
# Collection of tokens that should appear dedented even though they
|
||||
# don't affect the surrounding code.
|
||||
MIDWAY_TOKENS = ['when', 'else', 'elsif']
|
||||
MIDWAY_TOKENS = %w(when else elsif rescue)
|
||||
|
||||
def initialize
|
||||
reset
|
||||
|
|
|
@ -212,4 +212,23 @@ TXT
|
|||
it "should not indent single/multi-line until" do
|
||||
@indent.indent("%w{baz} until bar\nuntil foo\nbar\nend").should == "%w{baz} until bar\nuntil foo\n bar\nend"
|
||||
end
|
||||
|
||||
it "should indent begin rescue end" do
|
||||
input = <<INPUT.strip
|
||||
begin
|
||||
doo :something => :wrong
|
||||
rescue => e
|
||||
doit :right
|
||||
end
|
||||
INPUT
|
||||
output = <<OUTPUT.strip
|
||||
begin
|
||||
doo :something => :wrong
|
||||
rescue => e
|
||||
doit :right
|
||||
end
|
||||
OUTPUT
|
||||
|
||||
@indent.indent(input).should == output
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue