rv_string.pass.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. // assign(basic_string<charT,traits>&& str);
  12. #include <string>
  13. #include <utility>
  14. #include <cassert>
  15. #include "test_macros.h"
  16. #include "min_allocator.h"
  17. template <class S>
  18. void
  19. test(S s, S str, S expected)
  20. {
  21. s.assign(std::move(str));
  22. LIBCPP_ASSERT(s.__invariants());
  23. assert(s == expected);
  24. }
  25. int main()
  26. {
  27. {
  28. typedef std::string S;
  29. test(S(), S(), S());
  30. test(S(), S("12345"), S("12345"));
  31. test(S(), S("1234567890"), S("1234567890"));
  32. test(S(), S("12345678901234567890"), S("12345678901234567890"));
  33. test(S("12345"), S(), S());
  34. test(S("12345"), S("12345"), S("12345"));
  35. test(S("12345"), S("1234567890"), S("1234567890"));
  36. test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
  37. test(S("1234567890"), S(), S());
  38. test(S("1234567890"), S("12345"), S("12345"));
  39. test(S("1234567890"), S("1234567890"), S("1234567890"));
  40. test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
  41. test(S("12345678901234567890"), S(), S());
  42. test(S("12345678901234567890"), S("12345"), S("12345"));
  43. test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
  44. test(S("12345678901234567890"), S("12345678901234567890"),
  45. S("12345678901234567890"));
  46. }
  47. #if TEST_STD_VER >= 11
  48. {
  49. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  50. test(S(), S(), S());
  51. test(S(), S("12345"), S("12345"));
  52. test(S(), S("1234567890"), S("1234567890"));
  53. test(S(), S("12345678901234567890"), S("12345678901234567890"));
  54. test(S("12345"), S(), S());
  55. test(S("12345"), S("12345"), S("12345"));
  56. test(S("12345"), S("1234567890"), S("1234567890"));
  57. test(S("12345"), S("12345678901234567890"), S("12345678901234567890"));
  58. test(S("1234567890"), S(), S());
  59. test(S("1234567890"), S("12345"), S("12345"));
  60. test(S("1234567890"), S("1234567890"), S("1234567890"));
  61. test(S("1234567890"), S("12345678901234567890"), S("12345678901234567890"));
  62. test(S("12345678901234567890"), S(), S());
  63. test(S("12345678901234567890"), S("12345"), S("12345"));
  64. test(S("12345678901234567890"), S("1234567890"), S("1234567890"));
  65. test(S("12345678901234567890"), S("12345678901234567890"),
  66. S("12345678901234567890"));
  67. }
  68. #endif
  69. }