summaryrefslogtreecommitdiffhomepage
path: root/test
diff options
context:
space:
mode:
authortake_cheeze <[email protected]>2014-06-14 13:16:13 +0900
committertake_cheeze <[email protected]>2014-06-14 13:25:00 +0900
commit8f4b7ac15c77f24952364f1b3b1ac42e2e52ebd5 (patch)
treed5a6c984a017c0cbe8c3e28d59a6a72a2cfe28c2 /test
parent514450e891e015efa9fd01f13a46863d4f118c13 (diff)
downloadmruby-8f4b7ac15c77f24952364f1b3b1ac42e2e52ebd5.tar.gz
mruby-8f4b7ac15c77f24952364f1b3b1ac42e2e52ebd5.zip
Support float/double unpacking.
Diffstat (limited to 'test')
-rw-r--r--test/pack.rb41
1 files changed, 26 insertions, 15 deletions
diff --git a/test/pack.rb b/test/pack.rb
index 02265f126..c7899e2d7 100644
--- a/test/pack.rb
+++ b/test/pack.rb
@@ -89,24 +89,35 @@ assert('issue #1') do
[1, 2].pack("nn") == "\000\001\000\002"
end
-assert 'pack float' do
- assert_equal "\x00\x00@@", [3.0].pack('e')
- assert_equal "@@\x00\x00", [3.0].pack('g')
+def assert_pack tmpl, packed, unpacked
+ assert_equal packed, unpacked.pack(tmpl)
+ assert_equal unpacked, packed.unpack(tmpl)
+end
+
+PACK_IS_LITTLE_ENDIAN = "\x01\00".unpack('S')[0] == 0x01
- native = [3.0].pack 'f'
- assert_true native == "\x00\x00@@" or native == "@@\x00\x00"
+assert 'pack float' do
+ assert_pack 'e', "\x00\x00@@", [3.0]
+ assert_pack 'g', "@@\x00\x00", [3.0]
- native = [3.0].pack 'F'
- assert_true native == "\x00\x00@@" or native == "@@\x00\x00"
+ if PACK_IS_LITTLE_ENDIAN
+ assert_pack 'f', "\x00\x00@@", [3.0]
+ assert_pack 'F', "\x00\x00@@", [3.0]
+ else
+ assert_pack 'f', "@@\x00\x00", [3.0]
+ assert_pack 'F', "@@\x00\x00", [3.0]
+ end
end
assert 'pack double' do
- assert_equal "\x00\x00\x00\x00\x00\x00\b@", [3.0].pack('E')
- assert_equal "@\b\x00\x00\x00\x00\x00\x00", [3.0].pack('G')
-
- native = [3.0].pack 'd'
- assert_true native == "\x00\x00\x00\x00\x00\x00\b@" or native == "@\b\x00\x00\x00\x00\x00\x00"
-
- native = [3.0].pack 'D'
- assert_true native == "\x00\x00\x00\x00\x00\x00\b@" or native == "@\b\x00\x00\x00\x00\x00\x00"
+ assert_pack 'E', "\x00\x00\x00\x00\x00\x00\b@", [3.0]
+ assert_pack 'G', "@\b\x00\x00\x00\x00\x00\x00", [3.0]
+
+ if PACK_IS_LITTLE_ENDIAN
+ assert_pack 'd', "\x00\x00\x00\x00\x00\x00\b@", [3.0]
+ assert_pack 'D', "\x00\x00\x00\x00\x00\x00\b@", [3.0]
+ else
+ assert_pack 'd', "@\b\x00\x00\x00\x00\x00\x00", [3.0]
+ assert_pack 'D', "@\b\x00\x00\x00\x00\x00\x00", [3.0]
+ end
end