mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Indent case statements
This commit is contained in:
parent
b3253c36c5
commit
7694cfeaaa
2 changed files with 36 additions and 1 deletions
|
@ -27,6 +27,7 @@ class Pry
|
|||
'if' => 'end',
|
||||
'while' => 'end',
|
||||
'for' => 'end',
|
||||
'case' => 'end',
|
||||
'[' => ']',
|
||||
'{' => '}',
|
||||
'(' => ')'
|
||||
|
@ -44,7 +45,7 @@ class Pry
|
|||
|
||||
# Collection of tokens that should appear dedented even though they
|
||||
# don't affect the surrounding code.
|
||||
MIDWAY_TOKENS = ['else', 'elsif']
|
||||
MIDWAY_TOKENS = ['when', 'else', 'elsif']
|
||||
|
||||
def initialize
|
||||
reset
|
||||
|
|
|
@ -150,6 +150,40 @@ TXT
|
|||
@indent.indent(input).should == output
|
||||
end
|
||||
|
||||
it "should ident case statements" do
|
||||
input = <<TXT.strip
|
||||
case foo
|
||||
when 1
|
||||
2
|
||||
when 2
|
||||
if 3
|
||||
4
|
||||
end
|
||||
when 5
|
||||
#
|
||||
else
|
||||
#
|
||||
end
|
||||
TXT
|
||||
|
||||
output = <<TXT.strip
|
||||
case foo
|
||||
when 1
|
||||
2
|
||||
when 2
|
||||
if 3
|
||||
4
|
||||
end
|
||||
when 5
|
||||
#
|
||||
else
|
||||
#
|
||||
end
|
||||
TXT
|
||||
|
||||
@indent.indent(input).should == output
|
||||
end
|
||||
|
||||
it "should indent correctly with nesting" do
|
||||
@indent.indent("[[\n[]]\n]").should == "[[\n []]\n]"
|
||||
@indent.reset.indent("[[\n[]]\n]").should == "[[\n []]\n]"
|
||||
|
|
Loading…
Reference in a new issue