1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/spec/ruby/library/objectspace/memsize_of_spec.rb
2021-07-29 22:11:21 +02:00

34 lines
921 B
Ruby

require_relative '../../spec_helper'
require 'objspace'
describe "ObjectSpace.memsize_of" do
it "returns 0 for true, false and nil" do
ObjectSpace.memsize_of(true).should == 0
ObjectSpace.memsize_of(false).should == 0
ObjectSpace.memsize_of(nil).should == 0
end
it "returns 0 for small Integers" do
ObjectSpace.memsize_of(42).should == 0
end
it "returns 0 for literal Symbols" do
ObjectSpace.memsize_of(:abc).should == 0
end
it "returns a positive Integer for an Object" do
obj = Object.new
ObjectSpace.memsize_of(obj).should be_kind_of(Integer)
ObjectSpace.memsize_of(obj).should > 0
end
it "is larger if the Object has more instance variables" do
obj = Object.new
before = ObjectSpace.memsize_of(obj)
100.times do |i|
obj.instance_variable_set(:"@foo#{i}", nil)
end
after = ObjectSpace.memsize_of(obj)
after.should > before
end
end