Skip to content

Commit

Permalink
Add std::string_view to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SergiusTheBest committed Oct 5, 2023
1 parent 0d9baad commit f45f5ca
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
cmake_minimum_required(VERSION 3.0)
if(${CMAKE_VERSION} VERSION_LESS 3.27.0)
cmake_minimum_required(VERSION 3.0)
else()
cmake_minimum_required(VERSION 3.6)
endif()

project(PlogTest CXX)

Expand Down
52 changes: 52 additions & 0 deletions test/StringTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
#include <plog/Log.h>
#include "TestAppender.h"

#ifdef __cpp_lib_string_view
#include <string_view>
#endif

SCENARIO("string types")
{
GIVEN("logger is initialised")
Expand Down Expand Up @@ -76,6 +80,30 @@ SCENARIO("string types")
}
}

#ifdef __cpp_lib_string_view
WHEN("type is std::string_view")
{
std::string_view var = "test";
PLOGI << var;

THEN("the result is as expected")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("test"));
}
}

WHEN("type is const std::string_view")
{
const std::string_view var = "test";
PLOGI << var;

THEN("the result is as expected")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("test"));
}
}
#endif

#if PLOG_ENABLE_WCHAR_INPUT
WHEN("type is wchar_t*")
{
Expand Down Expand Up @@ -142,6 +170,30 @@ SCENARIO("string types")
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("test"));
}
}

# ifdef __cpp_lib_string_view
WHEN("type is std::wstring_view")
{
std::wstring_view var = L"test";
PLOGI << var;

THEN("the result is as expected")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("test"));
}
}

WHEN("type is const std::wstring_view")
{
const std::wstring_view var = L"test";
PLOGI << var;

THEN("the result is as expected")
{
CHECK_EQ(testAppender.getMessage(), PLOG_NSTR("test"));
}
}
# endif
#endif

#ifdef __cplusplus_cli
Expand Down

0 comments on commit f45f5ca

Please sign in to comment.