string_buffer.cpp 714 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #include<__vic/string_buffer.h>
  2. #include<iostream>
  3. #include<exception>
  4. #include<cassert>
  5. void run_tests()
  6. {
  7. const size_t initial_capacity = 64;
  8. __vic::string_buffer s(initial_capacity);
  9. assert(s.empty());
  10. assert(s.capacity() >= initial_capacity);
  11. s << 1;
  12. assert(s == "1");
  13. s << ' ' << 2.0 << " " << true;
  14. std::string std_str = s;
  15. s = std_str;
  16. const char *c_str = s;
  17. s.clear() << static_cast<const void *>(c_str);
  18. #if __cpp_lib_string_view
  19. s << std::string_view("string_view");
  20. #endif
  21. }
  22. int main()
  23. {
  24. try
  25. {
  26. run_tests();
  27. return 0;
  28. }
  29. catch(const std::exception &ex)
  30. {
  31. std::cerr << ex.what() << '\n';
  32. }
  33. return 1;
  34. }