string.pass.cpp 2.6 KB

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