Permalink
Browse files

specs for Marshal.dump/load Integer

  • Loading branch information...
Nikolai Lugovoi
Nikolai Lugovoi committed Mar 26, 2011
1 parent cf71b7d commit b072fff744a3346ab1e09d5bfd308e706c91bf83
Showing with 77 additions and 0 deletions.
  1. +36 −0 spec/ruby/core/marshal/dump_spec.rb
  2. +41 −0 spec/ruby/core/marshal/load_spec.rb
@@ -392,4 +392,40 @@
Marshal.dump(obj).should == "\x04\bo:2MarshalSpec::BasicObjectSubWithRespondToFalse\x00"
end
end
describe "for an Integer" do
it "dumps an Integer 8" do
Marshal.dump(8).should == "\004\bi\r"
end
it "dumps and Integer -8" do
Marshal.dump(-8).should == "\004\bi\363"
end
it "dumps an Integer 1234" do
Marshal.dump(1234).should == "\004\bi\002\322\004"
end
it "dumps an Integer -1234" do
Marshal.dump(-1234).should == "\004\bi\376.\373"
end
it "dumps an Integer 4611686018427387903" do
Marshal.dump(4611686018427387903).should == "\004\bl+\t\377\377\377\377\377\377\377?"
end
it "dumps an Integer -4611686018427387903" do
Marshal.dump(-4611686018427387903).should == "\004\bl-\t\377\377\377\377\377\377\377?"
end
it "dumps an Integer 2361183241434822606847" do
Marshal.dump(2361183241434822606847).should == "\004\bl+\n\377\377\377\377\377\377\377\377\177\000"
end
it "dumps an Integer -2361183241434822606847" do
Marshal.dump(-2361183241434822606847).should == "\004\bl-\n\377\377\377\377\377\377\377\377\177\000"
end
end
end
@@ -426,4 +426,45 @@
end
end
describe "for a Integer" do
it "loads an Integer 8" do
Marshal.load("\004\bi\r" ).should == 8
end
it "loads and Integer -8" do
Marshal.load("\004\bi\363" ).should == -8
end
it "loads an Integer 1234" do
Marshal.load("\004\bi\002\322\004").should == 1234
end
it "loads an Integer -1234" do
Marshal.load("\004\bi\376.\373").should == -1234
end
it "loads an Integer 4611686018427387903" do
Marshal.load("\004\bl+\t\377\377\377\377\377\377\377?").should == 4611686018427387903
end
it "loads an Integer -4611686018427387903" do
Marshal.load("\004\bl-\t\377\377\377\377\377\377\377?").should == -4611686018427387903
end
it "loads an Integer 2361183241434822606847" do
Marshal.load("\004\bl+\n\377\377\377\377\377\377\377\377\177\000").should == 2361183241434822606847
end
it "loads an Integer -2361183241434822606847" do
Marshal.load("\004\bl-\n\377\377\377\377\377\377\377\377\177\000").should == -2361183241434822606847
end
if 0.size == 8 # for platforms like x86_64
it "roundtrips 4611686018427387903 from dump/load correctly" do
Marshal.load(Marshal.dump(4611686018427387903)).should == 4611686018427387903
end
end
end
end

0 comments on commit b072fff

Please sign in to comment.