aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic/string_ut.pyx
diff options
context:
space:
mode:
authorMikhail Borisov <borisov.mikhail@gmail.com>2022-02-10 16:45:40 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:40 +0300
commit5d50718e66d9c037dc587a0211110b7d25a66185 (patch)
treee98df59de24d2ef7c77baed9f41e4875a2fef972 /util/generic/string_ut.pyx
parenta6a92afe03e02795227d2641b49819b687f088f8 (diff)
downloadydb-5d50718e66d9c037dc587a0211110b7d25a66185.tar.gz
Restoring authorship annotation for Mikhail Borisov <borisov.mikhail@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util/generic/string_ut.pyx')
-rw-r--r--util/generic/string_ut.pyx338
1 files changed, 169 insertions, 169 deletions
diff --git a/util/generic/string_ut.pyx b/util/generic/string_ut.pyx
index 0aafffd1d1..5407f5b4c1 100644
--- a/util/generic/string_ut.pyx
+++ b/util/generic/string_ut.pyx
@@ -1,225 +1,225 @@
# cython: c_string_type=str, c_string_encoding=utf8
-from libcpp.string cimport string as std_string
+from libcpp.string cimport string as std_string
from util.generic.string cimport TString, npos
-
-import pytest
-import unittest
-
+
+import pytest
+import unittest
+
import sys
-
-class TestStroka(unittest.TestCase):
+
+class TestStroka(unittest.TestCase):
def test_unicode(self):
cdef TString x = "привет"
self.assertEquals(x, "привет")
-
- def test_ctor1(self):
+
+ def test_ctor1(self):
cdef TString tmp = TString()
cdef TString tmp2 = TString(tmp)
self.assertEquals(tmp2, "")
-
- def test_ctor2(self):
- cdef std_string tmp = b"hello"
+
+ def test_ctor2(self):
+ cdef std_string tmp = b"hello"
cdef TString tmp2 = TString(tmp)
self.assertEquals(tmp2, "hello")
-
- def test_ctor3(self):
- cdef TString tmp = b"hello"
+
+ def test_ctor3(self):
+ cdef TString tmp = b"hello"
cdef TString tmp2 = TString(tmp, 0, 4)
self.assertEquals(tmp2, "hell")
-
- def test_ctor4(self):
+
+ def test_ctor4(self):
cdef TString tmp = TString(<char*>b"hello")
self.assertEquals(tmp, "hello")
-
- def test_ctor5(self):
+
+ def test_ctor5(self):
cdef TString tmp = TString(<char*>b"hello", 4)
self.assertEquals(tmp, "hell")
-
- def test_ctor6(self):
+
+ def test_ctor6(self):
cdef TString tmp = TString(<char*>b"hello", 1, 3)
self.assertEquals(tmp, "ell")
-
- def test_ctor7(self):
+
+ def test_ctor7(self):
cdef TString tmp = TString(3, <char>'x')
self.assertEquals(tmp, "xxx")
-
- def test_ctor8(self):
- cdef bytes tmp = b"hello"
+
+ def test_ctor8(self):
+ cdef bytes tmp = b"hello"
cdef TString tmp2 = TString(<char*>tmp, <char*>tmp + 4)
self.assertEquals(tmp2, "hell")
-
- def test_compare(self):
- cdef TString tmp1 = b"abacab"
- cdef TString tmp2 = b"abacab"
- cdef TString tmp3 = b"abacac"
-
- self.assertTrue(tmp1.compare(tmp2) == 0)
- self.assertTrue(tmp1.compare(tmp3) < 0)
- self.assertTrue(tmp3.compare(tmp1) > 0)
-
- self.assertTrue(tmp1 == tmp2)
- self.assertTrue(tmp1 != tmp3)
-
- self.assertTrue(tmp1 < tmp3)
- self.assertTrue(tmp1 <= tmp3)
-
- self.assertTrue(tmp3 > tmp1)
- self.assertTrue(tmp3 >= tmp1)
-
- def test_operator_assign(self):
- cdef TString tmp = b"hello"
+
+ def test_compare(self):
+ cdef TString tmp1 = b"abacab"
+ cdef TString tmp2 = b"abacab"
+ cdef TString tmp3 = b"abacac"
+
+ self.assertTrue(tmp1.compare(tmp2) == 0)
+ self.assertTrue(tmp1.compare(tmp3) < 0)
+ self.assertTrue(tmp3.compare(tmp1) > 0)
+
+ self.assertTrue(tmp1 == tmp2)
+ self.assertTrue(tmp1 != tmp3)
+
+ self.assertTrue(tmp1 < tmp3)
+ self.assertTrue(tmp1 <= tmp3)
+
+ self.assertTrue(tmp3 > tmp1)
+ self.assertTrue(tmp3 >= tmp1)
+
+ def test_operator_assign(self):
+ cdef TString tmp = b"hello"
cdef TString tmp2 = tmp
self.assertEquals(tmp2, "hello")
-
- def test_operator_plus(self):
- cdef TString tmp = TString(b"hello ") + TString(b"world")
+
+ def test_operator_plus(self):
+ cdef TString tmp = TString(b"hello ") + TString(b"world")
self.assertEquals(tmp, "hello world")
-
- def test_c_str(self):
- cdef TString tmp = b"hello"
+
+ def test_c_str(self):
+ cdef TString tmp = b"hello"
if sys.version_info.major == 2:
self.assertEquals(bytes(tmp.c_str()), b"hello")
else:
self.assertEquals(bytes(tmp.c_str(), 'utf8'), b"hello")
-
- def test_length(self):
- cdef TString tmp = b"hello"
- self.assertEquals(tmp.size(), tmp.length())
-
- def test_index(self):
- cdef TString tmp = b"hello"
-
- self.assertEquals(<bytes>tmp[0], b'h')
- self.assertEquals(<bytes>tmp.at(0), b'h')
-
- self.assertEquals(<bytes>tmp[4], b'o')
- self.assertEquals(<bytes>tmp.at(4), b'o')
-
+
+ def test_length(self):
+ cdef TString tmp = b"hello"
+ self.assertEquals(tmp.size(), tmp.length())
+
+ def test_index(self):
+ cdef TString tmp = b"hello"
+
+ self.assertEquals(<bytes>tmp[0], b'h')
+ self.assertEquals(<bytes>tmp.at(0), b'h')
+
+ self.assertEquals(<bytes>tmp[4], b'o')
+ self.assertEquals(<bytes>tmp.at(4), b'o')
+
# Actually, TString::at() is noexcept
- # with pytest.raises(IndexError):
- # tmp.at(100)
-
- def test_append(self):
+ # with pytest.raises(IndexError):
+ # tmp.at(100)
+
+ def test_append(self):
cdef TString tmp
- cdef TString tmp2 = b"fuu"
-
- tmp.append(tmp2)
+ cdef TString tmp2 = b"fuu"
+
+ tmp.append(tmp2)
self.assertEquals(tmp, "fuu")
-
- tmp.append(tmp2, 1, 2)
+
+ tmp.append(tmp2, 1, 2)
self.assertEquals(tmp, "fuuuu")
-
- tmp.append(<char*>"ll ")
+
+ tmp.append(<char*>"ll ")
self.assertEquals(tmp, "fuuuull ")
-
- tmp.append(<char*>"of greatness", 4)
+
+ tmp.append(<char*>"of greatness", 4)
self.assertEquals(tmp, "fuuuull of g")
-
- tmp.append(2, <char>b'o')
+
+ tmp.append(2, <char>b'o')
self.assertEquals(tmp, "fuuuull of goo")
-
- tmp.push_back(b'z')
+
+ tmp.push_back(b'z')
self.assertEquals(tmp, "fuuuull of gooz")
-
- def test_assign(self):
+
+ def test_assign(self):
cdef TString tmp
-
- tmp.assign(b"one")
+
+ tmp.assign(b"one")
self.assertEquals(tmp, "one")
-
- tmp.assign(b"two hundred", 0, 3)
+
+ tmp.assign(b"two hundred", 0, 3)
self.assertEquals(tmp, "two")
-
- tmp.assign(<char*>b"three")
+
+ tmp.assign(<char*>b"three")
self.assertEquals(tmp, "three")
-
- tmp.assign(<char*>b"three fiddy", 5)
+
+ tmp.assign(<char*>b"three fiddy", 5)
self.assertEquals(tmp, "three")
-
- def test_insert(self):
+
+ def test_insert(self):
cdef TString tmp
-
- tmp = b"xx"
- tmp.insert(1, b"foo")
+
+ tmp = b"xx"
+ tmp.insert(1, b"foo")
self.assertEquals(tmp, "xfoox")
-
- tmp = b"xx"
- tmp.insert(1, b"haxor", 1, 3)
+
+ tmp = b"xx"
+ tmp.insert(1, b"haxor", 1, 3)
self.assertEquals(tmp, "xaxox")
-
- tmp = b"xx"
- tmp.insert(1, <char*>b"foo")
+
+ tmp = b"xx"
+ tmp.insert(1, <char*>b"foo")
self.assertEquals(tmp, "xfoox")
-
- tmp = b"xx"
- tmp.insert(1, <char*>b"foozzy", 3)
+
+ tmp = b"xx"
+ tmp.insert(1, <char*>b"foozzy", 3)
self.assertEquals(tmp, "xfoox")
-
- tmp = b"xx"
- tmp.insert(1, 2, <char>b'u')
+
+ tmp = b"xx"
+ tmp.insert(1, 2, <char>b'u')
self.assertEquals(tmp, "xuux")
-
- def test_copy(self):
- cdef char buf[16]
- cdef TString tmp = b"hello"
- tmp.copy(buf, 5, 0)
+
+ def test_copy(self):
+ cdef char buf[16]
+ cdef TString tmp = b"hello"
+ tmp.copy(buf, 5, 0)
self.assertEquals(buf[:5], "hello")
-
- def test_find(self):
- cdef TString haystack = b"whole lotta bytes"
+
+ def test_find(self):
+ cdef TString haystack = b"whole lotta bytes"
cdef TString needle = "hole"
-
- self.assertEquals(haystack.find(needle), 1)
- self.assertEquals(haystack.find(needle, 3), npos)
-
- self.assertEquals(haystack.find(<char>b'h'), 1)
- self.assertEquals(haystack.find(<char>b'h', 3), npos)
-
- def test_rfind(self):
- cdef TString haystack = b"whole lotta bytes"
- cdef TString needle = b"hole"
-
- self.assertEquals(haystack.rfind(needle), 1)
- self.assertEquals(haystack.rfind(needle, 0), npos)
-
- self.assertEquals(haystack.rfind(<char>b'h'), 1)
- self.assertEquals(haystack.rfind(<char>b'h', 0), npos)
-
- def test_find_first_of(self):
- cdef TString haystack = b"whole lotta bytes"
- cdef TString cset = b"hxz"
-
- self.assertEquals(haystack.find_first_of(<char>b'h'), 1)
- self.assertEquals(haystack.find_first_of(<char>b'h', 3), npos)
-
- self.assertEquals(haystack.find_first_of(cset), 1)
- self.assertEquals(haystack.find_first_of(cset, 3), npos)
-
- def test_first_not_of(self):
- cdef TString haystack = b"whole lotta bytes"
- cdef TString cset = b"wxz"
-
- self.assertEquals(haystack.find_first_not_of(<char>b'w'), 1)
- self.assertEquals(haystack.find_first_not_of(<char>b'w', 3), 3)
-
- self.assertEquals(haystack.find_first_not_of(cset), 1)
- self.assertEquals(haystack.find_first_not_of(cset, 3), 3)
-
- def test_find_last_of(self):
- cdef TString haystack = b"whole lotta bytes"
- cdef TString cset = b"hxz"
-
- self.assertEquals(haystack.find_last_of(<char>b'h'), 1)
- self.assertEquals(haystack.find_last_of(<char>b'h', 0), npos)
-
- self.assertEquals(haystack.find_last_of(cset), 1)
- self.assertEquals(haystack.find_last_of(cset, 0), npos)
-
- def test_substr(self):
- cdef TString tmp = b"foobar"
-
+
+ self.assertEquals(haystack.find(needle), 1)
+ self.assertEquals(haystack.find(needle, 3), npos)
+
+ self.assertEquals(haystack.find(<char>b'h'), 1)
+ self.assertEquals(haystack.find(<char>b'h', 3), npos)
+
+ def test_rfind(self):
+ cdef TString haystack = b"whole lotta bytes"
+ cdef TString needle = b"hole"
+
+ self.assertEquals(haystack.rfind(needle), 1)
+ self.assertEquals(haystack.rfind(needle, 0), npos)
+
+ self.assertEquals(haystack.rfind(<char>b'h'), 1)
+ self.assertEquals(haystack.rfind(<char>b'h', 0), npos)
+
+ def test_find_first_of(self):
+ cdef TString haystack = b"whole lotta bytes"
+ cdef TString cset = b"hxz"
+
+ self.assertEquals(haystack.find_first_of(<char>b'h'), 1)
+ self.assertEquals(haystack.find_first_of(<char>b'h', 3), npos)
+
+ self.assertEquals(haystack.find_first_of(cset), 1)
+ self.assertEquals(haystack.find_first_of(cset, 3), npos)
+
+ def test_first_not_of(self):
+ cdef TString haystack = b"whole lotta bytes"
+ cdef TString cset = b"wxz"
+
+ self.assertEquals(haystack.find_first_not_of(<char>b'w'), 1)
+ self.assertEquals(haystack.find_first_not_of(<char>b'w', 3), 3)
+
+ self.assertEquals(haystack.find_first_not_of(cset), 1)
+ self.assertEquals(haystack.find_first_not_of(cset, 3), 3)
+
+ def test_find_last_of(self):
+ cdef TString haystack = b"whole lotta bytes"
+ cdef TString cset = b"hxz"
+
+ self.assertEquals(haystack.find_last_of(<char>b'h'), 1)
+ self.assertEquals(haystack.find_last_of(<char>b'h', 0), npos)
+
+ self.assertEquals(haystack.find_last_of(cset), 1)
+ self.assertEquals(haystack.find_last_of(cset, 0), npos)
+
+ def test_substr(self):
+ cdef TString tmp = b"foobar"
+
self.assertEquals(tmp.substr(1), "oobar")
self.assertEquals(tmp.substr(1, 4), "ooba")