test/test_blocker.rb in binaryparse-0.2.7 vs test/test_blocker.rb in binaryparse-0.3.3
- old
+ new
@@ -516,6 +516,66 @@
now = Time.local(1985, 5, 30, 7, 6, 0)
assert_equal(now, b2.now)
end
+ def test_clone
+ bb = BBTest1.new
+ bb.foo = 32
+ bb.bar = 24
+
+ assert_equal(32, bb.foo)
+ assert_equal(24, bb.bar)
+
+ b2 = bb.clone
+ assert_equal(32, b2.foo)
+ assert_equal(24, b2.bar)
+
+ b2.foo = 42
+ assert_equal(42, b2.foo)
+ assert_equal(32, bb.foo)
+ end
+
+ def test_clone_some_more
+ bb = BBList.new
+ bb.header = 13
+ bb.footer = 42
+
+ ia = ItemA.new
+ ib = ItemB.new
+ ib.name = 'widget B'
+ bb.items << ia << ib
+
+ b2 = bb.clone
+ assert(13, b2.header)
+ b2.header = 21
+ assert(21, b2.header)
+ assert(13, bb.header)
+ end
+
+ class Nested < BinaryBlocker::Blocker
+ has_one :name, :string, :length => 20
+ end
+
+ class Parent < BinaryBlocker::Blocker
+ has_one :rtype, :string, :length => 10
+ has_one :nest, Nested
+ has_one :footer, :string, :length => 10
+ end
+
+ def test_clone_has_one
+ p = Parent.new
+ p.rtype = 'foo'
+ p.nest.name = 'bar'
+ p.footer = 'end'
+
+ assert_equal('foo', p.rtype)
+ assert_equal('bar', p.nest.name)
+ assert_equal('end', p.footer)
+
+ p2 = p.clone
+ assert_equal('foo', p2.rtype)
+ assert_equal('bar', p2.nest.name)
+ assert_equal('end', p2.footer)
+
+ end
end