size_char.pass.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <string>
  10. // basic_string<charT,traits,Allocator>&
  11. // assign(size_type n, charT c);
  12. #include <string>
  13. #include <cassert>
  14. template <class S>
  15. void
  16. test(S s, typename S::size_type n, typename S::value_type c, S expected)
  17. {
  18. s.assign(n, c);
  19. assert(s.__invariants());
  20. assert(s == expected);
  21. }
  22. int main()
  23. {
  24. typedef std::string S;
  25. test(S(), 0, 'a', S());
  26. test(S(), 1, 'a', S(1, 'a'));
  27. test(S(), 10, 'a', S(10, 'a'));
  28. test(S(), 100, 'a', S(100, 'a'));
  29. test(S("12345"), 0, 'a', S());
  30. test(S("12345"), 1, 'a', S(1, 'a'));
  31. test(S("12345"), 10, 'a', S(10, 'a'));
  32. test(S("12345678901234567890"), 0, 'a', S());
  33. test(S("12345678901234567890"), 1, 'a', S(1, 'a'));
  34. test(S("12345678901234567890"), 10, 'a', S(10, 'a'));
  35. }