test/test_blocker.rb in binaryparse-0.1.0 vs test/test_blocker.rb in binaryparse-0.1.2

- old
+ new

@@ -406,7 +406,31 @@ assert_equal(b2.items[2].name, ia.name) assert_equal(b2.items[3].name, ib.name) assert_equal(b2.items[4].name, ib.name) assert_equal(b2.items[5].name, ib.name) end -end + + class BBDefaultTest < BinaryBlocker::Blocker + has_one :foo, :int16, :default => 7 + has_one :bar, :int16 + has_one :str, :string, :length => 20, :default => 'troaeipo' + end + def test_default + b = BBDefaultTest.new + assert_equal(7, b.foo) + assert_equal(nil, b.bar) + assert_equal('troaeipo', b.str) + + b.foo = nil + assert_equal(nil, b.foo) + b.bar = 3 + + buf = b.block + + b2 = BBDefaultTest.new(buf) + assert_equal(0, b2.foo) + assert_equal(3, b2.bar) + assert_equal('troaeipo', b2.str) + end + +end