Skip to content

Commit

Permalink
Make sure the indentation level returned from IRB::Source is never lo…
Browse files Browse the repository at this point in the history
…wer than zero. Closes #1133.

git-svn-id: http://svn.macosforge.org/repository/ruby/DietRB/trunk@5205 23306eb0-4c56-4727-a40e-e92c0eb68959
  • Loading branch information
alloy committed Jan 28, 2011
1 parent 94957b2 commit 2c95572
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/irb/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ def initialize(source)
@code_block = @terminate = @syntax_error = @in_string = @in_regexp = @in_array = nil

@level = 0
@code_block = !parse.nil? && !@in_string && !@in_regexp && !@in_array
parsed = !parse.nil?
@level = 0 if @level < 0
@code_block = parsed && !@in_string && !@in_regexp && !@in_array
end

# Returns the code block indentation level.
Expand Down
1 change: 1 addition & 0 deletions spec/source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ def reflect(source)
end

it "returns the code block indentation level" do
reflect("]").level.should == 0
reflect("").level.should == 0
reflect("class A").level.should == 1
reflect("class A; def foo").level.should == 2
Expand Down

0 comments on commit 2c95572

Please sign in to comment.