rv_string.pass.cpp 2.6 KB

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