starts_with.ptr.pass.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. // UNSUPPORTED: c++98, c++03, c++11, c++14, c++17
  9. // <string>
  10. // bool starts_with(const CharT *x) const;
  11. #include <string>
  12. #include <cassert>
  13. #include "test_macros.h"
  14. int main(int, char**)
  15. {
  16. {
  17. typedef std::string S;
  18. const char *s = "abcde";
  19. S s0 {};
  20. S s1 { s, 1 };
  21. S s2 { s, 2 };
  22. // S s3 { s, 3 };
  23. // S s4 { s, 4 };
  24. // S s5 { s, 5 };
  25. S sNot {"def", 3 };
  26. LIBCPP_ASSERT_NOEXCEPT(s0.starts_with(""));
  27. assert ( s0.starts_with(""));
  28. assert (!s0.starts_with("a"));
  29. assert ( s1.starts_with(""));
  30. assert ( s1.starts_with("a"));
  31. assert (!s1.starts_with("ab"));
  32. assert (!s1.starts_with("abc"));
  33. assert (!s1.starts_with("abcd"));
  34. assert (!s1.starts_with("abcde"));
  35. assert (!s1.starts_with("def"));
  36. assert ( s2.starts_with(""));
  37. assert ( s2.starts_with("a"));
  38. assert ( s2.starts_with("ab"));
  39. assert (!s2.starts_with("abc"));
  40. assert (!s2.starts_with("abcd"));
  41. assert (!s2.starts_with("abcde"));
  42. assert (!s2.starts_with("def"));
  43. assert ( sNot.starts_with(""));
  44. assert (!sNot.starts_with("a"));
  45. assert (!sNot.starts_with("ab"));
  46. assert (!sNot.starts_with("abc"));
  47. assert (!sNot.starts_with("abcd"));
  48. assert (!sNot.starts_with("abcde"));
  49. assert ( sNot.starts_with("def"));
  50. }
  51. return 0;
  52. }