char_assignment.pass.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // <string>
  9. // basic_string<charT,traits,Allocator>& operator=(charT c);
  10. #include <string>
  11. #include <cassert>
  12. #include "test_macros.h"
  13. #include "min_allocator.h"
  14. template <class S>
  15. void
  16. test(S s1, typename S::value_type s2)
  17. {
  18. typedef typename S::traits_type T;
  19. s1 = s2;
  20. LIBCPP_ASSERT(s1.__invariants());
  21. assert(s1.size() == 1);
  22. assert(T::eq(s1[0], s2));
  23. assert(s1.capacity() >= s1.size());
  24. }
  25. int main(int, char**)
  26. {
  27. {
  28. typedef std::string S;
  29. test(S(), 'a');
  30. test(S("1"), 'a');
  31. test(S("123456789"), 'a');
  32. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
  33. }
  34. #if TEST_STD_VER >= 11
  35. {
  36. typedef std::basic_string<char, std::char_traits<char>, min_allocator<char>> S;
  37. test(S(), 'a');
  38. test(S("1"), 'a');
  39. test(S("123456789"), 'a');
  40. test(S("1234567890123456789012345678901234567890123456789012345678901234567890"), 'a');
  41. }
  42. #endif
  43. return 0;
  44. }