append test is better

This modifies the new test we introduced to also run on std::string, but
it just does the append without expecting anything about how its data is
stored. We also check that the string has the right value afterwards.
This commit is contained in:
Jōshin 2024-06-06 21:35:38 -07:00
parent 13fe4849e9
commit cd5e646b74
No known key found for this signature in database

View file

@ -353,19 +353,29 @@ main()
return 78;
}
if constexpr (!std::is_same_v<ctl::string, std::string>) {
// tests the small-string optimization on ctl::string
{
ctl::string s;
char *d = s.data();
for (int i = 0; i < 23; ++i) {
if constexpr (!std::is_same_v<ctl::string, std::string>) {
// tests the small-string optimization on ctl::string
char *d = s.data();
for (int i = 0; i < 23; ++i) {
s.append('a');
if (s.data() != d) {
return 79 + i;
}
}
s.append('a');
if (s.data() != d) {
return 79 + i;
if (s.data() == d) {
return 103;
}
} else {
// just check that append in a loop works
for (int i = 0; i < 24; ++i) {
s.append('a');
}
}
s.append('a');
if (s.data() == d) {
return 103;
if (s != "aaaaaaaaaaaaaaaaaaaaaaaa") {
return 104;
}
}