char_assignment.pass.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 s1, typename S::value_type s2)
  18. {
  19. typedef typename S::traits_type T;
  20. s1 = s2;
  21. LIBCPP_ASSERT(s1.__invariants());
  22. assert(s1.size() == 1);
  23. assert(T::eq(s1[0], s2));
  24. assert(s1.capacity() >= s1.size());
  25. }
  26. int main()
  27. {
  28. {
  29. typedef std::string S;
  30. test(S(), 'a');
  31. test(S("1"), 'a');
  32. test(S("123456789"), 'a');
  33. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
  34. }
  35. #if TEST_STD_VER >= 11
  36. {
  37. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  38. test(S(), 'a');
  39. test(S("1"), 'a');
  40. test(S("123456789"), 'a');
  41. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
  42. }
  43. #endif
  44. }