string_view.pass.cpp 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <string>
  10. // basic_string<charT,traits,Allocator>&
  11. // append(basic_string_view<charT,traits> sv);
  12. #include <string>
  13. #include <string_view>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "min_allocator.h"
  17. template <class S, class SV>
  18. void
  19. test(S s, SV sv, S expected)
  20. {
  21. s.append(sv);
  22. LIBCPP_ASSERT(s.__invariants());
  23. assert(s == expected);
  24. }
  25. int main()
  26. {
  27. {
  28. typedef std::string S;
  29. typedef std::string_view SV;
  30. test(S(), SV(), S());
  31. test(S(), SV("12345"), S("12345"));
  32. test(S(), SV("1234567890"), S("1234567890"));
  33. test(S(), SV("12345678901234567890"), S("12345678901234567890"));
  34. test(S("12345"), SV(), S("12345"));
  35. test(S("12345"), SV("12345"), S("1234512345"));
  36. test(S("12345"), SV("1234567890"), S("123451234567890"));
  37. test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
  38. test(S("1234567890"), SV(), S("1234567890"));
  39. test(S("1234567890"), SV("12345"), S("123456789012345"));
  40. test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
  41. test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
  42. test(S("12345678901234567890"), SV(), S("12345678901234567890"));
  43. test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
  44. test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
  45. test(S("12345678901234567890"), SV("12345678901234567890"),
  46. S("1234567890123456789012345678901234567890"));
  47. }
  48. #if TEST_STD_VER >= 11
  49. {
  50. typedef std::basic_string <char, std::char_traits<char>, min_allocator<char>> S;
  51. typedef std::basic_string_view<char, std::char_traits<char> > SV;
  52. test(S(), SV(), S());
  53. test(S(), SV("12345"), S("12345"));
  54. test(S(), SV("1234567890"), S("1234567890"));
  55. test(S(), SV("12345678901234567890"), S("12345678901234567890"));
  56. test(S("12345"), SV(), S("12345"));
  57. test(S("12345"), SV("12345"), S("1234512345"));
  58. test(S("12345"), SV("1234567890"), S("123451234567890"));
  59. test(S("12345"), SV("12345678901234567890"), S("1234512345678901234567890"));
  60. test(S("1234567890"), SV(), S("1234567890"));
  61. test(S("1234567890"), SV("12345"), S("123456789012345"));
  62. test(S("1234567890"), SV("1234567890"), S("12345678901234567890"));
  63. test(S("1234567890"), SV("12345678901234567890"), S("123456789012345678901234567890"));
  64. test(S("12345678901234567890"), SV(), S("12345678901234567890"));
  65. test(S("12345678901234567890"), SV("12345"), S("1234567890123456789012345"));
  66. test(S("12345678901234567890"), SV("1234567890"), S("123456789012345678901234567890"));
  67. test(S("12345678901234567890"), SV("12345678901234567890"),
  68. S("1234567890123456789012345678901234567890"));
  69. }
  70. #endif
  71. }