From 64954e539c46d18bd8ed03b08ad7728e4434b44a Mon Sep 17 00:00:00 2001 From: Tobias Hienzsch Date: Wed, 17 Apr 2024 18:38:37 +0200 Subject: [PATCH] [string] Improve basic_inplace_string tests --- tests/string/CMakeLists.txt | 3 + tests/string/basic_inplace_string.t.cpp | 93 +++++++++++++++++++++++++ tests/string/inplace_u16string.t.cpp | 47 +++++++++++++ tests/string/inplace_u32string.t.cpp | 47 +++++++++++++ 4 files changed, 190 insertions(+) create mode 100644 tests/string/basic_inplace_string.t.cpp create mode 100644 tests/string/inplace_u16string.t.cpp create mode 100644 tests/string/inplace_u32string.t.cpp diff --git a/tests/string/CMakeLists.txt b/tests/string/CMakeLists.txt index 5ebf17da8..b66f1f3f5 100644 --- a/tests/string/CMakeLists.txt +++ b/tests/string/CMakeLists.txt @@ -1,5 +1,6 @@ project("string") +tetl_add_test(${PROJECT_NAME} basic_inplace_string) tetl_add_test(${PROJECT_NAME} char_traits) tetl_add_test(${PROJECT_NAME} inplace_string.access) tetl_add_test(${PROJECT_NAME} inplace_string.algorithm) @@ -7,6 +8,8 @@ tetl_add_test(${PROJECT_NAME} inplace_string.compare) tetl_add_test(${PROJECT_NAME} inplace_string.construct) tetl_add_test(${PROJECT_NAME} inplace_string.modify) tetl_add_test(${PROJECT_NAME} inplace_u8string) +tetl_add_test(${PROJECT_NAME} inplace_u16string) +tetl_add_test(${PROJECT_NAME} inplace_u32string) tetl_add_test(${PROJECT_NAME} inplace_wstring) tetl_add_test(${PROJECT_NAME} stod) tetl_add_test(${PROJECT_NAME} stoi) diff --git a/tests/string/basic_inplace_string.t.cpp b/tests/string/basic_inplace_string.t.cpp new file mode 100644 index 000000000..9297d4893 --- /dev/null +++ b/tests/string/basic_inplace_string.t.cpp @@ -0,0 +1,93 @@ +// SPDX-License-Identifier: BSL-1.0 + +#include + +#include "testing/testing.hpp" + +namespace { + +template +constexpr auto test() -> bool +{ + CHECK_SAME_TYPE(typename String::value_type, Char); + CHECK_SAME_TYPE(typename String::size_type, etl::size_t); + CHECK_SAME_TYPE(typename String::difference_type, etl::ptrdiff_t); + CHECK_SAME_TYPE(typename String::traits_type, etl::char_traits); + CHECK_SAME_TYPE(typename String::pointer, Char*); + CHECK_SAME_TYPE(typename String::const_pointer, Char const*); + CHECK_SAME_TYPE(typename String::reference, Char&); + CHECK_SAME_TYPE(typename String::const_reference, Char const&); + CHECK_SAME_TYPE(typename String::iterator, Char*); + CHECK_SAME_TYPE(typename String::const_iterator, Char const*); + CHECK_SAME_TYPE(typename String::reverse_iterator, etl::reverse_iterator); + CHECK_SAME_TYPE(typename String::const_reverse_iterator, etl::reverse_iterator); + + // construct(default) + { + auto const str = String(); + CHECK(str.empty()); + CHECK(str.size() == 0); // NOLINT + CHECK(str.begin() == str.end()); + CHECK(str == str); + CHECK_FALSE(str != str); + } + + // construct(size, char) + { + auto const str = String(2, Char('A')); + CHECK_FALSE(str.empty()); + CHECK(str.size() == 2); + CHECK(str.begin() != str.end()); + + CHECK_FALSE(str == String()); + CHECK_FALSE(String() == str); + + CHECK(str != String()); + CHECK(String() != str); + + CHECK_FALSE(str < String()); + CHECK(String() < str); + + CHECK_FALSE(str <= String()); + CHECK(String() <= str); + + CHECK(str > String()); + CHECK_FALSE(String() > str); + + CHECK(str >= String()); + CHECK_FALSE(String() >= str); + } + + return true; +} + +template +constexpr auto test_char_type() -> bool +{ + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + return true; +} + +constexpr auto test_all() -> bool +{ + CHECK(test_char_type()); + CHECK(test_char_type()); + CHECK(test_char_type()); + CHECK(test_char_type()); + CHECK(test_char_type()); + return true; +} + +} // namespace + +auto main() -> int +{ + STATIC_CHECK(test_all()); + return 0; +} diff --git a/tests/string/inplace_u16string.t.cpp b/tests/string/inplace_u16string.t.cpp new file mode 100644 index 000000000..6e78bca29 --- /dev/null +++ b/tests/string/inplace_u16string.t.cpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: BSL-1.0 + +#include + +#include "testing/testing.hpp" + +template +constexpr auto test() -> bool +{ + auto str = String(); + CHECK(str == u""); + CHECK(str.empty()); + CHECK(str.size() == 0); // NOLINT + CHECK(size(str) == 0); // NOLINT + + str = str + u"tes"; + CHECK(str == u"tes"); + + str = str + char16_t('t'); + CHECK(str == u"test"); + + str = str + String{u"_foo"}; + CHECK(str == u"test_foo"); + + str = u"__" + str; + CHECK(str == u"__test_foo"); + + str = char16_t('a') + str; + CHECK(str == u"a__test_foo"); + return true; +} + +constexpr auto test_all() -> bool +{ + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + return true; +} + +auto main() -> int +{ + STATIC_CHECK(test_all()); + return 0; +} diff --git a/tests/string/inplace_u32string.t.cpp b/tests/string/inplace_u32string.t.cpp new file mode 100644 index 000000000..c169699e5 --- /dev/null +++ b/tests/string/inplace_u32string.t.cpp @@ -0,0 +1,47 @@ +// SPDX-License-Identifier: BSL-1.0 + +#include + +#include "testing/testing.hpp" + +template +constexpr auto test() -> bool +{ + auto str = String(); + CHECK(str == U""); + CHECK(str.empty()); + CHECK(str.size() == 0); // NOLINT + CHECK(size(str) == 0); // NOLINT + + str = str + U"tes"; + CHECK(str == U"tes"); + + str = str + char32_t('t'); + CHECK(str == U"test"); + + str = str + String{U"_foo"}; + CHECK(str == U"test_foo"); + + str = U"__" + str; + CHECK(str == U"__test_foo"); + + str = char32_t('a') + str; + CHECK(str == U"a__test_foo"); + return true; +} + +constexpr auto test_all() -> bool +{ + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + CHECK(test>()); + return true; +} + +auto main() -> int +{ + STATIC_CHECK(test_all()); + return 0; +}