spec/mem_spec.rb in asciipack-0.2.2 vs spec/mem_spec.rb in asciipack-0.2.3
- old
+ new
@@ -1,15 +1,27 @@
# encoding: utf-8
require 'spec_helper'
-here = File.dirname(File.expand_path(__FILE__))
+describe "AsciiPack:memory" do
+ it "packer:num" do
+ check([1,1.1,-1.1,1.0/3.0,0xffffffffffffffff,-0x8000000000000000,0,Float::INFINITY] * 3)
+ end
-describe AsciiPack do
- it "num" do
- obj = [0,0xf,0xff,0xffff,0xffffffff,0xffffffffffffffff,-1,-0x80,-0x8000,-0x80000000,-0x8000000000000000,0.1,1.0000000000000002,-0.1,0.0,1/3,Float::INFINITY]
- obj = obj * 1000
- ap = AsciiPack.pack(obj)
- expect(AsciiPack.unpack(ap)).to eq(obj)
+ it "packer:str" do
+ check(["a"*100*1024*1024,"b"*1024*1024,"c"*1024] * 3)
+ end
+
+ def check (obj)
+ packer = AsciiPack::Packer.new
+ obj.each {|i|
+ packer.write i
+ GC.start
+ expect(AsciiPack.unpack(packer.to_s)).to eq(i)
+ GC.start
+ packer.clear
+ expect(packer.to_s).to eq("")
+ }
+ expect(AsciiPack.unpack(obj.to_asciipack)).to eq(obj)
end
end