def test_distance_only_measured_to_next_matching_byte(): b = ByteStream() b.write(b"abcabc") distance = b.until(97) assert distance == 1 distance = b.until(98) assert distance == 2 distance = b.until(99) assert distance == 3
def test_can_find_bytes(): b = ByteStream() b.write(b"abc") distance = b.until(97) assert distance == 1 distance = b.until(98) assert distance == 2 distance = b.until(99) assert distance == 3
def test_can_find_bytes_several_chunks_ahead(): b = ByteStream() b.write(b"xxx") b.write(b"xxx") b.write(b"xxx") b.write(b"abc") distance = b.until(97) assert distance == 10 distance = b.until(98) assert distance == 11 distance = b.until(99) assert distance == 12
def test_distance_changes_after_read(): b = ByteStream() b.write(b"abcbca") distance = b.until(97) assert distance == 1 distance = b.until(98) assert distance == 2 distance = b.until(99) assert distance == 3 b.read(3) distance = b.until(97) assert distance == 3 distance = b.until(98) assert distance == 1 distance = b.until(99) assert distance == 2
def test_cannot_find_anything_if_empty(): b = ByteStream() distance = b.until(97) assert distance is None
def test_cannot_find_byte_not_written(): b = ByteStream() b.write(b"abc") distance = b.until(100) assert distance is None