test_operators.cpp 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. *
  3. * Copyright (c) 2004
  4. * John Maddock
  5. *
  6. * Use, modification and distribution are subject to the
  7. * Boost Software License, Version 1.0. (See accompanying file
  8. * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  9. *
  10. */
  11. #include "test.hpp"
  12. #include <iostream>
  13. #include <iomanip>
  14. #if !BOOST_WORKAROUND(BOOST_MSVC, <= 1300)\
  15. && !BOOST_WORKAROUND(__HP_aCC, BOOST_TESTED_AT(55500))\
  16. && !(defined(__GNUC__) && (__GNUC__ < 3) && !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)))
  17. template <class T1, class T2>
  18. void test_less(const T1& t1, const T2& t2)
  19. {
  20. if(!(t1 < t2))
  21. {
  22. BOOST_REGEX_TEST_ERROR("Failed < comparison", char);
  23. }
  24. if(!(t1 <= t2))
  25. {
  26. BOOST_REGEX_TEST_ERROR("Failed <= comparison", char);
  27. }
  28. if(!(t1 != t2))
  29. {
  30. BOOST_REGEX_TEST_ERROR("Failed != comparison", char);
  31. }
  32. if(t1 == t2)
  33. {
  34. BOOST_REGEX_TEST_ERROR("Failed == comparison", char);
  35. }
  36. if(t1 >= t2)
  37. {
  38. BOOST_REGEX_TEST_ERROR("Failed >= comparison", char);
  39. }
  40. if(t1 > t2)
  41. {
  42. BOOST_REGEX_TEST_ERROR("Failed > comparison", char);
  43. }
  44. }
  45. template <class T1, class T2>
  46. void test_greater(const T1& t1, const T2& t2)
  47. {
  48. if(t1 < t2)
  49. {
  50. BOOST_REGEX_TEST_ERROR("Failed < comparison", char);
  51. }
  52. if(t1 <= t2)
  53. {
  54. BOOST_REGEX_TEST_ERROR("Failed <= comparison", char);
  55. }
  56. if(!(t1 != t2))
  57. {
  58. BOOST_REGEX_TEST_ERROR("Failed != comparison", char);
  59. }
  60. if(t1 == t2)
  61. {
  62. BOOST_REGEX_TEST_ERROR("Failed == comparison", char);
  63. }
  64. if(!(t1 >= t2))
  65. {
  66. BOOST_REGEX_TEST_ERROR("Failed >= comparison", char);
  67. }
  68. if(!(t1 > t2))
  69. {
  70. BOOST_REGEX_TEST_ERROR("Failed > comparison", char);
  71. }
  72. }
  73. template <class T1, class T2>
  74. void test_equal(const T1& t1, const T2& t2)
  75. {
  76. if(t1 < t2)
  77. {
  78. BOOST_REGEX_TEST_ERROR("Failed < comparison", char);
  79. }
  80. if(!(t1 <= t2))
  81. {
  82. BOOST_REGEX_TEST_ERROR("Failed <= comparison", char);
  83. }
  84. if(t1 != t2)
  85. {
  86. BOOST_REGEX_TEST_ERROR("Failed != comparison", char);
  87. }
  88. if(!(t1 == t2))
  89. {
  90. BOOST_REGEX_TEST_ERROR("Failed == comparison", char);
  91. }
  92. if(!(t1 >= t2))
  93. {
  94. BOOST_REGEX_TEST_ERROR("Failed >= comparison", char);
  95. }
  96. if(t1 > t2)
  97. {
  98. BOOST_REGEX_TEST_ERROR("Failed > comparison", char);
  99. }
  100. }
  101. template <class T1, class T2, class T3>
  102. void test_plus(const T1& t1, const T2& t2, const T3& t3)
  103. {
  104. if(t1 + t2 != t3)
  105. {
  106. BOOST_REGEX_TEST_ERROR("Failed addition", char);
  107. }
  108. if(t3 != t1 + t2)
  109. {
  110. BOOST_REGEX_TEST_ERROR("Failed addition", char);
  111. }
  112. }
  113. void test_operators()
  114. {
  115. test_info<char>::set_typename("sub_match operators");
  116. std::string s1("a");
  117. std::string s2("b");
  118. boost::sub_match<std::string::const_iterator> sub1, sub2;
  119. sub1.first = s1.begin();
  120. sub1.second = s1.end();
  121. sub1.matched = true;
  122. sub2.first = s2.begin();
  123. sub2.second = s2.end();
  124. sub2.matched = true;
  125. test_less(sub1, sub2);
  126. test_less(sub1, s2.c_str());
  127. test_less(s1.c_str(), sub2);
  128. test_less(sub1, *s2.c_str());
  129. test_less(*s1.c_str(), sub2);
  130. test_less(sub1, s2);
  131. test_less(s1, sub2);
  132. test_greater(sub2, sub1);
  133. test_greater(sub2, s1.c_str());
  134. test_greater(s2.c_str(), sub1);
  135. test_greater(sub2, *s1.c_str());
  136. test_greater(*s2.c_str(), sub1);
  137. test_greater(sub2, s1);
  138. test_greater(s2, sub1);
  139. test_equal(sub1, sub1);
  140. test_equal(sub1, s1.c_str());
  141. test_equal(s1.c_str(), sub1);
  142. test_equal(sub1, *s1.c_str());
  143. test_equal(*s1.c_str(), sub1);
  144. test_equal(sub1, s1);
  145. test_equal(s1, sub1);
  146. test_plus(sub2, sub1, "ba");
  147. test_plus(sub2, s1.c_str(), "ba");
  148. test_plus(s2.c_str(), sub1, "ba");
  149. test_plus(sub2, *s1.c_str(), "ba");
  150. test_plus(*s2.c_str(), sub1, "ba");
  151. test_plus(sub2, s1, "ba");
  152. test_plus(s2, sub1, "ba");
  153. }
  154. #else
  155. #include <iostream>
  156. void test_operators()
  157. {
  158. std::cout <<
  159. "\n<note>\n"
  160. "This compiler version does not support the sub_match comparison operators\n"
  161. "tests for these operators are not carried out\n"
  162. "</note>\n";
  163. }
  164. #endif