aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/util_ut.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/string/util_ut.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/string/util_ut.cpp')
-rw-r--r--util/string/util_ut.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/util/string/util_ut.cpp b/util/string/util_ut.cpp
new file mode 100644
index 0000000000..18a2d8e195
--- /dev/null
+++ b/util/string/util_ut.cpp
@@ -0,0 +1,46 @@
+#include "util.h"
+
+#include <library/cpp/testing/unittest/registar.h>
+
+class TStrUtilTest: public TTestBase {
+ UNIT_TEST_SUITE(TStrUtilTest);
+ UNIT_TEST(TestSpn);
+ UNIT_TEST(TestRemoveAll);
+ UNIT_TEST_SUITE_END();
+
+public:
+ void TestSpn() {
+ str_spn rul("a-z", true);
+ char s[] = "!@#$ab%^&c+-";
+ UNIT_ASSERT_EQUAL(rul.brk(s), s + 4);
+ UNIT_ASSERT_EQUAL(rul.brk(s + 4), s + 4);
+ UNIT_ASSERT_EQUAL(rul.brk(s + 10), s + 12);
+ char* s1 = s;
+ UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), "!@#$"), 0);
+ UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), ""), 0);
+ UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), "%^&"), 0);
+ UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), "+-"), 0);
+ UNIT_ASSERT_EQUAL(rul.sep(s1), nullptr);
+ }
+
+ void TestRemoveAll() {
+ static const struct T {
+ const char* Str;
+ char Ch;
+ const char* Result;
+ } tests[] = {
+ {"", 'x', ""},
+ {"hello world", 'h', "ello world"},
+ {"hello world", 'l', "heo word"},
+ {"hello world", 'x', "hello world"},
+ };
+
+ for (const T* t = tests; t != std::end(tests); ++t) {
+ TString str(t->Str);
+ RemoveAll(str, t->Ch);
+ UNIT_ASSERT_EQUAL(t->Result, str);
+ }
+ }
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TStrUtilTest);