ends_with.string_view.pass.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
  9. // <string_view>
  10. // constexpr bool ends_with(string_view x) const noexcept;
  11. #include <string_view>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. #include "constexpr_char_traits.h"
  15. int main(int, char**)
  16. {
  17. {
  18. typedef std::string_view SV;
  19. const char *s = "abcde";
  20. SV sv0;
  21. SV sv1 { s + 4, 1 };
  22. SV sv2 { s + 3, 2 };
  23. SV sv3 { s + 2, 3 };
  24. SV sv4 { s + 1, 4 };
  25. SV sv5 { s , 5 };
  26. SV svNot {"def", 3 };
  27. ASSERT_NOEXCEPT(sv0.ends_with(sv0));
  28. assert ( sv0.ends_with(sv0));
  29. assert (!sv0.ends_with(sv1));
  30. assert ( sv1.ends_with(sv0));
  31. assert ( sv1.ends_with(sv1));
  32. assert (!sv1.ends_with(sv2));
  33. assert (!sv1.ends_with(sv3));
  34. assert (!sv1.ends_with(sv4));
  35. assert (!sv1.ends_with(sv5));
  36. assert (!sv1.ends_with(svNot));
  37. assert ( sv2.ends_with(sv0));
  38. assert ( sv2.ends_with(sv1));
  39. assert ( sv2.ends_with(sv2));
  40. assert (!sv2.ends_with(sv3));
  41. assert (!sv2.ends_with(sv4));
  42. assert (!sv2.ends_with(sv5));
  43. assert (!sv2.ends_with(svNot));
  44. assert ( svNot.ends_with(sv0));
  45. assert (!svNot.ends_with(sv1));
  46. assert (!svNot.ends_with(sv2));
  47. assert (!svNot.ends_with(sv3));
  48. assert (!svNot.ends_with(sv4));
  49. assert (!svNot.ends_with(sv5));
  50. assert ( svNot.ends_with(svNot));
  51. }
  52. #if TEST_STD_VER > 11
  53. {
  54. typedef std::basic_string_view<char, constexpr_char_traits<char>> SV;
  55. constexpr const char *s = "abcde";
  56. constexpr SV sv0 {};
  57. constexpr SV sv1 { s + 4, 1 };
  58. constexpr SV sv2 { s + 3, 2 };
  59. constexpr SV sv3 { s + 2, 3 };
  60. constexpr SV sv4 { s + 1, 4 };
  61. constexpr SV sv5 { s, 5 };
  62. constexpr SV svNot {"def", 3 };
  63. static_assert ( sv0.ends_with(sv0), "" );
  64. static_assert (!sv0.ends_with(sv1), "" );
  65. static_assert ( sv1.ends_with(sv0), "" );
  66. static_assert ( sv1.ends_with(sv1), "" );
  67. static_assert (!sv1.ends_with(sv2), "" );
  68. static_assert (!sv1.ends_with(sv3), "" );
  69. static_assert (!sv1.ends_with(sv4), "" );
  70. static_assert (!sv1.ends_with(sv5), "" );
  71. static_assert (!sv1.ends_with(svNot), "" );
  72. static_assert ( sv2.ends_with(sv0), "" );
  73. static_assert ( sv2.ends_with(sv1), "" );
  74. static_assert ( sv2.ends_with(sv2), "" );
  75. static_assert (!sv2.ends_with(sv3), "" );
  76. static_assert (!sv2.ends_with(sv4), "" );
  77. static_assert (!sv2.ends_with(sv5), "" );
  78. static_assert (!sv2.ends_with(svNot), "" );
  79. static_assert ( svNot.ends_with(sv0), "" );
  80. static_assert (!svNot.ends_with(sv1), "" );
  81. static_assert (!svNot.ends_with(sv2), "" );
  82. static_assert (!svNot.ends_with(sv3), "" );
  83. static_assert (!svNot.ends_with(sv4), "" );
  84. static_assert (!svNot.ends_with(sv5), "" );
  85. static_assert ( svNot.ends_with(svNot), "" );
  86. }
  87. #endif
  88. return 0;
  89. }