Skip to content

Commit

Permalink
Ruby 2.7: extend logic
Browse files Browse the repository at this point in the history
  • Loading branch information
gogainda committed Dec 15, 2020
1 parent 1382260 commit a260037
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
8 changes: 1 addition & 7 deletions spec/ruby/core/integer/element_reference_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,10 @@
0b000001[-3, 4].should == 0b1000
end

it "ignores negative upper boundary" do
0b101001101[1..-1].should == 0b10100110
0b101001101[1..-2].should == 0b10100110
0b101001101[1..-3].should == 0b10100110
end

it "ignores upper boundary smaller than lower boundary" do
0b101001101[4..1].should == 0b10100
0b101001101[4..2].should == 0b10100
0b101001101[4..3].should == 0b10100
0b101001101[-4..-5].should == 0b1010011010000
end

it "raises FloatDomainError if any boundary is infinity" do
Expand Down
12 changes: 4 additions & 8 deletions src/main/ruby/truffleruby/core/integer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,16 @@ def [](index, len = undefined)
num = self >> range.begin
mask = mask(range, len)

return num if range.end < 0
return num if range.end < range.begin
num & mask
range.end < range.begin ? num : num & mask
elsif Primitive.nil? range.end
start = range.begin

return self >> start
return self >> range.begin
else
result = self & mask(range, range.end)
raise ArgumentError, 'The beginless range for Integer#[] results in infinity' if result != 0
raise ArgumentError, 'The beginless range for Integer#[] results in infinity' if result != 0 && range.end >= 0

result
0
end

end

private def validate_range(index)
Expand Down
3 changes: 1 addition & 2 deletions test/mri/excludes/TestInteger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@
exclude :test_floor, "needs investigation"
exclude :test_pow, "needs investigation"
exclude :test_truncate, "needs investigation"
exclude :test_Integer_with_invalid_exception, "needs investigation"
exclude :test_aref, "needs investigation"
exclude :test_Integer_with_invalid_exception, "needs investigation"

0 comments on commit a260037

Please sign in to comment.