Sha256: a36f044d64f14a252b32858affff3ab2abb86a669e88bb6af5893db9b3972208
Contents?: true
Size: 1.28 KB
Versions: 5
Compression:
Stored size: 1.28 KB
Contents
#!/usr/bin/env ruby require File.expand_path(File.join(File.dirname(__FILE__), "spec_common")) require 'bindata' describe BinData::ResumeByteAlignment do class ResumeAlignmentRecord < BinData::Record bit4 :a resume_byte_alignment bit4 :b end subject { ResumeAlignmentRecord.new } it "should reset read alignment" do subject.read "\x12\x34" subject.a.should == 1 subject.b.should == 3 end it "should reset write alignment" do subject.assign(:a => 2, :b => 7) subject.to_binary_s.should == "\x20\x70" end end describe BinData::BitAligned do it "should not apply to BinData::Primitives" do lambda { class BitAlignedPrimitive < BinData::Primitive bit_aligned end }.should raise_error end class BitString < BinData::String bit_aligned end class BitAlignedRecord < BinData::Record bit4 :preamble bit_string :str, :length => 2 bit4 :afterward end subject { BitAlignedRecord.new } its(:num_bytes) { should == 3 } it "should read" do subject.read("\x56\x36\x42") subject.should == {"preamble" => 5, "str" => "cd", "afterward" => 2} end it "should write" do subject.assign(:preamble => 5, :str => "ab", :afterward => 1) subject.to_binary_s.should == "\x56\x16\x21" end end
Version data entries
5 entries across 5 versions & 1 rubygems
Version | Path |
---|---|
bindata-1.4.3 | spec/alignment_spec.rb |
bindata-1.4.2 | spec/alignment_spec.rb |
bindata-1.4.1 | spec/alignment_spec.rb |
bindata-1.4.0 | spec/alignment_spec.rb |
bindata-1.3.1 | spec/alignment_spec.rb |