summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--bignum.c4
-rw-r--r--ext/-test-/bignum/depend3
-rw-r--r--ext/-test-/bignum/export.c29
-rw-r--r--ext/-test-/bignum/import.c18
-rw-r--r--ext/-test-/bignum/pack.c40
-rw-r--r--internal.h4
-rw-r--r--pack.c4
-rw-r--r--test/-ext-/bignum/test_export.rb67
-rw-r--r--test/-ext-/bignum/test_import.rb54
-rw-r--r--test/-ext-/bignum/test_pack.rb112
11 files changed, 166 insertions, 176 deletions
diff --git a/ChangeLog b/ChangeLog
index 907787d928..cfcd7d0900 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Jun 7 21:39:39 2013 Tanaka Akira <akr@fsij.org>
+
+ * bignum.c (rb_integer_pack): Renamed from rb_int_export.
+ (rb_integer_unpack): Renamed from rb_int_import.
+
+ * internal.h, pack.c: Follow the above change.
+
Fri Jun 7 21:05:26 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (integer_format_loop_setup): Extracted from rb_int_export
diff --git a/bignum.c b/bignum.c
index cfad1b11f7..20e9804e4c 100644
--- a/bignum.c
+++ b/bignum.c
@@ -667,7 +667,7 @@ int_export_take_lowbits(int n, BDIGIT_DBL *ddp, int *numbits_in_dd_p)
*/
void *
-rb_int_export(VALUE val, int *signp, size_t *wordcount_allocated, void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails)
+rb_integer_pack(VALUE val, int *signp, size_t *wordcount_allocated, void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails)
{
int sign;
BDIGIT *dp;
@@ -846,7 +846,7 @@ int_import_push_bits(int data, int numbits, BDIGIT_DBL *ddp, int *numbits_in_dd_
* This function returns the imported integer as Fixnum or Bignum.
*/
VALUE
-rb_int_import(int sign, const void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails)
+rb_integer_unpack(int sign, const void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails)
{
VALUE num_bits, num_bdigits;
VALUE result;
diff --git a/ext/-test-/bignum/depend b/ext/-test-/bignum/depend
index 217aed9dac..8524e41ce6 100644
--- a/ext/-test-/bignum/depend
+++ b/ext/-test-/bignum/depend
@@ -1,4 +1,3 @@
$(OBJS): $(HDRS) $(ruby_headers)
-export.o: export.c $(top_srcdir)/internal.h
-import.o: import.c $(top_srcdir)/internal.h
+pack.o: pack.c $(top_srcdir)/internal.h
diff --git a/ext/-test-/bignum/export.c b/ext/-test-/bignum/export.c
deleted file mode 100644
index 56e4f9f6dc..0000000000
--- a/ext/-test-/bignum/export.c
+++ /dev/null
@@ -1,29 +0,0 @@
-#include "ruby.h"
-#include "internal.h"
-
-static VALUE
-rb_int_export_m(VALUE val, VALUE buf, VALUE wordorder, VALUE wordsize_arg, VALUE endian, VALUE nails)
-{
- int sign;
- size_t count = 0;
- void *ret;
- size_t wordsize = NUM2SIZET(wordsize_arg);
-
- if (!NIL_P(buf)) {
- StringValue(buf);
- rb_str_modify(buf);
- count = RSTRING_LEN(buf) / wordsize;
- }
-
- ret = rb_int_export(val,
- &sign, &count, NIL_P(buf) ? NULL : RSTRING_PTR(buf), count,
- NUM2INT(wordorder), wordsize, NUM2INT(endian), NUM2INT(nails));
-
- return rb_ary_new_from_args(3, INT2NUM(sign), ret ? rb_str_new(ret, wordsize * count) : Qnil, SIZET2NUM(count));
-}
-
-void
-Init_export(VALUE klass)
-{
- rb_define_method(rb_cInteger, "test_export", rb_int_export_m, 5);
-}
diff --git a/ext/-test-/bignum/import.c b/ext/-test-/bignum/import.c
deleted file mode 100644
index c50d855c44..0000000000
--- a/ext/-test-/bignum/import.c
+++ /dev/null
@@ -1,18 +0,0 @@
-#include "ruby.h"
-#include "internal.h"
-
-static VALUE
-rb_int_import_m(VALUE klass, VALUE sign, VALUE buf, VALUE wordcount, VALUE wordorder, VALUE wordsize, VALUE endian, VALUE nails)
-{
- StringValue(buf);
-
- return rb_int_import(NUM2INT(sign), RSTRING_PTR(buf),
- NUM2SIZET(wordcount), NUM2INT(wordorder), NUM2SIZET(wordsize),
- NUM2INT(endian), NUM2SIZET(nails));
-}
-
-void
-Init_import(VALUE klass)
-{
- rb_define_singleton_method(rb_cInteger, "test_import", rb_int_import_m, 7);
-}
diff --git a/ext/-test-/bignum/pack.c b/ext/-test-/bignum/pack.c
new file mode 100644
index 0000000000..5307db6f4b
--- /dev/null
+++ b/ext/-test-/bignum/pack.c
@@ -0,0 +1,40 @@
+#include "ruby.h"
+#include "internal.h"
+
+static VALUE
+rb_integer_pack_m(VALUE val, VALUE buf, VALUE wordorder, VALUE wordsize_arg, VALUE endian, VALUE nails)
+{
+ int sign;
+ size_t count = 0;
+ void *ret;
+ size_t wordsize = NUM2SIZET(wordsize_arg);
+
+ if (!NIL_P(buf)) {
+ StringValue(buf);
+ rb_str_modify(buf);
+ count = RSTRING_LEN(buf) / wordsize;
+ }
+
+ ret = rb_integer_pack(val,
+ &sign, &count, NIL_P(buf) ? NULL : RSTRING_PTR(buf), count,
+ NUM2INT(wordorder), wordsize, NUM2INT(endian), NUM2INT(nails));
+
+ return rb_ary_new_from_args(3, INT2NUM(sign), ret ? rb_str_new(ret, wordsize * count) : Qnil, SIZET2NUM(count));
+}
+
+static VALUE
+rb_integer_unpack_m(VALUE klass, VALUE sign, VALUE buf, VALUE wordcount, VALUE wordorder, VALUE wordsize, VALUE endian, VALUE nails)
+{
+ StringValue(buf);
+
+ return rb_integer_unpack(NUM2INT(sign), RSTRING_PTR(buf),
+ NUM2SIZET(wordcount), NUM2INT(wordorder), NUM2SIZET(wordsize),
+ NUM2INT(endian), NUM2SIZET(nails));
+}
+
+void
+Init_pack(VALUE klass)
+{
+ rb_define_method(rb_cInteger, "test_pack", rb_integer_pack_m, 5);
+ rb_define_singleton_method(rb_cInteger, "test_unpack", rb_integer_unpack_m, 7);
+}
diff --git a/internal.h b/internal.h
index c35b6b2916..31fdc90a5e 100644
--- a/internal.h
+++ b/internal.h
@@ -428,8 +428,8 @@ const char *rb_objspace_data_type_name(VALUE obj);
VALUE rb_thread_io_blocking_region(rb_blocking_function_t *func, void *data1, int fd);
/* bignum.c */
-void *rb_int_export(VALUE val, int *signp, size_t *wordcount_allocated, void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails);
-VALUE rb_int_import(int sign, const void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails);
+void *rb_integer_pack(VALUE val, int *signp, size_t *wordcount_allocated, void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails);
+VALUE rb_integer_unpack(int sign, const void *words, size_t wordcount, int wordorder, size_t wordsize, int endian, size_t nails);
/* io.c */
void rb_maygvl_fd_fix_cloexec(int fd);
diff --git a/pack.c b/pack.c
index f4c907cc2e..0f6812f07b 100644
--- a/pack.c
+++ b/pack.c
@@ -1023,7 +1023,7 @@ pack_pack(VALUE ary, VALUE fmt)
numbytes = 1;
buf = rb_str_new(NULL, numbytes);
- rb_int_export(from, &sign, NULL, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, 1, 1);
+ rb_integer_pack(from, &sign, NULL, RSTRING_PTR(buf), RSTRING_LEN(buf), 1, 1, 1, 1);
if (sign < 0)
rb_raise(rb_eArgError, "can't compress negative numbers");
@@ -2142,7 +2142,7 @@ pack_unpack(VALUE str, VALUE fmt)
}
else {
s++;
- UNPACK_PUSH(rb_int_import(1, s0, s-s0, 1, 1, 1, 1));
+ UNPACK_PUSH(rb_integer_unpack(1, s0, s-s0, 1, 1, 1, 1));
len--;
s0 = s;
}
diff --git a/test/-ext-/bignum/test_export.rb b/test/-ext-/bignum/test_export.rb
deleted file mode 100644
index 3c1fc2e5e7..0000000000
--- a/test/-ext-/bignum/test_export.rb
+++ /dev/null
@@ -1,67 +0,0 @@
-# coding: ASCII-8BIT
-
-require 'test/unit'
-require "-test-/bignum"
-
-class TestBignum < Test::Unit::TestCase
- class TestExport < Test::Unit::TestCase
- def test_export_zero
- assert_equal([0, "", 0], 0.test_export(nil, 1, 1, 1, 0))
- end
-
- def test_argument_check
- assert_raise(ArgumentError) { 0.test_export(nil, 0, 1, 1, 0) }
- assert_raise(ArgumentError) { 0.test_export(nil, 1, 1, 2, 0) }
- assert_raise(ArgumentError) { 0.test_export(nil, 1, 0, 1, 0) }
- assert_raise(ArgumentError) { 0.test_export(nil, 1, 1, 1, 8) }
-
- # assume sizeof(ssize_t) == sizeof(intptr_t)
- assert_raise(ArgumentError) { 0.test_export(nil, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
- end
-
- def test_export_wordsize
- assert_equal([1, "\x01", 1], 1.test_export(nil, 1, 1, 1, 0))
- assert_equal([1, "\x00\x01", 1], 1.test_export(nil, 1, 2, 1, 0))
- assert_equal([1, "\x00\x00\x01", 1], 1.test_export(nil, 1, 3, 1, 0))
- assert_equal([1, "\x01", 1], 1.test_export(nil, 1, 1, -1, 0))
- assert_equal([1, "\x01\x00", 1], 1.test_export(nil, 1, 2, -1, 0))
- assert_equal([1, "\x01\x00\x00", 1], 1.test_export(nil, 1, 3, -1, 0))
- end
-
- def test_export_fixed_buffer
- assert_equal([0, "\x00\x00", 2], 0.test_export("xx", 1, 1, 1, 0))
- assert_equal([1, "\x00\x01", 2], 0x01.test_export("xx", 1, 1, 1, 0))
- assert_equal([1, "\x02\x01", 2], 0x0201.test_export("xx", 1, 1, 1, 0))
- assert_equal([2, "\x02\x01", 2], 0x030201.test_export("xx", 1, 1, 1, 0))
- assert_equal([2, "\x02\x01", 2], 0x04030201.test_export("xx", 1, 1, 1, 0))
- assert_equal([0, "\x00\x00", 2], 0.test_export("xx", -1, 1, 1, 0))
- assert_equal([1, "\x01\x00", 2], 0x01.test_export("xx", -1, 1, 1, 0))
- assert_equal([1, "\x01\x02", 2], 0x0201.test_export("xx", -1, 1, 1, 0))
- assert_equal([2, "\x01\x02", 2], 0x030201.test_export("xx", -1, 1, 1, 0))
- assert_equal([2, "\x01\x02", 2], 0x04030201.test_export("xx", -1, 1, 1, 0))
- end
-
- def test_export_wordorder_and_endian
- assert_equal([1, "\x12\x34\x56\x78", 2], 0x12345678.test_export(nil, 1, 2, 1, 0))
- assert_equal([1, "\x34\x12\x78\x56", 2], 0x12345678.test_export(nil, 1, 2, -1, 0))
- assert_equal([1, "\x56\x78\x12\x34", 2], 0x12345678.test_export(nil, -1, 2, 1, 0))
- assert_equal([1, "\x78\x56\x34\x12", 2], 0x12345678.test_export(nil, -1, 2, -1, 0))
- end
-
- def test_export_native_endian
- assert_equal([1, [0x1234].pack("S!"), 1], 0x1234.test_export(nil, 1, 2, 0, 0))
- end
-
- def test_export_nail
- assert_equal([1, "\x01\x00\x00\x00\x01\x01", 6], 0b100011.test_export(nil, 1, 1, 1, 7))
- assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8], 0x12345678.test_export(nil, 1, 1, 1, 4))
- assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4], 0x12345678.test_export(nil, 1, 2, 1, 8))
- end
-
- def test_export_sign
- assert_equal([-1, "\x01", 1], (-1).test_export(nil, 1, 1, 1, 0))
- assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8], (-0x8070605040302010).test_export(nil, 1, 1, 1, 0))
- end
-
- end
-end
diff --git a/test/-ext-/bignum/test_import.rb b/test/-ext-/bignum/test_import.rb
deleted file mode 100644
index 5a456508fc..0000000000
--- a/test/-ext-/bignum/test_import.rb
+++ /dev/null
@@ -1,54 +0,0 @@
-# coding: ASCII-8BIT
-
-require 'test/unit'
-require "-test-/bignum"
-
-class TestBignum < Test::Unit::TestCase
- class TestImport < Test::Unit::TestCase
- def test_import_zero
- assert_equal(0, Integer.test_import(0, "", 1, 1, 1, 1, 0))
- end
-
- def test_argument_check
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 0, 1, 1, 0) }
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 1, 1, 2, 0) }
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 1, 0, 1, 0) }
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 1, 1, 1, 8) }
-
- # assume sizeof(ssize_t) == sizeof(intptr_t)
- assert_raise(ArgumentError) { Integer.test_import(1, "x", 1, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
- end
-
- def test_import_wordsize
- assert_equal(1, Integer.test_import(1, "\x01", 1, 1, 1, 1, 0))
- assert_equal(1, Integer.test_import(1, "\x00\x01", 1, 1, 2, 1, 0))
- assert_equal(1, Integer.test_import(1, "\x00\x00\x01", 1, 1, 3, 1, 0))
- assert_equal(1, Integer.test_import(1, "\x01", 1, 1, 1, -1, 0))
- assert_equal(1, Integer.test_import(1, "\x01\x00", 1, 1, 2, -1, 0))
- assert_equal(1, Integer.test_import(1, "\x01\x00\x00", 1, 1, 3, -1, 0))
- end
-
- def test_import_wordorder_and_endian
- assert_equal(0x01020304, Integer.test_import(1, "\x01\x02\x03\x04", 2, 1, 2, 1, 0))
- assert_equal(0x02010403, Integer.test_import(1, "\x01\x02\x03\x04", 2, 1, 2, -1, 0))
- assert_equal(0x03040102, Integer.test_import(1, "\x01\x02\x03\x04", 2, -1, 2, 1, 0))
- assert_equal(0x04030201, Integer.test_import(1, "\x01\x02\x03\x04", 2, -1, 2, -1, 0))
- end
-
- def test_import_native_endian
- assert_equal("\x12\x34".unpack("S!")[0], Integer.test_import(1, "\x12\x34", 1, 1, 2, 0, 0))
- end
-
- def test_import_nail
- assert_equal(0b100011, Integer.test_import(1, "\x01\x00\x00\x00\x01\x01", 6, 1, 1, 1, 7))
- assert_equal(0x12345678, Integer.test_import(1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 1, 1, 4))
- assert_equal(0x12345678, Integer.test_import(1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4, 1, 2, 1, 8))
- end
-
- def test_import_sign
- assert_equal(-1, Integer.test_import(-1, "\x01", 1, 1, 1, 1, 0))
- assert_equal(-0x8070605040302010, Integer.test_import(-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 1, 1, 0))
- end
-
- end
-end
diff --git a/test/-ext-/bignum/test_pack.rb b/test/-ext-/bignum/test_pack.rb
new file mode 100644
index 0000000000..3dae027539
--- /dev/null
+++ b/test/-ext-/bignum/test_pack.rb
@@ -0,0 +1,112 @@
+# coding: ASCII-8BIT
+
+require 'test/unit'
+require "-test-/bignum"
+
+class TestBignum < Test::Unit::TestCase
+ class TestPack < Test::Unit::TestCase
+ def test_pack_zero
+ assert_equal([0, "", 0], 0.test_pack(nil, 1, 1, 1, 0))
+ end
+
+ def test_argument_check
+ assert_raise(ArgumentError) { 0.test_pack(nil, 0, 1, 1, 0) }
+ assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1, 2, 0) }
+ assert_raise(ArgumentError) { 0.test_pack(nil, 1, 0, 1, 0) }
+ assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1, 1, 8) }
+
+ # assume sizeof(ssize_t) == sizeof(intptr_t)
+ assert_raise(ArgumentError) { 0.test_pack(nil, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
+ end
+
+ def test_pack_wordsize
+ assert_equal([1, "\x01", 1], 1.test_pack(nil, 1, 1, 1, 0))
+ assert_equal([1, "\x00\x01", 1], 1.test_pack(nil, 1, 2, 1, 0))
+ assert_equal([1, "\x00\x00\x01", 1], 1.test_pack(nil, 1, 3, 1, 0))
+ assert_equal([1, "\x01", 1], 1.test_pack(nil, 1, 1, -1, 0))
+ assert_equal([1, "\x01\x00", 1], 1.test_pack(nil, 1, 2, -1, 0))
+ assert_equal([1, "\x01\x00\x00", 1], 1.test_pack(nil, 1, 3, -1, 0))
+ end
+
+ def test_pack_fixed_buffer
+ assert_equal([0, "\x00\x00", 2], 0.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([1, "\x00\x01", 2], 0x01.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([1, "\x02\x01", 2], 0x0201.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([2, "\x02\x01", 2], 0x030201.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([2, "\x02\x01", 2], 0x04030201.test_pack("xx", 1, 1, 1, 0))
+ assert_equal([0, "\x00\x00", 2], 0.test_pack("xx", -1, 1, 1, 0))
+ assert_equal([1, "\x01\x00", 2], 0x01.test_pack("xx", -1, 1, 1, 0))
+ assert_equal([1, "\x01\x02", 2], 0x0201.test_pack("xx", -1, 1, 1, 0))
+ assert_equal([2, "\x01\x02", 2], 0x030201.test_pack("xx", -1, 1, 1, 0))
+ assert_equal([2, "\x01\x02", 2], 0x04030201.test_pack("xx", -1, 1, 1, 0))
+ end
+
+ def test_pack_wordorder_and_endian
+ assert_equal([1, "\x12\x34\x56\x78", 2], 0x12345678.test_pack(nil, 1, 2, 1, 0))
+ assert_equal([1, "\x34\x12\x78\x56", 2], 0x12345678.test_pack(nil, 1, 2, -1, 0))
+ assert_equal([1, "\x56\x78\x12\x34", 2], 0x12345678.test_pack(nil, -1, 2, 1, 0))
+ assert_equal([1, "\x78\x56\x34\x12", 2], 0x12345678.test_pack(nil, -1, 2, -1, 0))
+ end
+
+ def test_pack_native_endian
+ assert_equal([1, [0x1234].pack("S!"), 1], 0x1234.test_pack(nil, 1, 2, 0, 0))
+ end
+
+ def test_pack_nail
+ assert_equal([1, "\x01\x00\x00\x00\x01\x01", 6], 0b100011.test_pack(nil, 1, 1, 1, 7))
+ assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8], 0x12345678.test_pack(nil, 1, 1, 1, 4))
+ assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4], 0x12345678.test_pack(nil, 1, 2, 1, 8))
+ end
+
+ def test_pack_sign
+ assert_equal([-1, "\x01", 1], (-1).test_pack(nil, 1, 1, 1, 0))
+ assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8], (-0x8070605040302010).test_pack(nil, 1, 1, 1, 0))
+ end
+
+ def test_unpack_zero
+ assert_equal(0, Integer.test_unpack(0, "", 1, 1, 1, 1, 0))
+ end
+
+ def test_argument_check
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 0, 1, 1, 0) }
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 1, 2, 0) }
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 0, 1, 0) }
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 1, 1, 8) }
+
+ # assume sizeof(ssize_t) == sizeof(intptr_t)
+ assert_raise(ArgumentError) { Integer.test_unpack(1, "x", 1, 1, 1 << ([""].pack("p").length * 8 - 1), 1, 0) }
+ end
+
+ def test_unpack_wordsize
+ assert_equal(1, Integer.test_unpack(1, "\x01", 1, 1, 1, 1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x00\x01", 1, 1, 2, 1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x00\x00\x01", 1, 1, 3, 1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x01", 1, 1, 1, -1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x01\x00", 1, 1, 2, -1, 0))
+ assert_equal(1, Integer.test_unpack(1, "\x01\x00\x00", 1, 1, 3, -1, 0))
+ end
+
+ def test_unpack_wordorder_and_endian
+ assert_equal(0x01020304, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, 1, 2, 1, 0))
+ assert_equal(0x02010403, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, 1, 2, -1, 0))
+ assert_equal(0x03040102, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, -1, 2, 1, 0))
+ assert_equal(0x04030201, Integer.test_unpack(1, "\x01\x02\x03\x04", 2, -1, 2, -1, 0))
+ end
+
+ def test_unpack_native_endian
+ assert_equal("\x12\x34".unpack("S!")[0], Integer.test_unpack(1, "\x12\x34", 1, 1, 2, 0, 0))
+ end
+
+ def test_unpack_nail
+ assert_equal(0b100011, Integer.test_unpack(1, "\x01\x00\x00\x00\x01\x01", 6, 1, 1, 1, 7))
+ assert_equal(0x12345678, Integer.test_unpack(1, "\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 1, 1, 4))
+ assert_equal(0x12345678, Integer.test_unpack(1, "\x00\x12\x00\x34\x00\x56\x00\x78", 4, 1, 2, 1, 8))
+ end
+
+ def test_unpack_sign
+ assert_equal(-1, Integer.test_unpack(-1, "\x01", 1, 1, 1, 1, 0))
+ assert_equal(-0x8070605040302010, Integer.test_unpack(-1, "\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 1, 1, 0))
+ end
+
+ end
+end