-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[string] Improve basic_inplace_string tests
- Loading branch information
1 parent
ed48889
commit 64954e5
Showing
4 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// SPDX-License-Identifier: BSL-1.0 | ||
|
||
#include <etl/string.hpp> | ||
|
||
#include "testing/testing.hpp" | ||
|
||
namespace { | ||
|
||
template <typename Char, typename String> | ||
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<Char>); | ||
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<Char*>); | ||
CHECK_SAME_TYPE(typename String::const_reverse_iterator, etl::reverse_iterator<Char const*>); | ||
|
||
// 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 <typename Char> | ||
constexpr auto test_char_type() -> bool | ||
{ | ||
CHECK(test<Char, etl::basic_inplace_string<Char, 3>>()); | ||
CHECK(test<Char, etl::basic_inplace_string<Char, 5>>()); | ||
CHECK(test<Char, etl::basic_inplace_string<Char, 7>>()); | ||
CHECK(test<Char, etl::basic_inplace_string<Char, 8>>()); | ||
CHECK(test<Char, etl::basic_inplace_string<Char, 15>>()); | ||
CHECK(test<Char, etl::basic_inplace_string<Char, 16>>()); | ||
CHECK(test<Char, etl::basic_inplace_string<Char, 31>>()); | ||
return true; | ||
} | ||
|
||
constexpr auto test_all() -> bool | ||
{ | ||
CHECK(test_char_type<char>()); | ||
CHECK(test_char_type<wchar_t>()); | ||
CHECK(test_char_type<char8_t>()); | ||
CHECK(test_char_type<char16_t>()); | ||
CHECK(test_char_type<char32_t>()); | ||
return true; | ||
} | ||
|
||
} // namespace | ||
|
||
auto main() -> int | ||
{ | ||
STATIC_CHECK(test_all()); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: BSL-1.0 | ||
|
||
#include <etl/string.hpp> | ||
|
||
#include "testing/testing.hpp" | ||
|
||
template <typename String> | ||
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<etl::inplace_u16string<16>>()); | ||
CHECK(test<etl::inplace_u16string<17>>()); | ||
CHECK(test<etl::inplace_u16string<18>>()); | ||
CHECK(test<etl::inplace_u16string<24>>()); | ||
CHECK(test<etl::inplace_u16string<32>>()); | ||
return true; | ||
} | ||
|
||
auto main() -> int | ||
{ | ||
STATIC_CHECK(test_all()); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: BSL-1.0 | ||
|
||
#include <etl/string.hpp> | ||
|
||
#include "testing/testing.hpp" | ||
|
||
template <typename String> | ||
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<etl::inplace_u32string<16>>()); | ||
CHECK(test<etl::inplace_u32string<17>>()); | ||
CHECK(test<etl::inplace_u32string<18>>()); | ||
CHECK(test<etl::inplace_u32string<24>>()); | ||
CHECK(test<etl::inplace_u32string<32>>()); | ||
return true; | ||
} | ||
|
||
auto main() -> int | ||
{ | ||
STATIC_CHECK(test_all()); | ||
return 0; | ||
} |