1
0
Fork 0
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:
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]"