Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions language/case_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading