Skip to content

Commit a1e4b12

Browse files
committed
Fix specs for Range#max
1 parent 3b7ae14 commit a1e4b12

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

spec/tags/core/range/max_tags.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/main/ruby/truffleruby/core/range.rb

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -398,24 +398,29 @@ def last(n = undefined)
398398

399399
def max
400400
raise RangeError, 'cannot get the maximum of endless range' if Primitive.nil? self.end
401-
if Primitive.nil? self.begin
402-
raise RangeError, 'cannot get the maximum of beginless range with custom comparison method' if block_given?
403-
return exclude_end? ? self.end - 1 : self.end
404-
end
405-
return super if block_given? || (exclude_end? && !Primitive.is_a?(self.end, Numeric))
406-
return nil if Comparable.compare_int(self.end <=> self.begin) < 0
407-
return nil if exclude_end? && Comparable.compare_int(self.end <=> self.begin) == 0
408-
return self.end unless exclude_end?
409401

410-
unless Primitive.is_a?(self.end, Integer)
411-
raise TypeError, 'cannot exclude non Integer end value'
412-
end
402+
if block_given? || (exclude_end? && !Primitive.is_a?(self.end, Numeric))
403+
if Primitive.nil? self.begin
404+
raise RangeError, 'cannot get the maximum of beginless range with custom comparison method'
405+
end
413406

414-
unless Primitive.is_a?(self.begin, Integer)
415-
raise TypeError, 'cannot exclude end value with non Integer begin value'
407+
return super
416408
end
417409

418-
self.end - 1
410+
if exclude_end?
411+
if !Primitive.is_a?(self.end, Integer)
412+
raise TypeError, 'cannot exclude non Integer end value'
413+
elsif !Primitive.is_a?(self.begin, Integer)
414+
raise TypeError, 'cannot exclude end value with non Integer begin value'
415+
elsif self.end <= self.begin
416+
return nil
417+
end
418+
419+
self.end - 1
420+
else
421+
return nil if !Primitive.nil?(self.begin) && Comparable.compare_int(self.end <=> self.begin) < 0
422+
self.end
423+
end
419424
end
420425

421426
def min

0 commit comments

Comments
 (0)