diff --git a/language/case_spec.rb b/language/case_spec.rb index 8355062e4..705a48967 100644 --- a/language/case_spec.rb +++ b/language/case_spec.rb @@ -27,6 +27,41 @@ def bar; @calls << :bar; end @calls.should == [:foo, :bar] end + it "matches an Integer literal whose value does not fit in a 32-bit int" do + big = 10_000_000_000 + case big + when 10_000_000_000; true + else false + end.should == true + + case -3_000_000_000 + when -3_000_000_000; true + else false + end.should == true + end + + it "matches an arbitrary-precision Integer literal" do + huge = 1 << 100 + case huge + when 1 << 100; true + else false + end.should == true + end + + it "dispatches correctly with mixed small and large Integer literals" do + pick = -> x { + case x + when 1 << 100 then :beyond_long + when 10_000_000_000 then :beyond_int + when 1 then :fits_int + else :other + end + } + + [1 << 100, 10_000_000_000, 1, :nope].map(&pick).should == + [:beyond_long, :beyond_int, :fits_int, :other] + end + it "evaluates the body of the when clause whose range expression includes the case target expression" do case 5 when 21..30; false diff --git a/language/if_spec.rb b/language/if_spec.rb index 53fcb853d..2ea471e0e 100644 --- a/language/if_spec.rb +++ b/language/if_spec.rb @@ -147,6 +147,31 @@ end.should == 123 end + 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 + it "allows starting else-body on the same line" do if false 123