diff options
| author | Felix Morgner <felix.morgner@ost.ch> | 2026-05-02 17:12:21 +0200 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@ost.ch> | 2026-05-02 17:12:21 +0200 |
| commit | 3ab0a15fb6aba0ad9516da69589b9da8dbd63a8e (patch) | |
| tree | e79c1c0911c3b712a1b02c79d84f0ce5f643bc6c /libs/kstd/tests/src/format.cpp | |
| parent | e8904a65e49dea8ce2e1d58eaa3fb60c7cd3443e (diff) | |
| download | kernel-3ab0a15fb6aba0ad9516da69589b9da8dbd63a8e.tar.xz kernel-3ab0a15fb6aba0ad9516da69589b9da8dbd63a8e.zip | |
libs: adopt p1204 layout for kstd
Diffstat (limited to 'libs/kstd/tests/src/format.cpp')
| -rw-r--r-- | libs/kstd/tests/src/format.cpp | 114 |
1 files changed, 0 insertions, 114 deletions
diff --git a/libs/kstd/tests/src/format.cpp b/libs/kstd/tests/src/format.cpp deleted file mode 100644 index 624779a..0000000 --- a/libs/kstd/tests/src/format.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include <kstd/format> - -#include <catch2/catch_test_macros.hpp> - -#include <iterator> -#include <sstream> - -SCENARIO("Formatting to a new string", "[format]") -{ - GIVEN("a format string without any placeholders") - { - auto const & fmt = "This is a test"; - - WHEN("calling format with without any arguments.") - { - auto result = kstd::format(fmt); - - THEN("the result is the unmodified string") - { - REQUIRE(result == "This is a test"); - } - } - - WHEN("calling format with additional arguments") - { - auto result = kstd::format(fmt, 1, 2, 3); - - THEN("the result is the unmodified string") - { - REQUIRE(result == "This is a test"); - } - } - } - - GIVEN("a format string with placeholders") - { - auto const & fmt = "Here are some placeholders: {} {} {}"; - - WHEN("calling format with the same number of arguments as there are placeholders") - { - auto result = kstd::format(fmt, 1, true, 'a'); - - THEN("the result is the formatted string") - { - REQUIRE(result == "Here are some placeholders: 1 true a"); - } - } - - WHEN("calling format with too many arguments") - { - auto result = kstd::format(fmt, 2, false, 'b', 4, 5, 6); - - THEN("the result is the formatted string") - { - REQUIRE(result == "Here are some placeholders: 2 false b"); - } - } - } -} - -SCENARIO("Formatting to an output iterator", "[format]") -{ - auto buffer = std::ostringstream{}; - - GIVEN("a format string without any placeholders") - { - auto const & fmt = "This is a test"; - - WHEN("calling format with without any arguments.") - { - kstd::format_to(std::ostream_iterator<char>{buffer}, fmt); - - THEN("the unmodified string is written to the iterator") - { - REQUIRE(buffer.str() == "This is a test"); - } - } - - WHEN("calling format with additional arguments") - { - kstd::format_to(std::ostream_iterator<char>{buffer}, fmt, 1, 2, 3); - - THEN("the unmodified string is written to the iterator") - { - REQUIRE(buffer.str() == "This is a test"); - } - } - } - - GIVEN("a format string with placeholders") - { - auto const & fmt = "Here are some placeholders: {} {} {}"; - - WHEN("calling format with the same number of arguments as there are placeholders") - { - kstd::format_to(std::ostream_iterator<char>{buffer}, fmt, 1, true, -100); - - THEN("the formatted string is written to the iterator") - { - REQUIRE(buffer.str() == "Here are some placeholders: 1 true -100"); - } - } - - WHEN("calling format with too many arguments") - { - kstd::format_to(std::ostream_iterator<char>{buffer}, fmt, 2, false, -200, 4, 5, 6); - - THEN("the formatted string is written to the iterator") - { - REQUIRE(buffer.str() == "Here are some placeholders: 2 false -200"); - } - } - } -}
\ No newline at end of file |
