diff options
| author | Tomoyuki Sahara <[email protected]> | 2014-06-15 19:54:08 +0900 |
|---|---|---|
| committer | Tomoyuki Sahara <[email protected]> | 2014-06-15 19:54:08 +0900 |
| commit | 5b65ca3ebb3fb718138e1d23c4881a129b8606e2 (patch) | |
| tree | 88be8c9a72e80f0fe49eaf67239bdbcb97333ace /test | |
| parent | a0c4ca24067dc23ecbae59665e83cf49b8fa5bb1 (diff) | |
| parent | 7b2611ea28aad709d16f6196baabbdbdbd806087 (diff) | |
| download | mruby-5b65ca3ebb3fb718138e1d23c4881a129b8606e2.tar.gz mruby-5b65ca3ebb3fb718138e1d23c4881a129b8606e2.zip | |
Merge pull request #5 from take-cheeze/float
Add full support of float templates.
Diffstat (limited to 'test')
| -rw-r--r-- | test/pack.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/pack.rb b/test/pack.rb index 7789fb446..c7899e2d7 100644 --- a/test/pack.rb +++ b/test/pack.rb @@ -88,3 +88,36 @@ end assert('issue #1') do [1, 2].pack("nn") == "\000\001\000\002" end + +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 + +assert 'pack float' do + assert_pack 'e', "\x00\x00@@", [3.0] + assert_pack 'g', "@@\x00\x00", [3.0] + + 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_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 |
