// Formatting library for C++ - core tests // // Copyright (c) 2012 - present, Victor Zverovich // All rights reserved. // // For the license information refer to format.h. // Turn assertion failures into exceptions for testing. // clang-format off #include "test-assert.h" // clang-format on #include "fmt/base.h" #include // INT_MAX #include // strlen #include // std::equal_to #include // std::back_insert_iterator, std::distance #include // std::numeric_limits #include // std::string #include // std::is_same #include "gmock/gmock.h" #ifdef FMT_FORMAT_H_ # error base-test includes format.h #endif using testing::_; using testing::Invoke; using testing::Return; auto copy(fmt::string_view s, fmt::appender out) -> fmt::appender { for (char c : s) *out++ = c; return out; } TEST(string_view_test, value_type) { static_assert(std::is_same::value, ""); } TEST(string_view_test, ctor) { EXPECT_STREQ(fmt::string_view("abc").data(), "abc"); EXPECT_EQ(fmt::string_view("abc").size(), 3u); EXPECT_STREQ(fmt::string_view(std::string("defg")).data(), "defg"); EXPECT_EQ(fmt::string_view(std::string("defg")).size(), 4u); } TEST(string_view_test, length) { // Test that string_view::size() returns string length, not buffer size. char str[100] = "some string"; EXPECT_EQ(fmt::string_view(str).size(), strlen(str)); EXPECT_LT(strlen(str), sizeof(str)); } // Check string_view's comparison operator. template