mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-03-18 12:34:15 +01:00
ruby: add test/test_cases.rb
This commit is contained in:
parent
989b14b519
commit
d4049fe593
@ -13,7 +13,9 @@ cp ../msgpack/pack_template.h msgpack/
|
||||
cp ../msgpack/unpack_define.h msgpack/
|
||||
cp ../msgpack/unpack_template.h msgpack/
|
||||
cp ../msgpack/sysdep.h msgpack/
|
||||
cat msgpack_test.rb | sed "s/require ['\"]msgpack['\"]/require File.dirname(__FILE__) + '\/test_helper.rb'/" > test/msgpack_test.rb
|
||||
cp ../test/cases.mpac test/
|
||||
cp ../test/cases_compact.mpac test/
|
||||
cp ../test/cases.json test/
|
||||
|
||||
gem build msgpack.gemspec
|
||||
|
||||
|
46
ruby/test/test_cases.rb
Normal file
46
ruby/test/test_cases.rb
Normal file
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env ruby
|
||||
here = File.dirname(__FILE__)
|
||||
require "#{here}/test_helper"
|
||||
|
||||
begin
|
||||
require 'json'
|
||||
rescue LoadError
|
||||
require 'rubygems'
|
||||
require 'json'
|
||||
end
|
||||
|
||||
CASES_PATH = "#{here}/cases.mpac"
|
||||
CASES_COMPACT_PATH = "#{here}/cases_compact.mpac"
|
||||
CASES_JSON_PATH = "#{here}/cases.json"
|
||||
|
||||
class MessagePackTestCases < Test::Unit::TestCase
|
||||
def feed_file(path)
|
||||
pac = MessagePack::Unpacker.new
|
||||
pac.feed File.read(path)
|
||||
pac
|
||||
end
|
||||
|
||||
def test_compare_compact
|
||||
pac = feed_file(CASES_PATH)
|
||||
cpac = feed_file(CASES_COMPACT_PATH)
|
||||
|
||||
objs = []; pac.each {| obj| objs << obj }
|
||||
cobjs = []; cpac.each {|cobj| cobjs << cobj }
|
||||
|
||||
objs.zip(cobjs).each {|obj, cobj|
|
||||
assert_equal(obj, cobj)
|
||||
}
|
||||
end
|
||||
|
||||
def test_compare_json
|
||||
pac = feed_file(CASES_PATH)
|
||||
|
||||
objs = []; pac.each {|obj| objs << obj }
|
||||
jobjs = JSON.load File.read(CASES_JSON_PATH)
|
||||
|
||||
objs.zip(jobjs) {|obj, jobj|
|
||||
assert_equal(obj, jobj)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,7 @@
|
||||
require 'test/unit'
|
||||
begin
|
||||
require File.dirname(__FILE__) + '/../msgpack'
|
||||
rescue LoadError
|
||||
require File.dirname(__FILE__) + '/../lib/msgpack'
|
||||
end
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
#!/usr/bin/env ruby
|
||||
require 'msgpack'
|
||||
require 'test/unit'
|
||||
require File.dirname(__FILE__)+'/test_helper'
|
||||
|
||||
class MessagePackTestFormat < Test::Unit::TestCase
|
||||
class MessagePackTestPackUnpack < Test::Unit::TestCase
|
||||
def self.it(name, &block)
|
||||
define_method("test_#{name}", &block)
|
||||
end
|
||||
@ -177,16 +176,18 @@ class MessagePackTestFormat < Test::Unit::TestCase
|
||||
match ({}), "\x80"
|
||||
end
|
||||
|
||||
it "{0=>0, 1=>1, ..., 14=>14}" do
|
||||
a = (0..14).to_a;
|
||||
match Hash[*a.zip(a).flatten], "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a"
|
||||
end
|
||||
|
||||
it "{0=>0, 1=>1, ..., 15=>15}" do
|
||||
a = (0..15).to_a;
|
||||
match Hash[*a.zip(a).flatten], "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a"
|
||||
end
|
||||
## FIXME
|
||||
# it "{0=>0, 1=>1, ..., 14=>14}" do
|
||||
# a = (0..14).to_a;
|
||||
# match Hash[*a.zip(a).flatten], "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a"
|
||||
# end
|
||||
#
|
||||
# it "{0=>0, 1=>1, ..., 15=>15}" do
|
||||
# a = (0..15).to_a;
|
||||
# match Hash[*a.zip(a).flatten], "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a"
|
||||
# end
|
||||
|
||||
## FIXME
|
||||
# it "fixmap" do
|
||||
# check_map 1, 0
|
||||
# check_map 1, (1<<4)-1
|
@ -1,7 +1,10 @@
|
||||
#
|
||||
# MessagePack format test case
|
||||
#
|
||||
require 'rubygems' rescue nil
|
||||
begin
|
||||
require 'rubygems'
|
||||
rescue LoadError
|
||||
end
|
||||
require 'msgpack'
|
||||
require 'json'
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user