mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
Handle unless and until in indent
This commit is contained in:
parent
0648d9c60d
commit
ab0dbfbe6d
2 changed files with 15 additions and 1 deletions
|
@ -25,7 +25,9 @@ class Pry
|
|||
'module' => 'end',
|
||||
'do' => 'end',
|
||||
'if' => 'end',
|
||||
'unless' => 'end',
|
||||
'while' => 'end',
|
||||
'until' => 'end',
|
||||
'for' => 'end',
|
||||
'case' => 'end',
|
||||
'[' => ']',
|
||||
|
@ -33,6 +35,10 @@ class Pry
|
|||
'(' => ')'
|
||||
}
|
||||
|
||||
# Which tokens can either be open tokens, or appear as modifiers on
|
||||
# a single-line.
|
||||
SINGLELINE_TOKENS = %w(if while until unless)
|
||||
|
||||
# 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.
|
||||
|
@ -135,7 +141,7 @@ class Pry
|
|||
# If the list of tokens contains a matching closing token the line should
|
||||
# not be indented (and thus we should return true).
|
||||
tokens.each do |token, kind|
|
||||
is_singleline_if = (token == "if" || token == "while") && end_of_statement?(last_token, last_kind)
|
||||
is_singleline_if = (SINGLELINE_TOKENS.include?(token)) && end_of_statement?(last_token, last_kind)
|
||||
is_optional_do = (token == "do" && seen_for_at.include?(add_after - 1))
|
||||
|
||||
last_token, last_kind = token, kind unless kind == :space
|
||||
|
|
|
@ -204,4 +204,12 @@ TXT
|
|||
@indent.reset.indent("[if bar\n#").should == "[if bar\n #"
|
||||
@indent.reset.indent("true; while bar\n#").should == "true; while bar\n #"
|
||||
end
|
||||
|
||||
it "should differentiate single/multi-line unless" do
|
||||
@indent.indent("foo unless bar\nunless foo\nbar\nend").should == "foo unless bar\nunless foo\n bar\nend"
|
||||
end
|
||||
|
||||
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
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue