Skip to content

Commit

Permalink
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions spec/std/proc_spec.cr
Original file line number Diff line number Diff line change
@@ -5,28 +5,44 @@ describe "Proc" do
str = MemoryIO.new
f = ->(x : Int32) { x.to_f }
f.to_s(str)
str.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}>")
{% if Crystal::VERSION == "0.18.0" %}
str.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}>")
{% else %}
str.to_s.should eq("#<(Int32 -> Float64):0x#{f.pointer.address.to_s(16)}>")
{% end %}
end

it "does to_s(io) when closured" do
str = MemoryIO.new
a = 1.5
f = ->(x : Int32) { x + a }
f.to_s(str)
str.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}:closure>")
{% if Crystal::VERSION == "0.18.0" %}
str.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}:closure>")
{% else %}
str.to_s.should eq("#<(Int32 -> Float64):0x#{f.pointer.address.to_s(16)}:closure>")
{% end %}
end

it "does to_s" do
str = MemoryIO.new
f = ->(x : Int32) { x.to_f }
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}>")
{% if Crystal::VERSION == "0.18.0" %}
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}>")
{% else %}
f.to_s.should eq("#<(Int32 -> Float64):0x#{f.pointer.address.to_s(16)}>")
{% end %}
end

it "does to_s when closured" do
str = MemoryIO.new
a = 1.5
f = ->(x : Int32) { x + a }
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}:closure>")
{% if Crystal::VERSION == "0.18.0" %}
f.to_s.should eq("#<Proc(Int32, Float64):0x#{f.pointer.address.to_s(16)}:closure>")
{% else %}
f.to_s.should eq("#<(Int32 -> Float64):0x#{f.pointer.address.to_s(16)}:closure>")
{% end %}
end

it "gets pointer" do

0 comments on commit 254f07b

Please sign in to comment.