char.pass.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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+=(charT c);
  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, 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(), 'a', S("a"));
  28. test(S("12345"), 'a', S("12345a"));
  29. test(S("1234567890"), 'a', S("1234567890a"));
  30. test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
  31. }
  32. #if TEST_STD_VER >= 11
  33. {
  34. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  35. test(S(), 'a', S("a"));
  36. test(S("12345"), 'a', S("12345a"));
  37. test(S("1234567890"), 'a', S("1234567890a"));
  38. test(S("12345678901234567890"), 'a', S("12345678901234567890a"));
  39. }
  40. #endif
  41. }