diff --git a/language/case_spec.rb b/language/case_spec.rb index 8355062e4..41881bf20 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 = 1267650600228229401496703205376 + case huge + when 1267650600228229401496703205376; true + else false + end.should == true + end + + it "dispatches correctly with mixed small and large Integer literals" do + pick = -> x { + case x + when 1267650600228229401496703205376 then :beyond_long + when 10_000_000_000 then :beyond_int + when 1 then :fits_int + else :other + end + } + + [1267650600228229401496703205376, 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