spec/format_spec.rb in asciipack-0.2.0 vs spec/format_spec.rb in asciipack-0.2.1

- old
+ new

@@ -2,11 +2,13 @@ require 'spec_helper' describe AsciiPack do it "intro" do - expect(AsciiPack.pack({"compact"=>true,"binary"=>0})).to eq('r2NcompactYMbinary0') + demo = {"compact"=>true,"binary"=>0} + expect(AsciiPack.pack(demo)).to eq('r2NcompactYMbinary0') + expect(AsciiPack.unpack('r2NcompactYMbinary0')).to eq(demo) end it "int 4" do format -1, T.int4, 2 format -8, T.int4, 2 @@ -68,10 +70,11 @@ check_each_other(1.0, T.float64 + '3ff0000000000000') check_each_other(1.0000000000000002, T.float64 + '3ff0000000000001') check_each_other(1.0000000000000004, T.float64 + '3ff0000000000002') check_each_other(1/3.0, T.float64 + '3fd5555555555555') expect(AsciiPack.pack(Float::NAN)).to eq(T.float64 + '7ff8000000000000') + expect(AsciiPack.unpack(T.float64 + '7ff8000000000000').nan?).to be true check_each_other(1 / 0.0, T.float64 + '7ff0000000000000') check_each_other(-1 / 0.0, T.float64 + 'fff0000000000000') end it "fixstr" do @@ -87,14 +90,12 @@ format "a" * 0x10, T.str8, 3 + 0x10 format "a" * 0xff, T.str8, 3 + 0xff end it "str 16" do - 100.times { format "a" * 0x100, T.str16, 5 + 0x100 format "a" * 0xffff, T.str16, 5 + 0xffff - } end it "str 32" do format "a" * 0x10000, T.str32, 9 + 0x10000 # FIXME too late @@ -146,11 +147,10 @@ it "recursive array" do array = [0] 1000.times { array = [array] } - ap = AsciiPack.pack(array) - expect(AsciiPack.unpack(ap)).to eq(array) + check_each_other(array, AsciiPack.pack(array)) end it "nil" do format nil, T.nil, 1 end