diff options
| -rw-r--r-- | library/cpp/string_utils/ztstrbuf/ut/ya.make | 5 | ||||
| -rw-r--r-- | library/cpp/string_utils/ztstrbuf/ya.make | 2 | ||||
| -rw-r--r-- | library/cpp/string_utils/ztstrbuf/ztstrbuf.h | 17 | ||||
| -rw-r--r-- | library/cpp/string_utils/ztstrbuf/ztstrbuf_ut.cpp | 28 |
4 files changed, 47 insertions, 5 deletions
diff --git a/library/cpp/string_utils/ztstrbuf/ut/ya.make b/library/cpp/string_utils/ztstrbuf/ut/ya.make new file mode 100644 index 00000000000..57ad2c4ac27 --- /dev/null +++ b/library/cpp/string_utils/ztstrbuf/ut/ya.make @@ -0,0 +1,5 @@ +UNITTEST_FOR(library/cpp/string_utils/ztstrbuf) + +SRCS(ztstrbuf_ut.cpp) + +END() diff --git a/library/cpp/string_utils/ztstrbuf/ya.make b/library/cpp/string_utils/ztstrbuf/ya.make index 9d8d3b7110b..172b74dbba4 100644 --- a/library/cpp/string_utils/ztstrbuf/ya.make +++ b/library/cpp/string_utils/ztstrbuf/ya.make @@ -6,3 +6,5 @@ SRCS( ) END() + +RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/string_utils/ztstrbuf/ztstrbuf.h b/library/cpp/string_utils/ztstrbuf/ztstrbuf.h index 72a5218bf69..fcca39698ba 100644 --- a/library/cpp/string_utils/ztstrbuf/ztstrbuf.h +++ b/library/cpp/string_utils/ztstrbuf/ztstrbuf.h @@ -16,22 +16,29 @@ class TZtStringBuf: public TStringBuf { public: - constexpr TZtStringBuf(const char* s) + constexpr TZtStringBuf(const char* s Y_LIFETIME_BOUND) noexcept : TStringBuf(s) { } - TZtStringBuf(const TString& s) + TZtStringBuf(const TString& s Y_LIFETIME_BOUND) noexcept : TStringBuf(s) { } - TZtStringBuf() - : TZtStringBuf(TString{}) + TZtStringBuf(const std::string& s Y_LIFETIME_BOUND) noexcept + : TStringBuf(s) { } - const char* c_str() const { + constexpr TZtStringBuf() noexcept + : TZtStringBuf("") + { + } + + TZtStringBuf(const TStringBuf&) = delete; + + constexpr const char* c_str() const noexcept { return data(); } }; diff --git a/library/cpp/string_utils/ztstrbuf/ztstrbuf_ut.cpp b/library/cpp/string_utils/ztstrbuf/ztstrbuf_ut.cpp new file mode 100644 index 00000000000..d8215abdfad --- /dev/null +++ b/library/cpp/string_utils/ztstrbuf/ztstrbuf_ut.cpp @@ -0,0 +1,28 @@ +#include "ztstrbuf.h" + +#include <library/cpp/testing/unittest/registar.h> + +Y_UNIT_TEST_SUITE(TZtStringBufTest) { + Y_UNIT_TEST(EmptyString) { + TZtStringBuf s0{}; + UNIT_ASSERT_VALUES_EQUAL(s0, TString{""}); + UNIT_ASSERT_VALUES_EQUAL(s0.c_str(), TString{""}); + } + + Y_UNIT_TEST(Constness) { + constexpr TZtStringBuf s0{"bar"}; + static_assert(s0[0] == 'b'); + static_assert(s0[3] == '\0'); + static_assert(s0.data()[2] == 'r'); + UNIT_ASSERT_VALUES_EQUAL(s0, TString{"bar"}); + } + + Y_UNIT_TEST(FromString) { + TString str0{"foo"}; + TZtStringBuf s0 = str0; + UNIT_ASSERT_VALUES_EQUAL(s0, "foo"); + std::string str1{"bar"}; + TZtStringBuf s1 = str1; + UNIT_ASSERT_VALUES_EQUAL(s1, "bar"); + } +} |
