William A. Kennington III | 48a470a | 2022-12-10 17:09:59 -0800 | [diff] [blame] | 1 | #include <stdplus/str/cexpr.hpp> |
| 2 | #include <stdplus/zstring_view.hpp> |
| 3 | |
| 4 | #include <string> |
| 5 | #include <string_view> |
| 6 | |
| 7 | #include <gtest/gtest.h> |
| 8 | |
| 9 | using namespace std::string_view_literals; |
| 10 | using namespace std::string_literals; |
| 11 | |
| 12 | namespace stdplus |
| 13 | { |
| 14 | |
| 15 | TEST(Constexpr, SvFromSv) |
| 16 | { |
| 17 | EXPECT_EQ((std::array{'a', 'b', 'c', '\0'}), |
| 18 | (cexprStrArr<[]() { return "abc"sv; }, true>)); |
| 19 | EXPECT_EQ((std::array{'a', 'b', 'c'}), |
| 20 | (cexprStrArr<[]() { return "abc"sv; }, false>)); |
| 21 | EXPECT_EQ("abc"sv, cexprZsv<[]() { return "abc"sv; }>); |
| 22 | EXPECT_EQ("abc"sv, cexprSv<[]() { return "abc"sv; }>); |
| 23 | } |
| 24 | |
| 25 | TEST(Constexpr, SvFromSmallStr) |
| 26 | { |
| 27 | EXPECT_EQ((std::array{'a', 'b', 'c', '\0'}), |
| 28 | (cexprStrArr<[]() { return "abc"s; }, true>)); |
| 29 | EXPECT_EQ((std::array{'a', 'b', 'c'}), |
| 30 | (cexprStrArr<[]() { return "abc"s; }, false>)); |
| 31 | EXPECT_EQ("abc"sv, cexprSv<[]() { return "abc"s; }>); |
| 32 | EXPECT_EQ("abc"sv, cexprZsv<[]() { return "abc"s; }>); |
| 33 | } |
| 34 | |
| 35 | TEST(Constexpr, SvFromAllocStr) |
| 36 | { |
| 37 | constexpr auto cb = []() { |
| 38 | return "abcdefg"s.append("hijklmnopqrstuvwxyz"sv); |
| 39 | }; |
| 40 | EXPECT_EQ("abcdefghijklmnopqrstuvwxyz"sv, cexprSv<cb>); |
| 41 | EXPECT_EQ("abcdefghijklmnopqrstuvwxyz"sv, cexprZsv<cb>); |
| 42 | } |
| 43 | |
| 44 | } // namespace stdplus |