diff --git a/CMakeLists.txt b/CMakeLists.txt index c62ff9c..ab80d78 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,6 +59,7 @@ add_executable(cpp_weekly cpp20_features/barrier_test.cc cpp20_features/semaphores_test.cc cpp20_features/placeholder_types.cc + cpp20_features/format_test.cc cpp_challenges/chap1_math_problems.cc diff --git a/cpp20_features/format_test.cc b/cpp20_features/format_test.cc new file mode 100644 index 0000000..25f40ff --- /dev/null +++ b/cpp20_features/format_test.cc @@ -0,0 +1,34 @@ +#include "internal_check_conds.h" + +#include +#include +#include + +namespace { + +void basic_example() { + std::string str{"hello"}; + + std::cout << std::format("String '{}' has {} chars\n", str, str.size()) ; + std::cout << std::format("String '{1}' has {0} chars\n", str, str.size()) ; +} + +} + +TEST(format_test, basic_test) { + std::stringstream oss; + + testing::internal::CaptureStdout(); + basic_example(); + + auto act_output = testing::internal::GetCapturedStdout(); + + oss << "String 'hello' has 5 chars\n" + "String '5' has hello chars\n"; + +#ifndef NDEBUG + debug_msg(oss, act_output); +#endif + + EXPECT_EQ(oss.str(), act_output); +} \ No newline at end of file