Skip to content
Open
Show file tree
Hide file tree
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 = 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
Expand Down
25 changes: 25 additions & 0 deletions language/if_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading