import sys
import unicode_strings
if sys.version_info[0:2] >= (3, 1):
test_string = "h\udce9llo w\u00f6rld"
if unicode_strings.non_utf8_c_str() != test_string:
raise ValueError("Test comparison mismatch")
if unicode_strings.non_utf8_std_string() != test_string:
raise ValueError("Test comparison mismatch")
def check(s1, s2):
if s1 != s2:
raise RuntimeError("{} != {}".format(s1, s2))
if sys.version_info[0:2] < (3, 0):
check(unicode_strings.charstring("hello1"), "hello1")
check(unicode_strings.charstring(str(unicode("hello2"))), "hello2")
check(unicode_strings.charstring(unicode("hello3")), "hello3")
check(unicode_strings.charstring(str("hello4")), "hello4")
unicode_strings.charstring(unicode("hell" + unichr(0xb0) + "5"))
unicode_strings.charstring(unicode("hell" + unichr(0x00f6) +"6"))
low_surrogate_string = unichr(0xdcff)
unicode_strings.instring(low_surrogate_string)
else:
low_surrogate_string = "\udcff"
try:
unicode_strings.instring(low_surrogate_string)
raise RuntimeError("Exception should have been thrown")
except TypeError as e:
pass