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