mirror of
https://github.com/boostorg/static_string.git
synced 2025-07-27 19:17:37 +02:00
Fix operator+, add tests
This commit is contained in:
@ -7009,6 +7009,53 @@ testStream()
|
||||
BOOST_TEST(a.str() == b.subview());
|
||||
}
|
||||
|
||||
void
|
||||
testOperatorPlus()
|
||||
{
|
||||
static_string<10> s1 = "hello";
|
||||
static_string<10> s2 = "world";
|
||||
|
||||
// operator+(static_string, static_string)
|
||||
{
|
||||
auto res = s1 + s2;
|
||||
BOOST_TEST(res == "helloworld");
|
||||
BOOST_TEST(res.capacity() == 20);
|
||||
BOOST_TEST(res.size() == 10);
|
||||
}
|
||||
|
||||
// operator+(static_string, CharT)
|
||||
{
|
||||
auto res = s1 + '!';
|
||||
BOOST_TEST(res == "hello!");
|
||||
BOOST_TEST(res.capacity() == 11);
|
||||
BOOST_TEST(res.size() == 6);
|
||||
}
|
||||
|
||||
// operator+(CharT, static_string)
|
||||
{
|
||||
auto res = '!' + s1;
|
||||
BOOST_TEST(res == "!hello");
|
||||
BOOST_TEST(res.capacity() == 11);
|
||||
BOOST_TEST(res.size() == 6);
|
||||
}
|
||||
|
||||
// operator+(static_string, CharT(&)[N])
|
||||
{
|
||||
auto res = s1 + "world";
|
||||
BOOST_TEST(res == "helloworld");
|
||||
BOOST_TEST(res.capacity() == 15);
|
||||
BOOST_TEST(res.size() == 10);
|
||||
}
|
||||
|
||||
// operator+(CharT(&)[N], static_string)
|
||||
{
|
||||
auto res = "hello" + s2;
|
||||
BOOST_TEST(res == "helloworld");
|
||||
BOOST_TEST(res.capacity() == 15);
|
||||
BOOST_TEST(res.size() == 10);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
runTests()
|
||||
{
|
||||
@ -7047,6 +7094,7 @@ runTests()
|
||||
testHash();
|
||||
testEmpty();
|
||||
testStream();
|
||||
testOperatorPlus();
|
||||
|
||||
return report_errors();
|
||||
}
|
||||
|
Reference in New Issue
Block a user