Commit 9e2dab50 authored by Kirill Smelkov's avatar Kirill Smelkov

golang_str: tests: Adjust test_strings_index2 not to depend on repr(ustr|bstr)

repr(ustr|bstr) will change behaviour depending on whether we are
running under regular python, or gpython with string types replaced by
bstr/ustr. But this test is completely orthogonal to that. -> Let's
untie it from particular repr behaviour by emitting verified items in
quoted form + asserting their types in the code.
parent 8dc44e12
#!/usr/bin/env python #!/usr/bin/env python
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2022 Nexedi SA and Contributors. # Copyright (C) 2022-2023 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -29,7 +29,8 @@ from builtin str/unicode, does not get into our way. ...@@ -29,7 +29,8 @@ from builtin str/unicode, does not get into our way.
from __future__ import print_function, absolute_import from __future__ import print_function, absolute_import
from golang import b, u from golang import b, u, bstr, ustr
from golang.gcompat import qq
def main(): def main():
...@@ -37,8 +38,10 @@ def main(): ...@@ -37,8 +38,10 @@ def main():
bs = b("миру мир") bs = b("миру мир")
def emit(what, uobj, bobj): def emit(what, uobj, bobj):
print("u"+what, repr(uobj)) assert type(uobj) is ustr
print("b"+what, repr(bobj)) assert type(bobj) is bstr
print("u"+what, qq(uobj))
print("b"+what, qq(bobj))
emit("s", us, bs) emit("s", us, bs)
emit("s[:]", us[:], bs[:]) emit("s[:]", us[:], bs[:])
......
us u('миру мир') us "миру мир"
bs b('миру мир') bs "миру мир"
us[:] u('миру мир') us[:] "миру мир"
bs[:] b('миру мир') bs[:] "миру мир"
us[0:1] u('м') us[0:1] "м"
bs[0:1] b(b'\xd0') bs[0:1] "\xd0"
us[0:2] u('ми') us[0:2] "ми"
bs[0:2] b('м') bs[0:2] "м"
us[1:2] u('и') us[1:2] "и"
bs[1:2] b(b'\xbc') bs[1:2] "\xbc"
us[0:-1] u('миру ми') us[0:-1] "миру ми"
bs[0:-1] b(b'миру ми\xd1') bs[0:-1] "миру ми\xd1"
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