Skip to content

Commit b82c7d8

Browse files
committed
Cover more cases for ObjectSpace._id2ref
1 parent 72ce69e commit b82c7d8

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

spec/ruby/core/objectspace/_id2ref_spec.rb

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,43 @@
77
r.should == s
88
end
99

10-
it "retrieves an Integer by object_id" do
11-
f = 1
12-
r = ObjectSpace._id2ref(f.object_id)
13-
r.should == f
10+
it "retrieves true by object_id" do
11+
ObjectSpace._id2ref(true.object_id).should == true
12+
end
13+
14+
it "retrieves false by object_id" do
15+
ObjectSpace._id2ref(false.object_id).should == false
16+
end
17+
18+
it "retrieves nil by object_id" do
19+
ObjectSpace._id2ref(nil.object_id).should == nil
20+
end
21+
22+
it "retrieves a small Integer by object_id" do
23+
ObjectSpace._id2ref(1.object_id).should == 1
24+
ObjectSpace._id2ref((-42).object_id).should == -42
25+
end
26+
27+
it "retrieves a large Integer by object_id" do
28+
obj = 1 << 88
29+
ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
1430
end
1531

1632
it "retrieves a Symbol by object_id" do
17-
s = :sym
18-
r = ObjectSpace._id2ref(s.object_id)
19-
r.should == s
33+
ObjectSpace._id2ref(:sym.object_id).should.equal?(:sym)
34+
end
35+
36+
it "retrieves a String by object_id" do
37+
obj = "str"
38+
ObjectSpace._id2ref(obj.object_id).should.equal?(obj)
39+
end
40+
41+
it "retrieves a frozen literal String by object_id" do
42+
ObjectSpace._id2ref("frozen string literal _id2ref".freeze.object_id).should.equal?("frozen string literal _id2ref".freeze)
43+
end
44+
45+
it "retrieves an Encoding by object_id" do
46+
ObjectSpace._id2ref(Encoding::UTF_8.object_id).should.equal?(Encoding::UTF_8)
2047
end
2148

2249
it 'raises RangeError when an object could not be found' do

0 commit comments

Comments
 (0)