Utils: Fix small string

Change-Id: I6a746eb28c6c803b9ade9f626a950cf93ba6fe99
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Marco Bubke
2018-08-30 17:37:12 +02:00
parent 4c88c1808c
commit 3d9974db95
2 changed files with 25 additions and 1 deletions

View File

@@ -615,7 +615,13 @@ public:
friend BasicSmallString operator+(SmallStringView first, const BasicSmallString &second)
{
return operator+(second, first);
BasicSmallString text;
text.reserve(first.size() + second.size());
text.append(first);
text.append(second);
return text;
}
template<size_type ArraySize>

View File

@@ -1657,6 +1657,15 @@ TEST(SmallString, StringViewPlusOperator)
ASSERT_THAT(result, "text and more text");
}
TEST(SmallString, StringViewPlusOperatorReverseOrder)
{
SmallStringView text = " and more text";
auto result = "text" + text;
ASSERT_THAT(result, "text and more text");
}
TEST(SmallString, StringPlusOperator)
{
SmallString text = "text";
@@ -1666,6 +1675,15 @@ TEST(SmallString, StringPlusOperator)
ASSERT_THAT(result, "text and more text");
}
TEST(SmallString, StringPlusOperatorReverseOrder)
{
SmallString text = " and more text";
auto result = "text" + text;
ASSERT_THAT(result, "text and more text");
}
TEST(SmallString, ShortStringCapacity)
{
ASSERT_THAT(SmallString().shortStringCapacity(), 30);