Skip to content

Commit

Permalink
Merge pull request rubinius#1329 from jtdowney/range-fixes
Browse files Browse the repository at this point in the history
Specs for Range#min and Range#max behavior on 1.8 and patch for 1.9
  • Loading branch information
rue committed Oct 22, 2011
2 parents a81da70 + 9bc0625 commit 5a9984b
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 11 deletions.
7 changes: 0 additions & 7 deletions kernel/common/range.rb
Expand Up @@ -322,12 +322,5 @@ def to_a


super super
end end

def max &a
return super(&a) if block_given?
return nil if @end < @begin
@end
end

end end


12 changes: 12 additions & 0 deletions kernel/common/range19.rb
@@ -1,3 +1,15 @@
class Range class Range
alias_method :cover?, :=== alias_method :cover?, :===

def max(&block)
return super(&block) if block_given?
return nil if @end < @begin
@end
end

def min(&block)
return super(&block) if block_given?
return nil if @end < @begin
@begin
end
end end
6 changes: 6 additions & 0 deletions spec/ruby/core/range/max_spec.rb
Expand Up @@ -13,6 +13,12 @@
end end
end end


ruby_version_is ""..."1.9" do
it "raises TypeError when called on a Float range" do
lambda { (303.20..908.1111).max }.should raise_error(TypeError)
end
end

it "returns nil when the endpoint is less than the start point" do it "returns nil when the endpoint is less than the start point" do
(100..10).max.should be_nil (100..10).max.should be_nil
('z'..'l').max.should be_nil ('z'..'l').max.should be_nil
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/core/range/min_spec.rb
Expand Up @@ -13,6 +13,12 @@
end end
end end


ruby_version_is ""..."1.9" do
it "raises TypeError when called on a Float range" do
lambda { (303.20..908.1111).min }.should raise_error(TypeError)
end
end

it "returns nil when the start point is greater than the endpoint" do it "returns nil when the start point is greater than the endpoint" do
(100..10).min.should be_nil (100..10).min.should be_nil
('z'..'l').min.should be_nil ('z'..'l').min.should be_nil
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/19/ruby/core/range/max_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/tags/19/ruby/core/range/min_tags.txt

This file was deleted.

Empty file.

0 comments on commit 5a9984b

Please sign in to comment.