starts_with.cpp 946 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #include<__vic/string_utils.h>
  2. #include<iostream>
  3. #include<exception>
  4. #include<cassert>
  5. void run_tests()
  6. {
  7. using __vic::starts_with;
  8. const std::string sample("sample");
  9. assert(starts_with(sample, 's'));
  10. assert(starts_with(sample, "sa"));
  11. assert(starts_with(sample, std::string("sa")));
  12. assert(starts_with("sample", 's'));
  13. assert(starts_with("sample", "sa"));
  14. assert(starts_with("sample", "sa", 2));
  15. assert(!starts_with(sample, 'a'));
  16. assert(!starts_with(sample, "am"));
  17. assert(!starts_with(sample, std::string("am")));
  18. assert(!starts_with("sample", 'a'));
  19. assert(!starts_with("sample", "am"));
  20. assert(!starts_with("sample", "am", 2));
  21. assert(starts_with(sample, ""));
  22. assert(starts_with("", ""));
  23. }
  24. int main()
  25. {
  26. try
  27. {
  28. run_tests();
  29. return 0;
  30. }
  31. catch(const std::exception &ex)
  32. {
  33. std::cerr << ex.what() << '\n';
  34. }
  35. return 1;
  36. }