Skip to content

Add specs for case/when and if with out-of-int-range Integer literals#1357

Open
sampokuokkanen wants to merge 1 commit into
ruby:masterfrom
sampokuokkanen:case-if-fixnum-bignum-literals
Open

Add specs for case/when and if with out-of-int-range Integer literals#1357
sampokuokkanen wants to merge 1 commit into
ruby:masterfrom
sampokuokkanen:case-if-fixnum-bignum-literals

Conversation

@sampokuokkanen
Copy link
Copy Markdown
Contributor

Add specs covering case/when and if with Integer literals outside 32-bit int range (10_000_000_000, -3_000_000_000) and beyond 64-bit long range (1 << 100).

Existing case/when specs only exercised small Integers, so optimized implementations whose codepaths diverge at the int/long boundary were not covered.

Found coverage missing when looking at jruby/jruby#9320.

Add specs covering case/when and if with Integer literals outside
32-bit int range (10_000_000_000, -3_000_000_000) and beyond 64-bit
long range (1 << 100).

Existing case/when specs only exercised small Integers, so optimized
implementations whose codepaths diverge at the int/long boundary were
not covered.
Comment thread language/case_spec.rb
it "matches an arbitrary-precision Integer literal" do
huge = 1 << 100
case huge
when 1 << 100; true
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a literal though, so I think you need to paste the actual value here to test what you want

Comment thread language/case_spec.rb
it "dispatches correctly with mixed small and large Integer literals" do
pick = -> x {
case x
when 1 << 100 then :beyond_long
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

Comment thread language/if_spec.rb
Comment on lines +150 to +174
it "compares against an Integer literal whose value does not fit in a 32-bit int" do
x = 10_000_000_000
if x == 10_000_000_000
:match
else
:miss
end.should == :match

y = -3_000_000_000
if y == -3_000_000_000
:match
else
:miss
end.should == :match
end

it "compares against an arbitrary-precision Integer literal" do
x = 1 << 100
if x == 1 << 100
:match
else
:miss
end.should == :match
end

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would drop these, correct Integer#== should imply those to pass

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants