string_ref.cpp 964 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #define __VIC_DEFINE_OSTREAM_INSERTERS 1
  2. #include<__vic/string_ref.h>
  3. #include<iostream>
  4. #include<exception>
  5. #include<cassert>
  6. namespace tests {
  7. void print(__vic::string_ref s)
  8. {
  9. std::cout << s << '\n';
  10. }
  11. void run()
  12. {
  13. print("String literal");
  14. print(std::string("std::string"));
  15. const char str[] = "str";
  16. __vic::string_ref sr = str;
  17. assert(sr == str);
  18. assert(!(sr != str));
  19. assert(sr > "abc");
  20. assert(sr > "st");
  21. assert(sr < "z");
  22. assert(sr >= str);
  23. assert(sr >= "abc");
  24. // Check assignment
  25. sr = str;
  26. assert(sr == str);
  27. std::string std_str(str);
  28. sr = std_str;
  29. assert(sr == std_str);
  30. #if __cpp_lib_string_view
  31. sr = std::string_view();
  32. std::string_view sv = sr;
  33. (void) sv;
  34. #endif
  35. }
  36. } // namespace
  37. int main()
  38. {
  39. try
  40. {
  41. tests::run();
  42. return 0;
  43. }
  44. catch(const std::exception &ex)
  45. {
  46. std::cerr << ex.what() << '\n';
  47. }
  48. return 1;
  49. }