mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-15 15:00:01 +01:00
Added support for pre-c++17 experimental string_view (#607)
Added support for pre-c++17 experimental string_view
This commit is contained in:
committed by
Victor Zverovich
parent
cabce31f45
commit
5705bf1c71
@@ -11,6 +11,12 @@ target_compile_options(gmock PUBLIC ${CPP11_FLAG})
|
||||
target_compile_definitions(gmock PUBLIC GTEST_HAS_STD_WSTRING=1)
|
||||
target_include_directories(gmock PUBLIC .)
|
||||
|
||||
# Workaround for Cygwin to make google-tests compile and run because the macro
|
||||
# _POSIX_C_SOURCE must be defined to allow fileno(), strdup(), fdopen() calls.
|
||||
if (CYGWIN)
|
||||
target_compile_definitions(gmock PUBLIC _POSIX_C_SOURCE=200809)
|
||||
endif ()
|
||||
|
||||
find_package(Threads)
|
||||
if (Threads_FOUND)
|
||||
target_link_libraries(gmock ${CMAKE_THREAD_LIBS_INIT})
|
||||
|
||||
@@ -156,6 +156,11 @@ TEST(StringRefTest, Ctor) {
|
||||
EXPECT_STREQ("hijk", StringRef(std::string_view("hijk")).data());
|
||||
EXPECT_EQ(4u, StringRef(std::string_view("hijk")).size());
|
||||
#endif
|
||||
|
||||
#if FMT_HAS_EXPERIMENTAL_STRING_VIEW
|
||||
EXPECT_STREQ("hijk", StringRef(std::experimental::string_view("hijk")).data());
|
||||
EXPECT_EQ(4u, StringRef(std::experimental::string_view("hijk")).size());
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(StringRefTest, ConvertToString) {
|
||||
@@ -167,6 +172,12 @@ TEST(StringRefTest, ConvertToString) {
|
||||
std::string_view sv = static_cast<std::string_view>(str_ref);
|
||||
EXPECT_EQ("defg", sv);
|
||||
#endif
|
||||
|
||||
#if FMT_HAS_EXPERIMENTAL_STRING_VIEW
|
||||
StringRef str_ref("defg");
|
||||
std::experimental::string_view sv = static_cast<std::experimental::string_view>(str_ref);
|
||||
EXPECT_EQ("defg", sv);
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(CStringRefTest, Ctor) {
|
||||
@@ -176,6 +187,10 @@ TEST(CStringRefTest, Ctor) {
|
||||
#if FMT_HAS_STRING_VIEW
|
||||
EXPECT_STREQ("hijk", CStringRef(std::string_view("hijk")).c_str());
|
||||
#endif
|
||||
|
||||
#if FMT_HAS_EXPERIMENTAL_STRING_VIEW
|
||||
EXPECT_STREQ("hijk", CStringRef(std::experimental::string_view("hijk")).c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
#if FMT_USE_TYPE_TRAITS
|
||||
@@ -1399,6 +1414,12 @@ TEST(FormatterTest, FormatStringView) {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if FMT_HAS_EXPERIMENTAL_STRING_VIEW
|
||||
TEST(FormatterTest, FormatExperimentalStringView) {
|
||||
EXPECT_EQ("test", format("{0}", std::experimental::string_view("test")));
|
||||
}
|
||||
#endif
|
||||
|
||||
void format_arg(fmt::BasicFormatter<char> &f, const char *, const Date &d) {
|
||||
f.writer() << d.year() << '-' << d.month() << '-' << d.day();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user