Permalink
Browse files

Make sure the indentation level returned from IRB::Source is never lo…

…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...
1 parent 94957b2 commit 2c95572ce1386687903ad45ff446f48bc2398112 @alloy alloy committed Jan 28, 2011
Showing with 4 additions and 1 deletion.
  1. +3 −1 lib/irb/source.rb
  2. +1 −0 spec/source_spec.rb
View
@@ -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.
View
@@ -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

0 comments on commit 2c95572

Please sign in to comment.