예제 #1
0
def test_pack_into():
    size = ASCII_SIZE + UTF8_SIZE
    buf = bytearray(size)
    offset = 0

    offset = CString.pack_into(buf, offset, "ABC", "ascii")
    offset = CString.pack_into(buf, offset, "日本語")

    assert buf == (ASCII + UTF8)
    assert offset == size
예제 #2
0
def test_pack_into():
    size = ASCII_SIZE + UTF8_SIZE
    buf = bytearray(size)
    offset = 0

    offset = CString.pack_into(buf, offset, "ABC", "ascii")
    offset = CString.pack_into(buf, offset, "日本語")

    assert buf == (ASCII + UTF8)
    assert offset == size
예제 #3
0
def test_unpack_from():
    buf = ASCII + UTF8 + BROKEN_UTF8

    offset = 0

    val, offset = CString.unpack_from(buf, offset)
    assert val == "ABC"

    val, offset = CString.unpack_from(buf, offset)
    assert val == "日本語"

    val, offset = CString.unpack_from(buf, offset)
    assert val == "日本"
예제 #4
0
def test_unpack_from():
    buf = ASCII + UTF8 + BROKEN_UTF8

    offset = 0

    val, offset = CString.unpack_from(buf, offset)
    assert val == "ABC"

    val, offset = CString.unpack_from(buf, offset)
    assert val == "日本語"

    val, offset = CString.unpack_from(buf, offset)
    assert val == "日本"
예제 #5
0
def test_read_broken_utf8(fd):
    assert CString.read(fd) == "日本"
    assert fd.tell() == BROKEN_UTF8_SIZE
예제 #6
0
def test_read_utf8(fd):
    assert CString.read(fd) == "日本語"
    assert fd.tell() == UTF8_SIZE
예제 #7
0
def test_read_ascii(fd):
    assert CString.read(fd, "ascii") == "ABC"
    assert fd.tell() == ASCII_SIZE
예제 #8
0
def test_size_utf8():
    assert CString.size("日本語") == UTF8_SIZE
예제 #9
0
def test_size_ascii():
    assert CString.size("ABC", "ascii") == ASCII_SIZE
예제 #10
0
def test_pack_utf8():
    assert CString("日本語") == UTF8
예제 #11
0
def test_pack_ascii():
    assert CString("ABC", "ascii") == ASCII
예제 #12
0
def test_read_broken_utf8(fd):
    assert CString.read(fd) == "日本"
    assert fd.tell() == BROKEN_UTF8_SIZE
예제 #13
0
def test_read_utf8(fd):
    assert CString.read(fd) == "日本語"
    assert fd.tell() == UTF8_SIZE
예제 #14
0
def test_read_ascii(fd):
    assert CString.read(fd, "ascii") == "ABC"
    assert fd.tell() == ASCII_SIZE
예제 #15
0
def test_size_utf8():
    assert CString.size("日本語") == UTF8_SIZE
예제 #16
0
def test_size_ascii():
    assert CString.size("ABC", "ascii") == ASCII_SIZE