diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/stream/str_ut.pyx | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/stream/str_ut.pyx')
-rw-r--r-- | util/stream/str_ut.pyx | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/util/stream/str_ut.pyx b/util/stream/str_ut.pyx new file mode 100644 index 0000000000..2ae617303f --- /dev/null +++ b/util/stream/str_ut.pyx @@ -0,0 +1,62 @@ +# cython: c_string_type=str, c_string_encoding=utf8 + +from cython.operator cimport dereference + +from util.generic.ptr cimport THolder +from util.generic.string cimport TString, TStringBuf +from util.stream.str cimport TStringOutput, TStringOutputPtr + +import unittest + + +class TestStringOutput(unittest.TestCase): + def test_ctor1(self): + cdef TStringOutput output + + def test_ctor2(self): + cdef TString string + cdef THolder[TStringOutput] string_output = THolder[TStringOutput](new TStringOutput(string)) + + def test_write_char(self): + cdef TString string + cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string)) + + self.assertEqual(string, "") + dereference(string_output.Get()).WriteChar('1') + self.assertEqual(string, "1") + dereference(string_output.Get()).WriteChar('2') + self.assertEqual(string, "12") + dereference(string_output.Get()).WriteChar('3') + self.assertEqual(string, "123") + + def test_write_void(self): + cdef TString string + cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string)) + + self.assertEqual(string, "") + dereference(string_output.Get()).Write("1", 1) + self.assertEqual(string, "1") + dereference(string_output.Get()).Write("2", 1) + self.assertEqual(string, "12") + dereference(string_output.Get()).Write("34", 2) + self.assertEqual(string, "1234") + + def test_write_buf(self): + cdef TString string + cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string)) + + self.assertEqual(string, "") + dereference(string_output.Get()).WriteBuf(TStringBuf("1")) + self.assertEqual(string, "1") + dereference(string_output.Get()).WriteBuf(TStringBuf("2")) + self.assertEqual(string, "12") + dereference(string_output.Get()).WriteBuf(TStringBuf("34")) + self.assertEqual(string, "1234") + + def test_reserve(self): + cdef TString string + cdef TStringOutputPtr string_output = TStringOutputPtr(new TStringOutput(string)) + self.assertEqual(string, "") + dereference(string_output.Get()).Reserve(50) + self.assertEqual(string, "") + self.assertLessEqual(50, string.capacity()) |