1 # $Id: test_hash.rb 1 2005-03-26 01:45:38Z tilman $
8 def initialize(key, value)
9 @key = key.to_str.dup.freeze
10 @value = value.to_str.dup.freeze
16 @hash = {"artist" => HashEntry.new("artist", "Amon Amarth"),
17 "title" => HashEntry.new("title", "Death In Fire")}
30 class HashTest < Test::Unit::TestCase
32 data = HashTestData.new.to_eet
37 assert_nothing_raised do
38 stream = Eet::Stream.deserialize(data)
41 assert_equal(1, stream.length)
42 assert_equal("HashTest", stream.first.tag)
45 assert_nothing_raised do
46 stream = Eet::Stream.deserialize(stream.first.data)
49 assert_equal(2, stream.length)
52 hashlist = stream.find_all { |c| c.tag == "hash" }
53 assert_equal(2, hashlist.length)
55 hash = {"artist" => "Amon Amarth",
56 "title" => "Death In Fire"}
57 hash.each do |key, value|
60 assert_nothing_raised do
61 d = hashlist.shift.data
62 str_stream = Eet::Stream.deserialize(d)
65 assert_equal(1, str_stream.length)
66 assert_equal("HashEntry", str_stream.first.tag)
70 assert_nothing_raised do
71 foo = Eet::Stream.deserialize(str_stream.first.data)
74 assert_equal(2, foo.length)
76 {"key" => key, "value" => value}.each do |tag, data|
77 found = foo.find { |i| i.tag == tag }
79 assert_equal(data + "\0", found.data)
83 assert_equal([], hashlist)