diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-25 00:38:33 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2007-11-25 00:38:33 +0000 |
commit | f90fdbfc73ff41570a068b410692acd4812ef9f5 (patch) | |
tree | 028dc6426353bae4c53053a9a086a3d183a1fa57 /test | |
parent | 07ba43734dad3b26d3e0ecb6d3c75a05efce7d7d (diff) | |
download | ruby-f90fdbfc73ff41570a068b410692acd4812ef9f5.tar.gz |
add more roundtrip tests.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14010 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_integer.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb index 7e1535df86..7087084d37 100644 --- a/test/ruby/test_integer.rb +++ b/test/ruby/test_integer.rb @@ -569,6 +569,50 @@ class TestInteger < Test::Unit::TestCase } end + def test_printf_diu + VS.reverse_each {|a| + s = sprintf("%d", a) + b = s.to_i + assert_equal(a, b, "sprintf('%d', #{a}) = #{s.inspect}") + s = sprintf("%i", a) + b = s.to_i + assert_equal(a, b, "sprintf('%i', #{a}) = #{s.inspect}") + s = sprintf("%u", a) + b = s.to_i + assert_equal(a, b, "sprintf('%u', #{a}) = #{s.inspect}") + } + end + + def test_marshal + VS.reverse_each {|a| + s = Marshal.dump(a) + b = Marshal.load(s) + assert_equal(a, b, "Marshal.load(Marshal.dump(#{a}))") + } + end + + def test_pack + %w[c C s S s! S! i I l L l! L! q Q].each {|template| + size = [0].pack(template).size + mask = (1 << (size * 8)) - 1 + if /[A-Z]/ =~ template + min = 0 + max = (1 << (size * 8))-1 + else + min = -(1 << (size * 8 - 1)) + max = (1 << (size * 8 - 1)) - 1 + end + VS.reverse_each {|a| + s = [a].pack(template) + b = s.unpack(template)[0] + assert_equal(a & mask, b & mask, "[#{a}].pack(#{template.dump}).unpack(#{template.dump}) & #{mask}") + if min <= a && a <= max + assert_equal(a, b, "[#{a}].pack(#{template.dump}).unpack(#{template.dump})") + end + } + } + end + def test_Integer assert_raise(ArgumentError) {Integer("0x-1")} assert_raise(ArgumentError) {Integer("-0x-1")} |