string_ref.cpp 856 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. }
  31. } // namespace
  32. int main()
  33. {
  34. try
  35. {
  36. tests::run();
  37. return 0;
  38. }
  39. catch(const std::exception &ex)
  40. {
  41. std::cerr << ex.what() << '\n';
  42. }
  43. return 1;
  44. }