pointer.pass.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // <string>
  10. // int compare(const charT *s) const;
  11. #include <string>
  12. #include <cassert>
  13. int sign(int x)
  14. {
  15. if (x == 0)
  16. return 0;
  17. if (x < 0)
  18. return -1;
  19. return 1;
  20. }
  21. template <class S>
  22. void
  23. test(const S& s, const typename S::value_type* str, int x)
  24. {
  25. assert(sign(s.compare(str)) == sign(x));
  26. }
  27. typedef std::string S;
  28. int main()
  29. {
  30. test(S(""), "", 0);
  31. test(S(""), "abcde", -5);
  32. test(S(""), "abcdefghij", -10);
  33. test(S(""), "abcdefghijklmnopqrst", -20);
  34. test(S("abcde"), "", 5);
  35. test(S("abcde"), "abcde", 0);
  36. test(S("abcde"), "abcdefghij", -5);
  37. test(S("abcde"), "abcdefghijklmnopqrst", -15);
  38. test(S("abcdefghij"), "", 10);
  39. test(S("abcdefghij"), "abcde", 5);
  40. test(S("abcdefghij"), "abcdefghij", 0);
  41. test(S("abcdefghij"), "abcdefghijklmnopqrst", -10);
  42. test(S("abcdefghijklmnopqrst"), "", 20);
  43. test(S("abcdefghijklmnopqrst"), "abcde", 15);
  44. test(S("abcdefghijklmnopqrst"), "abcdefghij", 10);
  45. test(S("abcdefghijklmnopqrst"), "abcdefghijklmnopqrst", 0);
  46. }