blob: 557591c7d71e275b577c5e86316d10c916f1a080 [file] [log] [blame]
William A. Kennington III48a470a2022-12-10 17:09:59 -08001#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
9using namespace std::string_view_literals;
10using namespace std::string_literals;
11
12namespace stdplus
13{
14
15TEST(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
25TEST(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
35TEST(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