[前][次][番号順一覧][スレッド一覧]

ruby-changes:29095

From: akr <ko1@a...>
Date: Fri, 7 Jun 2013 21:41:20 +0900 (JST)
Subject: [ruby-changes:29095] akr:r41147 (trunk): * bignum.c (rb_integer_pack): Renamed from rb_int_export.

akr	2013-06-07 21:41:02 +0900 (Fri, 07 Jun 2013)

  New Revision: 41147

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41147

  Log:
    * 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.

  Added files:
    trunk/ext/-test-/bignum/pack.c
    trunk/test/-ext-/bignum/test_pack.rb
  Removed files:
    trunk/ext/-test-/bignum/export.c
    trunk/ext/-test-/bignum/import.c
    trunk/test/-ext-/bignum/test_export.rb
    trunk/test/-ext-/bignum/test_import.rb
  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/ext/-test-/bignum/depend
    trunk/internal.h
    trunk/pack.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41146)
+++ ChangeLog	(revision 41147)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Jun  7 21:39:39 2013  Tanaka Akira  <akr@f...>
+
+	* 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@f...>
 
 	* bignum.c (integer_format_loop_setup): Extracted from rb_int_export
Index: pack.c
===================================================================
--- pack.c	(revision 41146)
+++ pack.c	(revision 41147)
@@ -1023,7 +1023,7 @@ pack_pack(VALUE ary, VALUE fmt) https://github.com/ruby/ruby/blob/trunk/pack.c#L1023
                     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) https://github.com/ruby/ruby/blob/trunk/pack.c#L2142
                     }
                     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;
                     }
Index: ext/-test-/bignum/export.c
===================================================================
--- ext/-test-/bignum/export.c	(revision 41146)
+++ ext/-test-/bignum/export.c	(revision 41147)
@@ -1,29 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/export.c#L0
-#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);
-}
Index: ext/-test-/bignum/import.c
===================================================================
--- ext/-test-/bignum/import.c	(revision 41146)
+++ ext/-test-/bignum/import.c	(revision 41147)
@@ -1,18 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/import.c#L0
-#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);
-}
Index: ext/-test-/bignum/depend
===================================================================
--- ext/-test-/bignum/depend	(revision 41146)
+++ ext/-test-/bignum/depend	(revision 41147)
@@ -1,4 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/depend#L1
 $(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
Index: ext/-test-/bignum/pack.c
===================================================================
--- ext/-test-/bignum/pack.c	(revision 0)
+++ ext/-test-/bignum/pack.c	(revision 41147)
@@ -0,0 +1,40 @@ https://github.com/ruby/ruby/blob/trunk/ext/-test-/bignum/pack.c#L1
+#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);
+}

Property changes on: ext/-test-/bignum/pack.c
___________________________________________________________________
Added: svn:eol-style
   + LF

Index: internal.h
===================================================================
--- internal.h	(revision 41146)
+++ internal.h	(revision 41147)
@@ -428,8 +428,8 @@ const char *rb_objspace_data_type_name(V https://github.com/ruby/ruby/blob/trunk/internal.h#L428
 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);
Index: bignum.c
===================================================================
--- bignum.c	(revision 41146)
+++ bignum.c	(revision 41147)
@@ -667,7 +667,7 @@ int_export_take_lowbits(int n, BDIGIT_DB https://github.com/ruby/ruby/blob/trunk/bignum.c#L667
  */
 
 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 numbi https://github.com/ruby/ruby/blob/trunk/bignum.c#L846
  * 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;
Index: test/-ext-/bignum/test_export.rb
===================================================================
--- test/-ext-/bignum/test_export.rb	(revision 41146)
+++ test/-ext-/bignum/test_export.rb	(revision 41147)
@@ -1,67 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_export.rb#L0
-# 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
Index: test/-ext-/bignum/test_import.rb
===================================================================
--- test/-ext-/bignum/test_import.rb	(revision 41146)
+++ test/-ext-/bignum/test_import.rb	(revision 41147)
@@ -1,54 +0,0 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_import.rb#L0
-# 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
Index: test/-ext-/bignum/test_pack.rb
===================================================================
--- test/-ext-/bignum/test_pack.rb	(revision 0)
+++ test/-ext-/bignum/test_pack.rb	(revision 41147)
@@ -0,0 +1,112 @@ https://github.com/ruby/ruby/blob/trunk/test/-ext-/bignum/test_pack.rb#L1
+# 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

Property changes on: test/-ext-/bignum/test_pack.rb
___________________________________________________________________
Added: svn:eol-style
   + LF


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]