text
stringlengths
0
2.2M
CHECK(text.is_truncated());
#endif
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_replace_first_last_n_c)
{
// Non-overflow short text.
Compare_Text compare_text(short_text.c_str());
TextBuffer buffer;
Text text(short_text.c_str(), buffer.data(), buffer.size());
compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 7, STR('A'));
compare_text.resize(std::min(compare_text.size(), SIZE));
text.replace(text.begin() + 2, text.begin() + 4, 7, STR('A'));
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(!text.is_truncated());
#endif
// Overflow short text.
compare_text.assign(short_text.c_str());
text.assign(short_text.c_str());
compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A'));
compare_text.resize(std::min(compare_text.size(), SIZE));
text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A'));
is_equal = Equal(compare_text, text);
CHECK(is_equal);
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(text.is_truncated());
#endif
// Non-overflow.
compare_text.assign(initial_text.c_str());
text.assign(initial_text.c_str());
compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 9, 7, STR('A'));
compare_text.resize(std::min(compare_text.size(), SIZE));
text.replace(text.begin() + 2, text.begin() + 9, 7, STR('A'));
is_equal = Equal(compare_text, text);
CHECK(is_equal);
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(!text.is_truncated());
#endif
// Overflow.
compare_text.assign(initial_text.c_str());
text.assign(initial_text.c_str());
compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, 15, STR('A'));
compare_text.resize(std::min(compare_text.size(), SIZE));
text.replace(text.begin() + 2, text.begin() + 4, 15, STR('A'));
is_equal = Equal(compare_text, text);
CHECK(is_equal);
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(text.is_truncated());
#endif
}
//*************************************************************************
TEST_FIXTURE(SetupFixture, test_replace_first_last_first_last)
{
// Non-overflow short text.
Compare_Text compare_text(short_text.c_str());
TextBuffer buffer;
Text text(short_text.c_str(), buffer.data(), buffer.size());
Compare_Text replace(STR("Replace"));
Compare_Text replace_long(STR("Replace with some text"));
compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace.begin() + 1, replace.begin() + 5);
compare_text.resize(std::min(compare_text.size(), SIZE));
text.replace(text.begin() + 2, text.begin() + 4, replace.begin() + 1, replace.begin() + 5);
bool is_equal = Equal(compare_text, text);
CHECK(is_equal);
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(!text.is_truncated());
#endif
// Overflow short text.
compare_text.assign(short_text.c_str());
text.assign(short_text.c_str());
compare_text.replace(compare_text.begin() + 2, compare_text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15);
compare_text.resize(std::min(compare_text.size(), SIZE));
text.replace(text.begin() + 2, text.begin() + 4, replace_long.begin() + 1, replace_long.begin() + 15);
is_equal = Equal(compare_text, text);
CHECK(is_equal);
#if ETL_STRING_TRUNCATION_CHECKS_ENABLED
CHECK(text.is_truncated());