diff --git a/spec/bitfield_spec.cr b/spec/bitfield_spec.cr index 112f3fb..6d57c2d 100644 --- a/spec/bitfield_spec.cr +++ b/spec/bitfield_spec.cr @@ -22,6 +22,14 @@ class TestTooMany < BitField(UInt16) num too_many, 17 end +class TestMethods < BitField(UInt8) + num bits, 8 + + def double_bits : Nil + self.bits <<= 1 + end +end + describe BitField do it "gets whole value" do bf = Test8.new 0xAF @@ -94,4 +102,10 @@ describe BitField do bf = TestTooMany.new 0x0000 end end + + it "allows new method definitions" do + bf = TestMethods.new 0b00000001 + bf.double_bits + bf.bits.should eq 0b00000010 + end end