diff options
author | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-19 08:26:33 +0000 |
---|---|---|
committer | shyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-19 08:26:33 +0000 |
commit | 8d81fc6df66ab4d839ceaf94f274da36b7fab295 (patch) | |
tree | e316707fad8091ba491bc7f5855c641955b45d96 /test/ruby | |
parent | fe9c4e615b69d06db554cf1116560b353b96a9ed (diff) |
merge revision(s) 20580:
* pack.c (pack_pack): fixed length for odd length string.
[ruby-dev:37283]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@22446 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_pack.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb index e67465b33a..a8f0176879 100644 --- a/test/ruby/test_pack.rb +++ b/test/ruby/test_pack.rb @@ -57,4 +57,44 @@ class TestPack < Test::Unit::TestCase assert_raises(RangeError) { [0x80000000].pack("U") } assert_raises(RangeError) { [0x100000000].pack("U") } end + + def test_pack_unpack_hH + assert_equal("\x01\xfe", ["10ef"].pack("h*")) + assert_equal("", ["10ef"].pack("h0")) + assert_equal("\x01\x0e", ["10ef"].pack("h3")) + assert_equal("\x01\xfe\x0", ["10ef"].pack("h5")) + assert_equal("\xff\x0f", ["fff"].pack("h3")) + assert_equal("\xff\x0f", ["fff"].pack("h4")) + assert_equal("\xff\x0f\0", ["fff"].pack("h5")) + assert_equal("\xff\x0f\0", ["fff"].pack("h6")) + assert_equal("\xff\x0f\0\0", ["fff"].pack("h7")) + assert_equal("\xff\x0f\0\0", ["fff"].pack("h8")) + + assert_equal("\x10\xef", ["10ef"].pack("H*")) + assert_equal("", ["10ef"].pack("H0")) + assert_equal("\x10\xe0", ["10ef"].pack("H3")) + assert_equal("\x10\xef\x0", ["10ef"].pack("H5")) + assert_equal("\xff\xf0", ["fff"].pack("H3")) + assert_equal("\xff\xf0", ["fff"].pack("H4")) + assert_equal("\xff\xf0\0", ["fff"].pack("H5")) + assert_equal("\xff\xf0\0", ["fff"].pack("H6")) + assert_equal("\xff\xf0\0\0", ["fff"].pack("H7")) + assert_equal("\xff\xf0\0\0", ["fff"].pack("H8")) + + assert_equal(["10ef"], "\x01\xfe".unpack("h*")) + assert_equal([""], "\x01\xfe".unpack("h0")) + assert_equal(["1"], "\x01\xfe".unpack("h1")) + assert_equal(["10"], "\x01\xfe".unpack("h2")) + assert_equal(["10e"], "\x01\xfe".unpack("h3")) + assert_equal(["10ef"], "\x01\xfe".unpack("h4")) + assert_equal(["10ef"], "\x01\xfe".unpack("h5")) + + assert_equal(["10ef"], "\x10\xef".unpack("H*")) + assert_equal([""], "\x10\xef".unpack("H0")) + assert_equal(["1"], "\x10\xef".unpack("H1")) + assert_equal(["10"], "\x10\xef".unpack("H2")) + assert_equal(["10e"], "\x10\xef".unpack("H3")) + assert_equal(["10ef"], "\x10\xef".unpack("H4")) + assert_equal(["10ef"], "\x10\xef".unpack("H5")) + end end |