From 6227f8a576ac5a27245aecc8e70cb2b8b1a4b0a0 Mon Sep 17 00:00:00 2001 From: Sampo Kuokkanen Date: Mon, 11 May 2026 21:19:19 +0900 Subject: [PATCH] Add specs for case/when with out-of-int-range Integer literals Add specs covering case/when 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. --- language/case_spec.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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