copy_assignment.pass.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. // operator=(const basic_string<charT,traits,Allocator>& str);
  12. #include <string>
  13. #include <cassert>
  14. #include "test_macros.h"
  15. #include "min_allocator.h"
  16. template <class S>
  17. void
  18. test(S s1, const S& s2)
  19. {
  20. s1 = s2;
  21. LIBCPP_ASSERT(s1.__invariants());
  22. assert(s1 == s2);
  23. assert(s1.capacity() >= s1.size());
  24. }
  25. int main()
  26. {
  27. {
  28. typedef std::string S;
  29. test(S(), S());
  30. test(S("1"), S());
  31. test(S(), S("1"));
  32. test(S("1"), S("2"));
  33. test(S("1"), S("2"));
  34. test(S(),
  35. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  36. test(S("123456789"),
  37. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  38. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
  39. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  40. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
  41. "1234567890123456789012345678901234567890123456789012345678901234567890"),
  42. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  43. }
  44. #if TEST_STD_VER >= 11
  45. {
  46. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  47. test(S(), S());
  48. test(S("1"), S());
  49. test(S(), S("1"));
  50. test(S("1"), S("2"));
  51. test(S("1"), S("2"));
  52. test(S(),
  53. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  54. test(S("123456789"),
  55. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  56. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"),
  57. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  58. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"
  59. "1234567890123456789012345678901234567890123456789012345678901234567890"),
  60. S("abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz"));
  61. }
  62. #endif
  63. }