Array#pack fails for Q/q directives
-----------------------------------
Key: JRUBY-1005
URL: http://jira.codehaus.org/browse/JRUBY-1005
Project: JRuby
Issue Type: Bug
Components: Core Classes/Modules
Environment: OS X 10.4.9, Java 1.5, JRuby 1.0.0RC2
Reporter: Daniel Berger
Priority: Minor
It appears that the 'Q/q' directive (64bit numbers) always returns an empty
string. Here are some sample tests:
{noformat}
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), [EMAIL
PROTECTED]("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), [EMAIL
PROTECTED]("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
{noformat}
And here are the results:
{noformat}
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
{noformat}
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe from this list please visit:
http://xircles.codehaus.org/manage_email