def test_next_char(text):
    buf = DecodeBuffer(text)
    chars = []
    try:
        while True:
            chars.append(buf.next_char())
    except StopIteration:
        pass
    assert buf.exhausted()
    assert u''.join(chars) == text
Exemplo n.º 2
0
def test_next_char(text):
    buf = DecodeBuffer(text.encode('utf8'), len(text))
    chars = []
    try:
        while True:
            ch = buf.next_char().decode('utf8')
            chars.append(ch)
    except StopIteration:
        pass
    assert buf.exhausted()
    assert u''.join(chars) == text
def test_readn_buffer(text, sizes):
    buf = DecodeBuffer(text)
    strings = []
    for n in sizes:
        s = buf.get_chars(n)
        if not buf.exhausted():
            assert len(s) == n
        else:
            assert len(s) <= n
        strings.append(s)
    assert ''.join(strings) == text[:sum(sizes)]
Exemplo n.º 4
0
def test_readn_buffer(text, sizes):
    buf = DecodeBuffer(text.encode('utf8'), len(text))
    strings = []
    for n in sizes:
        chars, size = buf.get_chars(n)
        s = chars.decode('utf8')
        assert size == len(s)
        if not buf.exhausted():
            assert len(s) == n
        else:
            assert len(s) <= n
        strings.append(s)
    assert ''.join(strings) == text[:sum(sizes)]
def test_read_buffer(text):
    buf = DecodeBuffer(text)
    assert buf.get_chars(-1) == text
    assert buf.exhausted()
Exemplo n.º 6
0
def test_read_buffer(text):
    buf = DecodeBuffer(text.encode('utf8'), len(text))
    chars, size = buf.get_chars(-1)
    assert chars.decode('utf8') == text
    assert len(text) == size
    assert buf.exhausted()
Exemplo n.º 7
0
def test_next_char(text):
    buf = DecodeBuffer(text.encode('utf-8'))
    for i in range(len(text)):
        ch = buf.next_char()
        assert ch == text[i].encode('utf-8')
    assert buf.exhausted()
Exemplo n.º 8
0
def test_read_buffer(text):
    buf = DecodeBuffer(text.encode('utf-8'))
    assert buf.get_chars(-1) == text.encode('utf-8')
    assert buf.exhausted()