diff --git a/test/StdContainers.cpp b/test/StdContainers.cpp index a10e7dd..4f90510 100644 --- a/test/StdContainers.cpp +++ b/test/StdContainers.cpp @@ -8,26 +8,36 @@ #include #include -SCENARIO("std containers") +#ifdef __has_include +# if __has_include() +# include +# endif +#endif + +#ifdef __cpp_lib_span +# include +#endif + +SCENARIO("std containers") { - GIVEN("logger is initialised") + GIVEN("logger is initialised") { plog::TestAppender testAppender; plog::Logger logger(plog::verbose); logger.addAppender(&testAppender); - WHEN("empty collection") + WHEN("empty collection") { std::vector vectorOfInts; PLOGI << vectorOfInts; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[]")); } } - WHEN("std::vector") + WHEN("std::vector") { std::vector vectorOfInts; vectorOfInts.push_back(1); @@ -35,13 +45,13 @@ SCENARIO("std containers") vectorOfInts.push_back(3); PLOGI << vectorOfInts; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[1, 2, 3]")); } } - WHEN("std::deque") + WHEN("std::deque") { std::deque dequeOfStrings; dequeOfStrings.push_back("one"); @@ -49,13 +59,13 @@ SCENARIO("std containers") dequeOfStrings.push_back("three"); PLOGI << dequeOfStrings; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[one, two, three]")); } } - WHEN("std::list") + WHEN("std::list") { std::list listOfCharPointers; listOfCharPointers.push_back("one"); @@ -63,13 +73,13 @@ SCENARIO("std containers") listOfCharPointers.push_back(NULL); PLOGI << listOfCharPointers; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[one, two, (null)]")); } } - WHEN("std::set") + WHEN("std::set") { std::set setOfInts; setOfInts.insert(10); @@ -77,13 +87,13 @@ SCENARIO("std containers") setOfInts.insert(30); PLOGI << setOfInts; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[10, 20, 30]")); } } - WHEN("std::map") + WHEN("std::map") { std::map mapStringToInt; mapStringToInt["red"] = 1; @@ -91,13 +101,13 @@ SCENARIO("std containers") mapStringToInt["blue"] = 4; PLOGI << mapStringToInt; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[blue:4, green:2, red:1]")); } } - WHEN("std::multimap") + WHEN("std::multimap") { std::multimap multimapIntToString; multimapIntToString.insert(std::make_pair(1, "one")); @@ -106,13 +116,13 @@ SCENARIO("std containers") multimapIntToString.insert(std::make_pair(2, "due")); PLOGI << multimapIntToString; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[1:one, 1:uno, 2:two, 2:due]")); } } - WHEN("std::vector of std::vector") + WHEN("std::vector of std::vector") { std::vector > vectorOfVectorsOfInts(3); vectorOfVectorsOfInts[0].push_back(1); @@ -121,21 +131,37 @@ SCENARIO("std containers") vectorOfVectorsOfInts[1].push_back(-2); PLOGI << vectorOfVectorsOfInts; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[[1, 2], [-1, -2], []]")); } } - WHEN("std::pair") + WHEN("std::pair") { std::pair pairOfInts(5, 10); PLOGI << pairOfInts; - THEN("the result is as expected") + THEN("the result is as expected") { CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("5:10")); } } + +#if 0 // std::span is not supported yet as it has no const_iterator till c++23 +#ifdef __cpp_lib_span + WHEN("std::span") + { + int arr[] = {1, 2, 3}; + std::span spanOfInts(std::begin(arr), std::end(arr)); + PLOGI << spanOfInts; + + THEN("the result is as expected") + { + CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("[1, 2, 3]")); + } + } +#endif +#endif } -} \ No newline at end of file +} diff --git a/test/StringTypes.cpp b/test/StringTypes.cpp index ada7da2..0df228a 100644 --- a/test/StringTypes.cpp +++ b/test/StringTypes.cpp @@ -2,8 +2,14 @@ #include #include "TestAppender.h" +#ifdef __has_include +# if __has_include() +# include +# endif +#endif + #ifdef __cpp_lib_string_view -#include +# include #endif SCENARIO("string types")