last_data_recv: do not assume Unicorn includes all constants
[raindrops.git] / test / test_struct.rb
blob9792d5bf327e95f49fbc0e3ce8215a5249f795d0
1 require 'test/unit'
2 require 'raindrops'
4 class TestRaindrops < Test::Unit::TestCase
6   def test_struct_new
7     @rw = Raindrops::Struct.new(:r, :w)
8     assert @rw.kind_of?(Class)
9   end
11   TMP = Raindrops::Struct.new(:r, :w)
13   def test_init_basic
14     tmp = TMP.new
15     assert_equal 0, tmp.r
16     assert_equal 1, tmp.incr_r
17     assert_equal 1, tmp.r
18     assert_equal({ :r => 1, :w => 0 }, tmp.to_hash)
20     assert_equal 1, tmp[0]
21     assert_equal 0, tmp[1]
22     assert_equal [ :r, :w ], TMP::MEMBERS
23   end
25   def test_init
26     tmp = TMP.new(5, 6)
27     assert_equal({ :r => 5, :w => 6 }, tmp.to_hash)
28   end
30   def test_dup
31     a = TMP.new(5, 6)
32     b = a.dup
33     assert_equal({ :r => 5, :w => 6 }, b.to_hash)
34     assert_nothing_raised { 4.times { b.decr_r } }
35     assert_equal({ :r => 1, :w => 6 }, b.to_hash)
36     assert_equal({ :r => 5, :w => 6 }, a.to_hash)
37   end
39   class Foo < Raindrops::Struct.new(:a, :b, :c, :d)
40     def to_ary
41       @raindrops.to_ary
42     end
44     def hello
45       "world"
46     end
47   end
49   def test_subclass
50     assert_equal [0, 0, 0, 0], Foo.new.to_ary
51     assert_equal "world", Foo.new.hello
52   end
54 end