aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_pack.rb
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-01 13:08:20 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-12-01 13:08:20 +0000
commit001b9a1ef694d634549a34480205ecc1d98d9026 (patch)
tree58a26d5d86ba98caa360b4d319e5092f6a5ba2b1 /test/ruby/test_pack.rb
parent64602e56e80f99d9de5f6fcd4068d80724498271 (diff)
downloadruby-001b9a1ef694d634549a34480205ecc1d98d9026.tar.gz
Supports `buffer` and `offset` in `Array#pack`
* pack.c (pack_pack): Supports `buffer` and `offset` in `Array#pack`. [Feature #12754] [ruby-dev:49798] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_pack.rb')
-rw-r--r--test/ruby/test_pack.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb
index c5af6f2152..415dc78e60 100644
--- a/test/ruby/test_pack.rb
+++ b/test/ruby/test_pack.rb
@@ -812,4 +812,38 @@ EXPECTED
assert_raise_with_message(ArgumentError, /too few/) {ary.pack("AA")}
end;
end
+
+ def test_pack_with_buffer
+ buf = String.new(capacity: 100)
+
+ assert_raise_with_message(ArgumentError, /without buffer/) {
+ [0xDEAD_BEEF].pack('N', offset: 10)
+ }
+ assert_raise_with_message(ArgumentError, /too small/) {
+ [0xDEAD_BEEF].pack('N', buffer: buf, offset: 200)
+ }
+ assert_raise_with_message(RuntimeError, /frozen/) {
+ [0xDEAD_BEEF].pack('N', buffer: 'foo'.freeze)
+ }
+ assert_raise_with_message(TypeError, /into Integer/) {
+ [0xDEAD_BEEF].pack('N', buffer: buf, offset: '10')
+ }
+ assert_raise_with_message(TypeError, /must be String/) {
+ [0xDEAD_BEEF].pack('N', buffer: Object.new)
+ }
+
+ addr = [buf].pack('p')
+
+ [0xDEAD_BEEF].pack('N', buffer: buf)
+ assert_equal "\xDE\xAD\xBE\xEF", buf
+
+ [0xBABE_F00D].pack('N', buffer: buf, offset: 4)
+ assert_equal "\xDE\xAD\xBE\xEF\xBA\xBE\xF0\x0D", buf
+ assert_equal addr, [buf].pack('p')
+
+ [0xBAAD_FACE].pack('N', buffer: buf, offset: 10)
+ assert_equal "\xDE\xAD\xBE\xEF\xBA\xBE\xF0\x0D\0\0\xBA\xAD\xFA\xCE", buf
+
+ assert_equal addr, [buf].pack('p')
+ end
end