Fix indentation of "true if foo" [Fixes #355]

This commit is contained in:
Conrad Irwin 2011-11-27 10:39:47 -08:00
parent ddae9fbfb0
commit 6f54733e1d
2 changed files with 7 additions and 1 deletions

View File

@ -43,7 +43,11 @@ class Pry
# 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.
IGNORE_TOKENS = [:space, :content, :string, :delimiter, :method, :ident]
#
# :pre_constant and :preserved_constant are the CodeRay 0.9.8 and 1.0.0
# classifications of "true", "false", and "nil".
IGNORE_TOKENS = [:space, :content, :string, :delimiter, :method, :ident,
:constant, :pre_constant, :predefined_constant]
# Tokens that indicate the end of a statement (i.e. that, if they appear
# directly before an "if" indicates that that if applies to the same line,

View File

@ -196,6 +196,8 @@ TXT
@indent.reset.indent("foo 'hi' if bar\n#").should == "foo 'hi' if bar\n#"
@indent.reset.indent("foo 1 while bar\n#").should == "foo 1 while bar\n#"
@indent.reset.indent("super if true\n#").should == "super if true\n#"
@indent.reset.indent("true if false\n#").should == "true if false\n#"
@indent.reset.indent("String if false\n#").should == "String if false\n#"
end
it "should indent cunningly disguised ifs" do