diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-27 20:31:48 +0100 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-27 20:31:48 +0100 |
| commit | 4f7ae11655807acf68f49637cc9dd01a03af36d5 (patch) | |
| tree | a5956248759fc4c735f2ba38157cbc2117e790b2 /libs | |
| parent | c3893d6f31b79719035f383ab489c2d18f01b3a3 (diff) | |
| download | teachos-4f7ae11655807acf68f49637cc9dd01a03af36d5.tar.xz teachos-4f7ae11655807acf68f49637cc9dd01a03af36d5.zip | |
add some more tests
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/kstd/tests/src/string.cpp | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/libs/kstd/tests/src/string.cpp b/libs/kstd/tests/src/string.cpp index f7f629d..43e9a6b 100644 --- a/libs/kstd/tests/src/string.cpp +++ b/libs/kstd/tests/src/string.cpp @@ -387,4 +387,59 @@ SCENARIO("String iteration", "[string]") } } } + + GIVEN("A const string") + { + auto const str = kstd::string{"Blub"}; + + WHEN("iterating over the characters of the string as string_view using a range-based for loop") + { + kstd::string result; + + for (auto ch : str.view()) + { + result.push_back(ch); + } + + THEN("the iterated characters are the same as the characters in the string") + { + REQUIRE(result == str.view()); + } + } + + WHEN("using front and back to access the first and last characters of the string") + { + THEN("front returns the first character of the string") + { + REQUIRE(str.front() == 'B'); + } + + THEN("back returns the last character of the string") + { + REQUIRE(str.back() == 'b'); + } + } + } + + GIVEN("An empty string") + { + auto str = kstd::string{}; + + WHEN("iterating over the characters of an empty string") + { + kstd::string result; + + for (auto ch : str.view()) + { + result.push_back(ch); + } + + THEN("no characters are iterated and the result is an empty string") + { + REQUIRE(result.empty()); + REQUIRE(result.size() == 0); + REQUIRE(result.view() == std::string_view{}); + } + } + } } |
