Exemple #1
0
    def test_empty(self):
        buffer = ByteBuffer()

        assert buffer.empty() is True
        buffer.write(b"abc")
        assert buffer.empty() is False
        buffer.discard()
        assert buffer.empty() is True
Exemple #2
0
    def test_write(self):
        buffer = ByteBuffer()

        buffer.write(b"abc")
        assert buffer.peek() == b"abc"
        buffer.write(b"def")
        assert buffer.peek() == b"abcdef"
Exemple #3
0
    def test_peek(self):
        buffer = ByteBuffer()
        buffer.write(b"abcdefghi")

        assert buffer.peek(slice(0, 1)) == b"a"
        assert buffer.peek(slice(3, 6)) == b"def"
        assert buffer.peek(slice(-2, -1)) == b"h"

        assert buffer.read() == b"abcdefghi"
Exemple #4
0
    def test_len(self):
        buffer = ByteBuffer()

        assert len(buffer) == 0
        buffer.write(b"abc")
        assert len(buffer) == 3
Exemple #5
0
    def test_read_all(self):
        buffer = ByteBuffer()
        buffer.write(b"abcdefghi")

        assert buffer.read() == b"abcdefghi"
        assert buffer.read() == b""
Exemple #6
0
    def test_discard_all(self):
        buffer = ByteBuffer()
        buffer.write(b"abcdefghi")

        assert buffer.discard() is None
        assert buffer.read() == b""