def test_alloc_text_and_data(self): buf = SegmentBuilder() buf.allocate(32) buf.alloc_text(0, b'foo') buf.alloc_text(8, None) buf.alloc_text(16, b'bar') buf.alloc_data(24, b'bar') s = buf.as_string() print() print_buffer(s) assert s == b('\x0D\x00\x00\x00\x22\x00\x00\x00' # ptr to 'foo' '\x00\x00\x00\x00\x00\x00\x00\x00' # NULL '\x09\x00\x00\x00\x22\x00\x00\x00' # ptr to text 'bar' (4 items) '\x09\x00\x00\x00\x1A\x00\x00\x00' # ptr to data 'bar' (3 items) 'foo\x00\x00\x00\x00\x00' 'bar\x00\x00\x00\x00\x00' 'bar\x00\x00\x00\x00\x00')
def _print(self): print_buffer(self.as_string())