pointer_size.pass.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // append(const charT* s, size_type n);
  12. #include <string>
  13. #include <stdexcept>
  14. #include <cassert>
  15. template <class S>
  16. void
  17. test(S s, const typename S::value_type* str, typename S::size_type n, S expected)
  18. {
  19. s.append(str, n);
  20. assert(s.__invariants());
  21. assert(s == expected);
  22. }
  23. int main()
  24. {
  25. typedef std::string S;
  26. test(S(), "", 0, S());
  27. test(S(), "12345", 3, S("123"));
  28. test(S(), "12345", 4, S("1234"));
  29. test(S(), "12345678901234567890", 0, S());
  30. test(S(), "12345678901234567890", 1, S("1"));
  31. test(S(), "12345678901234567890", 3, S("123"));
  32. test(S(), "12345678901234567890", 20, S("12345678901234567890"));
  33. test(S("12345"), "", 0, S("12345"));
  34. test(S("12345"), "12345", 5, S("1234512345"));
  35. test(S("12345"), "1234567890", 10, S("123451234567890"));
  36. test(S("12345678901234567890"), "", 0, S("12345678901234567890"));
  37. test(S("12345678901234567890"), "12345", 5, S("1234567890123456789012345"));
  38. test(S("12345678901234567890"), "12345678901234567890", 20,
  39. S("1234567890123456789012345678901234567890"));
  40. }