Commit 105d03d4 authored by Kirill Smelkov's avatar Kirill Smelkov

golang_str: Add test for memoryview(bstr)

Verify that it works as expected, and that memoryview(ustr) is rejected,
because ustr is semantically array of unicode characters, not bytes.

No change to the code - just add tests for current status which is
already working as expected.
parent d7e55bb0
...@@ -248,6 +248,29 @@ def test_strings_basic(): ...@@ -248,6 +248,29 @@ def test_strings_basic():
bs.hello = 1 bs.hello = 1
# verify memoryview(bstr|ustr).
def test_strings_memoryview():
bs = b('мир')
us = u('май')
with raises(TypeError):
memoryview(us)
m = memoryview(bs)
assert len(m) == 6
def _(i): # returns m[i] as int
x = m[i]
if six.PY2: # on py2 memoryview[i] returns bytechar
x = ord(x)
return x
assert _(0) == 0xd0
assert _(1) == 0xbc
assert _(2) == 0xd0
assert _(3) == 0xb8
assert _(4) == 0xd1
assert _(5) == 0x80
# verify string operations like `x + y` for all combinations of pairs from # verify string operations like `x + y` for all combinations of pairs from
# bytes, unicode, bstr, ustr and bytearray. Except if both x and y are std # bytes, unicode, bstr, ustr and bytearray. Except if both x and y are std
# python types, e.g. (bytes, unicode), because those combinations are handled # python types, e.g. (bytes, unicode), because those combinations are handled
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment