diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-06-15 10:42:44 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-06-15 10:42:44 +0200 |
| commit | fb0a56d575e8a28822c9bf9e426601acf09384ac (patch) | |
| tree | 7295c53b1f11cf82b1b4f5b2553748f98719d9b2 /libs | |
| parent | 073efba1940d6f8d8c3f8e4675c56a3b6c5cb75b (diff) | |
| download | kernel-fmorgner/develop/kstd-string-rewrite.tar.xz kernel-fmorgner/develop/kstd-string-rewrite.zip | |
kstd: add more long string testsfmorgner/develop/kstd-string-rewrite
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/kstd/string.test.cpp | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/libs/kstd/kstd/string.test.cpp b/libs/kstd/kstd/string.test.cpp index e5925aa..19345e0 100644 --- a/libs/kstd/kstd/string.test.cpp +++ b/libs/kstd/kstd/string.test.cpp @@ -1954,6 +1954,89 @@ SCENARIO("String modifiers", "[string]") } } + GIVEN("A long string") + { + auto s = kstd::string{"abcdefghijABCDEFGHIJ"}; + auto old_capacity = s.capacity(); + auto old_size = s.size(); + auto old_data = s.data(); + + WHEN("reserving a smaller capacity") + { + s.reserve(1); + + THEN("the capacity does not change") + { + REQUIRE(s.capacity() == old_capacity); + } + + THEN("the content stays the same") + { + REQUIRE(s == "abcdefghijABCDEFGHIJ"); + } + + THEN("the size stays the same") + { + REQUIRE(s.size() == old_size); + } + + THEN("the data pointer stays the same") + { + REQUIRE(s.data() == old_data); + } + } + + WHEN("reserving equal capacity") + { + s.reserve(old_capacity); + + THEN("the capacity does not change") + { + REQUIRE(s.capacity() == old_capacity); + } + + THEN("the content stays the same") + { + REQUIRE(s == "abcdefghijABCDEFGHIJ"); + } + + THEN("the size stays the same") + { + REQUIRE(s.size() == old_size); + } + + THEN("the data pointer stays the same") + { + REQUIRE(static_cast<void const *>(s.data()) == static_cast<void const *>(old_data)); + } + } + + WHEN("reserving larger capacity") + { + s.reserve(old_capacity + 1); + + THEN("the capacity increases") + { + REQUIRE(s.capacity() >= old_capacity + 1); + } + + THEN("the content stays the same") + { + REQUIRE(s == "abcdefghijABCDEFGHIJ"); + } + + THEN("the size stays the same") + { + REQUIRE(s.size() == old_size); + } + + THEN("the data pointer changes") + { + REQUIRE(s.data() != old_data); + } + } + } + GIVEN("Two strings") { auto str1 = kstd::string{"Blub"}; |
