Skip to content

Feature request: BitReader literal for testing. #7

@vi

Description

@vi

It should be easy to test code that is consuming BitReader. For this it should be easy to specify specific sequence of bits in a test.

Prototype:

fn testbits(x:&str) -> BitReader<impl Read, impl Endianness> {
    let mut v = Vec::new();
    {
        let c = std::io::Cursor::new(&mut v);
        let mut w = bitstream_io::write::BitWriter::endian(c, bitstream_io::BE{});
        for b in x.as_bytes() {
            w.write_bit(b == &b'1');
        }
        while !w.byte_aligned() {
            w.write_bit(false);
        }
    }
    let c = std::io::Cursor::new(v);
    BitReader::endian(c, bitstream_io::BE{})
}

#[test]
fn test() {
    let mut r = testbits("110");
    assert_eq!(r.read_bit().unwrap(), true);
    assert_eq!(r.read_bit().unwrap(), true);
    assert_eq!(r.read_bit().unwrap(), false);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions