Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: JRuby 1.0.2, JRuby 1.1b1
-
Component/s: Core Classes/Modules
-
Labels:None
-
Environment:OS X 10.4.9, Java 1.5, JRuby 1.0.0RC2
-
Testcase included:yes
-
Number of attachments :
Description
It appears that the 'Q/q' directive (64bit numbers) always returns an empty string. Here are some sample tests:
require 'test/unit'
class TC_Array_Pack_Q < Test::Unit::TestCase
def setup
@char_array = %w/alpha beta gamma/
@int_array = [-1, 0, 1, 128]
@float_array = [-1.5, 0.0, 1.5, 128.5]
@bignum1 = 2**63
end
def endian(data, n=4)
[1].pack('I') == [1].pack('N') ? data.gsub(/.{#{n}}/){ |s| s.reverse } : data
end
def test_pack_q
assert_equal(endian("\000\000\000\000\000\000\000\000", 8), [0].pack("q"))
assert_equal(endian("\001\000\000\000\000\000\000\000", 8), [1].pack("q"))
assert_equal(endian("\377\377\377\377\377\377\377\377", 8), [-1].pack("q"))
assert_equal(endian("\377\377\377\377\377\377\377\377", 8), @int_array.pack("q"))
assert_equal(endian("\377\377\377\377\377\377\377\377", 8), @float_array.pack("q"))
assert_equal(endian("\000\000\000\000\000\000\000\200", 8), [@bignum1].pack("q"))
end
def test_pack_q_expected_errors
assert_raises(TypeError){ @char_array.pack("q") }
assert_raises(RangeError){ [(2**128)].pack("q") }
end
def test_pack_Q
assert_equal(endian("\000\000\000\000\000\000\000\000", 8), [0].pack("Q"))
assert_equal(endian("\001\000\000\000\000\000\000\000", 8), [1].pack("Q"))
assert_equal(endian("\377\377\377\377\377\377\377\377", 8), [-1].pack("Q"))
assert_equal(endian("\377\377\377\377\377\377\377\377", 8), @int_array.pack("Q"))
assert_equal(endian("\377\377\377\377\377\377\377\377", 8), @float_array.pack("Q"))
assert_equal(endian("\000\000\000\000\000\000\000\200", 8), [@bignum1].pack("Q"))
end
def test_pack_Q_expected_errors
assert_raises(TypeError){ @char_array.pack("Q") }
assert_raises(RangeError){ [(2**128)].pack("Q") }
end
def teardown
@char_array = nil
@int_array = nil
@float_array = nil
@bignum1 = nil
end
end
And here are the results:
Loaded suite test/test_endian Started FFFF Finished in 0.168 seconds. 1) Failure: test_pack_Q(TC_Array_Pack_Q) [test/test_endian.rb:30]: <"\000\000\000\000\000\000\000\000"> expected but was <"">. 2) Failure: test_pack_Q_expected_errors(TC_Array_Pack_Q) [test/test_endian.rb:39]: <TypeError> exception expected but none was thrown. 3) Failure: test_pack_q(TC_Array_Pack_Q) [test/test_endian.rb:16]: <"\000\000\000\000\000\000\000\000"> expected but was <"">. 4) Failure: test_pack_q_expected_errors(TC_Array_Pack_Q) [test/test_endian.rb:25]: <TypeError> exception expected but none was thrown. 4 tests, 4 assertions, 4 failures, 0 errors
Still failing on trunk and 1.0 branch; probably too late to fix for 1.0.2, but try. Fix for 1.1.