Indent case statements

This commit is contained in:
Conrad Irwin 2011-10-09 01:39:42 -07:00
parent b3253c36c5
commit 7694cfeaaa
2 changed files with 36 additions and 1 deletions

View File

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

View File

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