aboutsummaryrefslogtreecommitdiff
path: root/libs/kstd/kstd/string.test.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/kstd/kstd/string.test.cpp')
-rw-r--r--libs/kstd/kstd/string.test.cpp169
1 files changed, 169 insertions, 0 deletions
diff --git a/libs/kstd/kstd/string.test.cpp b/libs/kstd/kstd/string.test.cpp
index 27ca95b3..e11877e5 100644
--- a/libs/kstd/kstd/string.test.cpp
+++ b/libs/kstd/kstd/string.test.cpp
@@ -1954,6 +1954,112 @@ SCENARIO("String modifiers", "[string]")
REQUIRE(s.data() != old_data);
}
}
+
+ WHEN("resizing to a greater size within the capacity")
+ {
+ s.resize(10);
+
+ THEN("the capacity stays the same")
+ {
+ REQUIRE(s.capacity() == old_capacity);
+ }
+
+ THEN("the size increases")
+ {
+ CHECK(s.size() > old_size);
+ REQUIRE(s.size() == 10);
+ }
+
+ THEN("the string get filled with null characters")
+ {
+ REQUIRE(kstd::string::traits_type::compare(s.data(), "abcd\0\0\0\0\0\0", s.size() + 1) == 0);
+ }
+ }
+
+ WHEN("resizing to a greater size with a given character within the capacity")
+ {
+ s.resize(10, 'x');
+
+ THEN("the capacity stays the same")
+ {
+ REQUIRE(s.capacity() == old_capacity);
+ }
+
+ THEN("the size increases")
+ {
+ CHECK(s.size() > old_size);
+ REQUIRE(s.size() == 10);
+ }
+
+ THEN("the string get filled with the given character")
+ {
+ REQUIRE(kstd::string::traits_type::compare(s.data(), "abcdxxxxxx", s.size() + 1) == 0);
+ }
+ }
+
+ WHEN("resizing to a greater size outside the capacity")
+ {
+ s.resize(20);
+
+ THEN("the capacity increases")
+ {
+ REQUIRE(s.capacity() > old_capacity);
+ }
+
+ THEN("the size increases")
+ {
+ CHECK(s.size() > old_size);
+ REQUIRE(s.size() == 20);
+ }
+
+ THEN("the string get filled with null characters")
+ {
+ REQUIRE(kstd::string::traits_type::compare(s.data(), "abcd\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", s.size() + 1) ==
+ 0);
+ }
+ }
+
+ WHEN("resizing to a greater size with a given character within the capacity")
+ {
+ s.resize(20, 'x');
+
+ THEN("the capacity increases")
+ {
+ REQUIRE(s.capacity() > old_capacity);
+ }
+
+ THEN("the size increases")
+ {
+ CHECK(s.size() > old_size);
+ REQUIRE(s.size() == 20);
+ }
+
+ THEN("the string get filled with the given character")
+ {
+ REQUIRE(kstd::string::traits_type::compare(s.data(), "abcdxxxxxxxxxxxxxxxx", s.size() + 1) == 0);
+ }
+ }
+
+ WHEN("resizing to a lesser size")
+ {
+ s.resize(2);
+
+ THEN("the capacity stays the same")
+ {
+ REQUIRE(s.capacity() == old_capacity);
+ }
+
+ THEN("the size decreases")
+ {
+ CHECK(s.size() < old_size);
+ REQUIRE(s.size() == 2);
+ }
+
+ THEN("the string get filled with the given character")
+ {
+ REQUIRE(kstd::string::traits_type::compare(s.data(), "ab\0", s.size() + 1) == 0);
+ }
+ }
}
GIVEN("A long string")
@@ -2037,6 +2143,69 @@ SCENARIO("String modifiers", "[string]")
REQUIRE(s.data() != old_data);
}
}
+
+ WHEN("resizing to a greater size")
+ {
+ s.resize(22); // NOLINT
+
+ THEN("the capacity increases")
+ {
+ REQUIRE(s.capacity() > old_capacity);
+ }
+
+ THEN("the size increases")
+ {
+ CHECK(s.size() > old_size);
+ REQUIRE(s.size() == 22);
+ }
+
+ THEN("the string get filled with null characters")
+ {
+ REQUIRE(kstd::string::traits_type::compare(s.data(), "abcdefghijABCDEFGHIJ\0\0", s.size() + 1) == 0);
+ }
+ }
+
+ WHEN("resizing to a greater size with a given character within the capacity")
+ {
+ s.resize(22, 'x'); // NOLINT
+
+ THEN("the capacity increases")
+ {
+ REQUIRE(s.capacity() > old_capacity);
+ }
+
+ THEN("the size increases")
+ {
+ CHECK(s.size() > old_size);
+ REQUIRE(s.size() == 22);
+ }
+
+ THEN("the string get filled with the given character")
+ {
+ REQUIRE(kstd::string::traits_type::compare(s.data(), "abcdefghijABCDEFGHIJxx", s.size() + 1) == 0);
+ }
+ }
+
+ WHEN("resizing to a lesser size")
+ {
+ s.resize(2);
+
+ THEN("the capacity stays the same")
+ {
+ REQUIRE(s.capacity() == old_capacity);
+ }
+
+ THEN("the size decreases")
+ {
+ CHECK(s.size() < old_size);
+ REQUIRE(s.size() == 2);
+ }
+
+ THEN("the string get filled with the given character")
+ {
+ REQUIRE(kstd::string::traits_type::compare(s.data(), "ab\0", s.size() + 1) == 0);
+ }
+ }
}
GIVEN("Two strings")