Fix operator+, add tests

This commit is contained in:
Krystian Stasiowski
2020-02-21 12:44:25 -05:00
parent 14ec006701
commit 7cf8c0aee8
2 changed files with 61 additions and 5 deletions

View File

@ -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();
}