summaryrefslogtreecommitdiff
path: root/ruby/test/test_cases.rb
blob: bfb752e245fe71738c212f1cc21338ae65ff6b82 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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