Utils: Fix replace function in SmallString

You need to allocate the memory before you replace a smaller text with
a larger one. It has some overhead because you go two times over the text
but it is anyway not designed for a large text.

Change-Id: I2f56f1300a5daf9e26632b5b0667023a09ff4bd2
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
Marco Bubke
2017-08-02 18:57:26 +02:00
committed by Tim Jenssen
parent 45dbc743b0
commit 4ae0c6782f
2 changed files with 66 additions and 2 deletions

View File

@@ -753,6 +753,42 @@ TEST(SmallString, Clear)
ASSERT_TRUE(text.isEmpty());
}
TEST(SmallString, NoOccurrencesForEmptyText)
{
SmallString text;
auto occurrences = text.countOccurrence("text");
ASSERT_THAT(occurrences, 0);
}
TEST(SmallString, NoOccurrencesInText)
{
SmallString text("here is some text, here is some text, here is some text");
auto occurrences = text.countOccurrence("texts");
ASSERT_THAT(occurrences, 0);
}
TEST(SmallString, SomeOccurrences)
{
SmallString text("here is some text, here is some text, here is some text");
auto occurrences = text.countOccurrence("text");
ASSERT_THAT(occurrences, 3);
}
TEST(SmallString, SomeMoreOccurrences)
{
SmallString text("texttexttext");
auto occurrences = text.countOccurrence("text");
ASSERT_THAT(occurrences, 3);
}
TEST(SmallString, ReplaceWithCharacter)
{
SmallString text("here is some text, here is some text, here is some text");