test/packing_test.rb in packable-1.3.6 vs test/packing_test.rb in packable-1.3.7

- old
+ new

@@ -10,11 +10,11 @@ raise "baddly packed XYZ: #{s}" unless "xyz" == s XYZ.new end end -class TestingPack < Test::Unit::TestCase +class TestingPack < Minitest::Test context "Original form" do should "pack like before" do assert_equal "a \000\000\000\001", ["a",1,66].pack("A3N") end @@ -46,22 +46,22 @@ assert_equal "\002\001\000", 258.pack(:bytes => 3, :endian => :little) assert_equal 258, Integer.unpack("\002\001\000", :bytes => 3, :endian => :little) assert_equal (1<<24)-1, -1.pack(:bytes => 3).unpack(Integer, :bytes => 3, :signed => false) assert_equal -1, -1.pack(:bytes => 3).unpack(Integer, :bytes => 3, :signed => true) assert_equal 42, 42.pack('L').unpack(Integer, :bytes => 4, :endian => :native) - assert_raise(ArgumentError){ 42.pack(:endian => "Geronimo")} + assert_raises(ArgumentError){ 42.pack(:endian => "Geronimo")} end def test_bignum assert_equal 1.pack(:long), ((1 << 69) + 1).pack(:long) assert_equal "*" + ("\000" * 15), (42 << (8*15)).pack(:bytes => 16) assert_equal 42 << (8*15), (42 << (8*15)).pack(:bytes => 16).unpack(Integer, :bytes => 16) assert_equal 42 << (8*15), (42 << (8*15)).pack(:bytes => 16).unpack(Bignum, :bytes => 16) end def test_float - assert_raise(ArgumentError){ Math::PI.pack(:endian => "Geronimo")} + assert_raises(ArgumentError){ Math::PI.pack(:endian => "Geronimo")} assert_equal Math::PI, Math::PI.pack(:precision => :double, :endian => :native).unpack(Float, :precision => :double, :endian => :native) # Issue #1 assert_equal Math::PI.pack(:precision => :double), Math::PI.pack('G') assert_equal Math::PI.pack(:precision => :single), Math::PI.pack('g') assert_equal Math::PI.pack(:precision => :double), Math::PI.pack('G') @@ -74,21 +74,27 @@ assert_equal "abcd", s assert_equal 69, c assert_equal "!", io.read end + def test_io_read_nil + # library was failing to call read_without_packing when invoked with nil. + io = StringIO.new("should read(nil)") + assert_equal "should read(nil)", io.read(nil) + end + should "do basic type checking" do - assert_raise(TypeError) {"".unpack(42, :short)} + assert_raises(TypeError) {"".unpack(42, :short)} end context "Reading beyond the eof" do should "raises an EOFError when reading" do ["", "x"].each do |s| io = StringIO.new(s) - assert_raise(EOFError) {io.read(:double)} - assert_raise(EOFError) {io.read(:short)} - assert_raise(EOFError) {io.read(String, :bytes => 4)} + assert_raises(EOFError) {io.read(:double)} + assert_raises(EOFError) {io.read(:short)} + assert_raises(EOFError) {io.read(String, :bytes => 4)} end end should "return nil for unpacking" do assert_nil "".unpack(:double) @@ -117,10 +123,10 @@ end end should "be accessible only from that class and descendants" do assert_equal "Hello", "World".pack(:specific_writer) - assert_raise RuntimeError do + assert_raises RuntimeError do 6.pack(:specific_writer) end end end end