diff options
Diffstat (limited to 'absl/strings/string_view_test.cc')
-rw-r--r-- | absl/strings/string_view_test.cc | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/absl/strings/string_view_test.cc b/absl/strings/string_view_test.cc index ed34ed83..22d43536 100644 --- a/absl/strings/string_view_test.cc +++ b/absl/strings/string_view_test.cc @@ -4,7 +4,7 @@ // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // -// http://www.apache.org/licenses/LICENSE-2.0 +// https://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, @@ -284,9 +284,10 @@ TEST(StringViewTest, ComparisonOperatorsByCharacterPosition) { } #undef COMPARE -// Sadly, our users often confuse string::npos with absl::string_view::npos; -// So much so that we test here that they are the same. They need to -// both be unsigned, and both be the maximum-valued integer of their type. +// Sadly, our users often confuse std::string::npos with +// absl::string_view::npos; So much so that we test here that they are the same. +// They need to both be unsigned, and both be the maximum-valued integer of +// their type. template <typename T> struct is_type { @@ -368,6 +369,11 @@ TEST(StringViewTest, STL1) { EXPECT_EQ(buf[1], c[1]); EXPECT_EQ(buf[2], c[2]); EXPECT_EQ(buf[3], a[3]); +#ifdef ABSL_HAVE_EXCEPTIONS + EXPECT_THROW(a.copy(buf, 1, 27), std::out_of_range); +#else + EXPECT_DEATH(a.copy(buf, 1, 27), "absl::string_view::copy"); +#endif } // Separated from STL1() because some compilers produce an overly @@ -755,7 +761,6 @@ TEST(StringViewTest, Remove) { std::string s1("123"); s1 += '\0'; s1 += "456"; - absl::string_view b(s1); absl::string_view e; std::string s2; @@ -941,6 +946,11 @@ TEST(StringViewTest, ConstexprCompiles) { #error GCC/clang should have constexpr string_view. #endif +// MSVC 2017+ should be able to construct a constexpr string_view from a cstr. +#if defined(_MSC_VER) && _MSC_VER >= 1910 +#define ABSL_HAVE_CONSTEXPR_STRING_VIEW_FROM_CSTR 1 +#endif + #endif // ABSL_HAVE_STD_STRING_VIEW #ifdef ABSL_HAVE_CONSTEXPR_STRING_VIEW_FROM_CSTR @@ -995,8 +1005,8 @@ TEST(StringViewTest, ConstexprCompiles) { TEST(StringViewTest, Noexcept) { EXPECT_TRUE((std::is_nothrow_constructible<absl::string_view, const std::string&>::value)); - EXPECT_TRUE( - (std::is_nothrow_constructible<absl::string_view, const std::string&>::value)); + EXPECT_TRUE((std::is_nothrow_constructible<absl::string_view, + const std::string&>::value)); EXPECT_TRUE(std::is_nothrow_constructible<absl::string_view>::value); constexpr absl::string_view sp; EXPECT_TRUE(noexcept(sp.begin())); |