forked from qt-creator/qt-creator
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:
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user