From cd5e646b74d376df8429e93cdee3cf0c12cd5dbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Thu, 6 Jun 2024 21:35:38 -0700 Subject: [PATCH] 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. --- test/ctl/string_test.cc | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/test/ctl/string_test.cc b/test/ctl/string_test.cc index be664b22b..360a1b968 100644 --- a/test/ctl/string_test.cc +++ b/test/ctl/string_test.cc @@ -353,19 +353,29 @@ main() return 78; } - if constexpr (!std::is_same_v) { - // 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) { + // 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; } }