rj_schema 0.2.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (371) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rj_schema/rapidjson/CMakeLists.txt +9 -4
  3. data/ext/rj_schema/rapidjson/RapidJSONConfig.cmake.in +10 -0
  4. data/ext/rj_schema/rapidjson/appveyor.yml +22 -9
  5. data/ext/rj_schema/rapidjson/bin/data/abcde.txt +1 -0
  6. data/ext/rj_schema/rapidjson/bin/unittestschema/address.json +139 -0
  7. data/ext/rj_schema/rapidjson/bin/unittestschema/allOf_address.json +7 -0
  8. data/ext/rj_schema/rapidjson/bin/unittestschema/anyOf_address.json +7 -0
  9. data/ext/rj_schema/rapidjson/bin/unittestschema/oneOf_address.json +7 -0
  10. data/ext/rj_schema/rapidjson/contrib/natvis/rapidjson.natvis +2 -2
  11. data/ext/rj_schema/rapidjson/doc/dom.md +1 -0
  12. data/ext/rj_schema/rapidjson/doc/dom.zh-cn.md +1 -0
  13. data/ext/rj_schema/rapidjson/doc/faq.md +3 -3
  14. data/ext/rj_schema/rapidjson/doc/faq.zh-cn.md +8 -8
  15. data/ext/rj_schema/rapidjson/doc/internals.md +1 -1
  16. data/ext/rj_schema/rapidjson/doc/internals.zh-cn.md +2 -2
  17. data/ext/rj_schema/rapidjson/doc/pointer.zh-cn.md +1 -1
  18. data/ext/rj_schema/rapidjson/doc/sax.md +1 -1
  19. data/ext/rj_schema/rapidjson/doc/sax.zh-cn.md +2 -2
  20. data/ext/rj_schema/rapidjson/doc/stream.md +1 -1
  21. data/ext/rj_schema/rapidjson/doc/tutorial.md +1 -1
  22. data/ext/rj_schema/rapidjson/doc/tutorial.zh-cn.md +7 -6
  23. data/ext/rj_schema/rapidjson/example/CMakeLists.txt +1 -0
  24. data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +118 -0
  25. data/ext/rj_schema/rapidjson/example/sortkeys/sortkeys.cpp +62 -0
  26. data/ext/rj_schema/rapidjson/example/tutorial/tutorial.cpp +1 -1
  27. data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +6 -6
  28. data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +1 -1
  29. data/ext/rj_schema/rapidjson/include/rapidjson/document.h +124 -35
  30. data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +1 -1
  31. data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +1 -1
  32. data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +49 -1
  33. data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +56 -1
  34. data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +2 -2
  35. data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +1 -1
  36. data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +2 -2
  37. data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +2 -2
  38. data/ext/rj_schema/rapidjson/include/rapidjson/internal/clzll.h +71 -0
  39. data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +3 -17
  40. data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +1 -1
  41. data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +1 -1
  42. data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +1 -1
  43. data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +1 -1
  44. data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +1 -1
  45. data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +20 -13
  46. data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +4 -3
  47. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +1 -1
  48. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +1 -1
  49. data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +1 -1
  50. data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +50 -35
  51. data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +1 -1
  52. data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +1 -1
  53. data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +1 -1
  54. data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +63 -5
  55. data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +2 -2
  56. data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +63 -1
  57. data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +67 -53
  58. data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +318 -164
  59. data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +1 -1
  60. data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +1 -1
  61. data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +10 -10
  62. data/ext/rj_schema/rapidjson/readme.md +51 -1
  63. data/ext/rj_schema/rapidjson/readme.zh-cn.md +2 -2
  64. data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +1 -1
  65. data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +1 -1
  66. data/ext/rj_schema/rapidjson/test/perftest/perftest.h +1 -1
  67. data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +2 -2
  68. data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +75 -1
  69. data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +1 -0
  70. data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +1 -1
  71. data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +1 -1
  72. data/ext/rj_schema/rapidjson/test/unittest/clzlltest.cpp +34 -0
  73. data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +19 -19
  74. data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +1 -1
  75. data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +1 -1
  76. data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +1 -1
  77. data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +1 -1
  78. data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +45 -2
  79. data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +1 -1
  80. data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +10 -10
  81. data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +8 -8
  82. data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +1 -1
  83. data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +1 -1
  84. data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +1 -1
  85. data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +157 -16
  86. data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +1 -1
  87. data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +113 -75
  88. data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +2 -1
  89. data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +593 -78
  90. data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +1 -1
  91. data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +1 -1
  92. data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +5 -5
  93. data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +1 -1
  94. data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +1 -1
  95. data/ext/rj_schema/rapidjson/test/unittest/unittest.h +4 -1
  96. data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +12 -12
  97. data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +1 -1
  98. data/ext/rj_schema/rapidjson/thirdparty/gtest/BUILD.bazel +175 -0
  99. data/ext/rj_schema/rapidjson/thirdparty/gtest/CMakeLists.txt +18 -1
  100. data/ext/rj_schema/rapidjson/thirdparty/gtest/CONTRIBUTING.md +160 -0
  101. data/ext/rj_schema/rapidjson/thirdparty/gtest/LICENSE +28 -0
  102. data/ext/rj_schema/rapidjson/thirdparty/gtest/Makefile.am +14 -0
  103. data/ext/rj_schema/rapidjson/thirdparty/gtest/README.md +16 -35
  104. data/ext/rj_schema/rapidjson/thirdparty/gtest/WORKSPACE +8 -0
  105. data/ext/rj_schema/rapidjson/thirdparty/gtest/appveyor.yml +104 -0
  106. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/build-linux-autotools.sh +44 -0
  107. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/build-linux-bazel.sh +36 -0
  108. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/env-linux.sh +41 -0
  109. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/env-osx.sh +40 -0
  110. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/get-nprocessors.sh +48 -0
  111. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/install-linux.sh +49 -0
  112. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/install-osx.sh +39 -0
  113. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/log-config.sh +51 -0
  114. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/travis.sh +44 -0
  115. data/ext/rj_schema/rapidjson/thirdparty/gtest/configure.ac +16 -0
  116. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/CHANGES +1 -1
  117. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/CMakeLists.txt +72 -32
  118. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/README.md +53 -42
  119. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/cmake/gmock.pc.in +9 -0
  120. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/cmake/gmock_main.pc.in +9 -0
  121. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/configure.ac +4 -4
  122. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/CheatSheet.md +6 -4
  123. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/CookBook.md +117 -132
  124. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/Documentation.md +7 -4
  125. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/ForDummies.md +20 -12
  126. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/FrequentlyAskedQuestions.md +1 -2
  127. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-actions.h +83 -26
  128. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-actions.h +262 -68
  129. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-actions.h.pump +45 -6
  130. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-function-mockers.h +650 -366
  131. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +76 -20
  132. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-matchers.h +308 -229
  133. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-matchers.h.pump +18 -15
  134. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-nice-strict.h +87 -26
  135. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +33 -16
  136. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-matchers.h +1209 -353
  137. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-more-matchers.h +33 -0
  138. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-spec-builders.h +159 -88
  139. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock.h +2 -1
  140. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump +1 -1
  141. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-matchers.h +3 -4
  142. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h +16 -9
  143. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-internal-utils.h +71 -8
  144. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-port.h +7 -11
  145. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock.sln +14 -0
  146. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock.vcxproj +69 -6
  147. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_config.props +2 -2
  148. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_main.vcxproj +69 -6
  149. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_test.vcxproj +83 -8
  150. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock.sln +14 -0
  151. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock.vcxproj +63 -2
  152. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock_main.vcxproj +63 -2
  153. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock_test.vcxproj +76 -3
  154. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/fuse_gmock_files.py +1 -1
  155. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/README +4 -5
  156. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/ast.py +3 -3
  157. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-cardinalities.cc +1 -1
  158. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-internal-utils.cc +36 -6
  159. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-matchers.cc +210 -135
  160. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-spec-builders.cc +108 -48
  161. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock.cc +23 -1
  162. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/BUILD.bazel +123 -0
  163. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-actions_test.cc +166 -2
  164. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-cardinalities_test.cc +1 -1
  165. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-actions_test.cc +64 -62
  166. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-function-mockers_test.cc +43 -18
  167. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-internal-utils_test.cc +11 -9
  168. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-matchers_test.cc +91 -36
  169. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-internal-utils_test.cc +33 -14
  170. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-matchers_test.cc +1286 -167
  171. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-more-actions_test.cc +85 -83
  172. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-nice-strict_test.cc +102 -15
  173. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-spec-builders_test.cc +136 -9
  174. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link2_test.cc +1 -1
  175. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link_test.cc +1 -1
  176. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link_test.h +24 -2
  177. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test.py +8 -5
  178. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test_.cc +20 -1
  179. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test_golden.txt +8 -1
  180. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_stress_test.cc +3 -2
  181. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_test.cc +44 -2
  182. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_test_utils.py +5 -7
  183. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/CMakeLists.txt +40 -14
  184. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/Makefile.am +60 -31
  185. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/README.md +232 -171
  186. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/gtest.pc.in +9 -0
  187. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/gtest_main.pc.in +10 -0
  188. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/internal_utils.cmake +54 -16
  189. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/configure.ac +1 -1
  190. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/Pkgconfig.md +146 -0
  191. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/PumpManual.md +2 -2
  192. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/XcodeGuide.md +6 -6
  193. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/{AdvancedGuide.md → advanced.md} +260 -26
  194. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/{FAQ.md → faq.md} +62 -57
  195. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/{Primer.md → primer.md} +43 -9
  196. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/{Samples.md → samples.md} +0 -0
  197. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-death-test.h +53 -5
  198. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-message.h +1 -2
  199. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-param-test.h +30 -36
  200. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-param-test.h.pump +8 -17
  201. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-printers.h +140 -51
  202. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-spi.h +2 -3
  203. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-typed-test.h +4 -3
  204. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest.h +126 -30
  205. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest_pred_impl.h +6 -7
  206. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest_prod.h +8 -5
  207. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/custom/gtest-port.h +6 -5
  208. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/custom/gtest.h +4 -0
  209. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-death-test-internal.h +13 -57
  210. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-filepath.h +1 -2
  211. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-internal.h +98 -59
  212. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util-generated.h +34 -41
  213. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util-generated.h.pump +3 -10
  214. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util.h +9 -17
  215. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-port-arch.h +8 -1
  216. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-port.h +232 -99
  217. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-string.h +3 -3
  218. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-type-util.h +17 -1
  219. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-type-util.h.pump +17 -1
  220. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.sln +55 -0
  221. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.vcxproj +149 -0
  222. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.vcxproj.filters +18 -0
  223. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.sln +55 -0
  224. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.vcxproj +149 -0
  225. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.vcxproj.filters +18 -0
  226. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main-md.vcxproj +154 -0
  227. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main-md.vcxproj.filters +18 -0
  228. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main.vcxproj +162 -0
  229. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main.vcxproj.filters +18 -0
  230. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test-md.vcxproj +199 -0
  231. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test-md.vcxproj.filters +26 -0
  232. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test.vcxproj +191 -0
  233. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test.vcxproj.filters +26 -0
  234. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest-md.vcxproj +188 -0
  235. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest-md.vcxproj.filters +18 -0
  236. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest.vcxproj +180 -0
  237. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest.vcxproj.filters +18 -0
  238. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/prime_tables.h +6 -2
  239. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample1.cc +1 -1
  240. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample10_unittest.cc +0 -4
  241. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample1_unittest.cc +2 -1
  242. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample2_unittest.cc +2 -1
  243. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample3_unittest.cc +7 -6
  244. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample4_unittest.cc +5 -1
  245. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample5_unittest.cc +3 -3
  246. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample6_unittest.cc +2 -1
  247. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample7_unittest.cc +10 -22
  248. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample8_unittest.cc +2 -1
  249. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample9_unittest.cc +0 -3
  250. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/fuse_gtest_files.py +1 -1
  251. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/gen_gtest_pred_impl.py +10 -10
  252. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/upload.py +1 -1
  253. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-all.cc +1 -1
  254. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-death-test.cc +226 -32
  255. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-filepath.cc +5 -7
  256. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-internal-inl.h +21 -29
  257. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-port.cc +85 -67
  258. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-printers.cc +93 -8
  259. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-test-part.cc +1 -9
  260. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-typed-test.cc +1 -0
  261. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest.cc +622 -164
  262. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest_main.cc +1 -1
  263. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/BUILD.bazel +396 -0
  264. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-death-test_test.cc +12 -15
  265. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-filepath_test.cc +2 -12
  266. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-listener_test.cc +1 -1
  267. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-options_test.cc +6 -8
  268. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test2_test.cc +1 -5
  269. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test_test.cc +84 -29
  270. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test_test.h +1 -5
  271. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-port_test.cc +11 -12
  272. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-printers_test.cc +165 -63
  273. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-typed-test2_test.cc +1 -1
  274. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-typed-test_test.cc +1 -1
  275. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-unittest-api_test.cc +1 -1
  276. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_all_test.cc +13 -13
  277. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_assert_by_exception_test.cc +119 -0
  278. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_break_on_failure_unittest.py +1 -3
  279. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_break_on_failure_unittest_.cc +1 -2
  280. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_catch_exceptions_test.py +0 -2
  281. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_catch_exceptions_test_.cc +1 -1
  282. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_color_test.py +1 -2
  283. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_color_test_.cc +0 -8
  284. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_env_var_test.py +6 -4
  285. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_env_var_test_.cc +0 -2
  286. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_environment_test.cc +0 -3
  287. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_filter_unittest.py +20 -18
  288. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_filter_unittest_.cc +0 -2
  289. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_help_test.py +1 -1
  290. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_outfiles_test.py +162 -0
  291. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_output_unittest.py +611 -0
  292. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_test_utils.py +60 -0
  293. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_list_tests_unittest.py +4 -4
  294. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_main_unittest.cc +2 -2
  295. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test.py +11 -7
  296. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test_.cc +17 -12
  297. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test_golden_lin.txt +104 -66
  298. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_pred_impl_unittest.cc +1 -1
  299. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_prod_test.cc +2 -2
  300. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_repeat_test.cc +2 -19
  301. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_stress_test.cc +0 -6
  302. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_test_utils.py +12 -14
  303. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_testbridge_test.py +65 -0
  304. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_testbridge_test_.cc +44 -0
  305. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_throw_on_failure_test.py +1 -1
  306. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_uninitialized_test.py +4 -5
  307. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_uninitialized_test_.cc +2 -2
  308. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_unittest.cc +240 -149
  309. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfile1_test_.cc +0 -1
  310. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfile2_test_.cc +0 -1
  311. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfiles_test.py +15 -7
  312. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_output_unittest.py +100 -30
  313. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_output_unittest_.cc +0 -2
  314. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_test_utils.py +25 -23
  315. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/production.cc +1 -1
  316. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/production.h +1 -1
  317. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Scripts/versiongenerate.py +4 -4
  318. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/gtest.xcodeproj/project.pbxproj +47 -0
  319. data/ext/rj_schema/rapidjson/travis-doxygen.sh +13 -6
  320. data/ext/rj_schema/rj_schema.cpp +161 -17
  321. data/lib/rj_schema.rb +1 -1
  322. metadata +63 -58
  323. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/DevGuide.md +0 -132
  324. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_5/CheatSheet.md +0 -525
  325. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_5/CookBook.md +0 -3250
  326. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_5/Documentation.md +0 -11
  327. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_5/ForDummies.md +0 -439
  328. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_5/FrequentlyAskedQuestions.md +0 -624
  329. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_6/CheatSheet.md +0 -534
  330. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_6/CookBook.md +0 -3342
  331. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_6/Documentation.md +0 -12
  332. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_6/ForDummies.md +0 -439
  333. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_6/FrequentlyAskedQuestions.md +0 -628
  334. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_7/CheatSheet.md +0 -556
  335. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_7/CookBook.md +0 -3432
  336. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_7/Documentation.md +0 -12
  337. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_7/ForDummies.md +0 -439
  338. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/v1_7/FrequentlyAskedQuestions.md +0 -628
  339. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/DevGuide.md +0 -126
  340. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/Documentation.md +0 -14
  341. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_5_AdvancedGuide.md +0 -2096
  342. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_5_Documentation.md +0 -12
  343. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_5_FAQ.md +0 -886
  344. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_5_Primer.md +0 -497
  345. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_5_PumpManual.md +0 -177
  346. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_5_XcodeGuide.md +0 -93
  347. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_6_AdvancedGuide.md +0 -2178
  348. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_6_Documentation.md +0 -14
  349. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_6_FAQ.md +0 -1038
  350. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_6_Primer.md +0 -501
  351. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_6_PumpManual.md +0 -177
  352. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_6_Samples.md +0 -14
  353. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_6_XcodeGuide.md +0 -93
  354. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_7_AdvancedGuide.md +0 -2181
  355. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_7_Documentation.md +0 -14
  356. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_7_FAQ.md +0 -1082
  357. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_7_Primer.md +0 -501
  358. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_7_PumpManual.md +0 -177
  359. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_7_Samples.md +0 -14
  360. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/V1_7_XcodeGuide.md +0 -93
  361. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest-md.sln +0 -45
  362. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest-md.vcproj +0 -126
  363. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest.sln +0 -45
  364. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest.vcproj +0 -126
  365. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest_main-md.vcproj +0 -129
  366. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest_main.vcproj +0 -129
  367. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest_prod_test-md.vcproj +0 -164
  368. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest_prod_test.vcproj +0 -164
  369. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest_unittest-md.vcproj +0 -147
  370. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/gtest_unittest.vcproj +0 -147
  371. data/ext/rj_schema/rapidjson/thirdparty/gtest/travis.sh +0 -15
@@ -1,6 +1,6 @@
1
1
  $$ -*- mode: c++; -*-
2
- $$ This is a Pump source file. Please use Pump to convert it to
3
- $$ gmock-generated-actions.h.
2
+ $$ This is a Pump source file. Please use Pump to convert
3
+ $$ it to gmock-generated-matchers.h.
4
4
  $$
5
5
  $var n = 10 $$ The maximum arity we support.
6
6
  $$ }} This line fixes auto-indentation of the following code in Emacs.
@@ -303,6 +303,9 @@ $for j, [[
303
303
 
304
304
  // UnorderedElementsAre(e_1, e_2, ..., e_n) is an ElementsAre extension
305
305
  // that matches n elements in any order. We support up to n=$n arguments.
306
+ //
307
+ // If you have >$n elements, consider UnorderedElementsAreArray() or
308
+ // UnorderedPointwise() instead.
306
309
 
307
310
  $range i 0..n
308
311
  $for i [[
@@ -479,7 +482,7 @@ $$ // show up in the generated code.
479
482
  // using testing::PrintToString;
480
483
  //
481
484
  // MATCHER_P2(InClosedRange, low, hi,
482
- // string(negation ? "is not" : "is") + " in range [" +
485
+ // std::string(negation ? "is not" : "is") + " in range [" +
483
486
  // PrintToString(low) + ", " + PrintToString(hi) + "]") {
484
487
  // return low <= arg && arg <= hi;
485
488
  // }
@@ -587,7 +590,7 @@ $$ // show up in the generated code.
587
590
  // ================
588
591
  //
589
592
  // To learn more about using these macros, please search for 'MATCHER'
590
- // on http://code.google.com/p/googlemock/wiki/CookBook.
593
+ // on https://github.com/google/googletest/blob/master/googlemock/docs/CookBook.md
591
594
 
592
595
  $range i 0..n
593
596
  $for i
@@ -604,32 +607,34 @@ $var template = [[$if i==0 [[]] $else [[
604
607
  ]]]]
605
608
  $var ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
606
609
  $var impl_ctor_param_list = [[$for j, [[p$j##_type gmock_p$j]]]]
607
- $var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
608
- $var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(gmock_p$j)]]]]]]
610
+ $var impl_inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]]
611
+ $var inits = [[$if i==0 [[]] $else [[ : $for j, [[p$j(::testing::internal::move(gmock_p$j))]]]]]]
609
612
  $var params = [[$for j, [[p$j]]]]
610
613
  $var param_types = [[$if i==0 [[]] $else [[<$for j, [[p$j##_type]]>]]]]
611
614
  $var param_types_and_names = [[$for j, [[p$j##_type p$j]]]]
612
615
  $var param_field_decls = [[$for j
613
616
  [[
614
617
 
615
- p$j##_type p$j;\
618
+ p$j##_type const p$j;\
616
619
  ]]]]
617
620
  $var param_field_decls2 = [[$for j
618
621
  [[
619
622
 
620
- p$j##_type p$j;\
623
+ p$j##_type const p$j;\
621
624
  ]]]]
622
625
 
623
626
  #define $macro_name(name$for j [[, p$j]], description)\$template
624
627
  class $class_name {\
625
628
  public:\
626
629
  template <typename arg_type>\
627
- class gmock_Impl : public ::testing::MatcherInterface<arg_type> {\
630
+ class gmock_Impl : public ::testing::MatcherInterface<\
631
+ GTEST_REFERENCE_TO_CONST_(arg_type)> {\
628
632
  public:\
629
633
  [[$if i==1 [[explicit ]]]]gmock_Impl($impl_ctor_param_list)\
630
634
  $impl_inits {}\
631
635
  virtual bool MatchAndExplain(\
632
- arg_type arg, ::testing::MatchResultListener* result_listener) const;\
636
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
637
+ ::testing::MatchResultListener* result_listener) const;\
633
638
  virtual void DescribeTo(::std::ostream* gmock_os) const {\
634
639
  *gmock_os << FormatDescription(false);\
635
640
  }\
@@ -637,8 +642,8 @@ $var param_field_decls2 = [[$for j
637
642
  *gmock_os << FormatDescription(true);\
638
643
  }\$param_field_decls
639
644
  private:\
640
- ::testing::internal::string FormatDescription(bool negation) const {\
641
- const ::testing::internal::string gmock_description = (description);\
645
+ ::std::string FormatDescription(bool negation) const {\
646
+ ::std::string gmock_description = (description);\
642
647
  if (!gmock_description.empty())\
643
648
  return gmock_description;\
644
649
  return ::testing::internal::FormatMatcherDescription(\
@@ -646,7 +651,6 @@ $var param_field_decls2 = [[$for j
646
651
  ::testing::internal::UniversalTersePrintTupleFieldsToStrings(\
647
652
  ::testing::tuple<$for j, [[p$j##_type]]>($for j, [[p$j]])));\
648
653
  }\
649
- GTEST_DISALLOW_ASSIGN_(gmock_Impl);\
650
654
  };\
651
655
  template <typename arg_type>\
652
656
  operator ::testing::Matcher<arg_type>() const {\
@@ -656,14 +660,13 @@ $var param_field_decls2 = [[$for j
656
660
  [[$if i==1 [[explicit ]]]]$class_name($ctor_param_list)$inits {\
657
661
  }\$param_field_decls2
658
662
  private:\
659
- GTEST_DISALLOW_ASSIGN_($class_name);\
660
663
  };\$template
661
664
  inline $class_name$param_types name($param_types_and_names) {\
662
665
  return $class_name$param_types($params);\
663
666
  }\$template
664
667
  template <typename arg_type>\
665
668
  bool $class_name$param_types::gmock_Impl<arg_type>::MatchAndExplain(\
666
- arg_type arg, \
669
+ GTEST_REFERENCE_TO_CONST_(arg_type) arg,\
667
670
  ::testing::MatchResultListener* result_listener GTEST_ATTRIBUTE_UNUSED_)\
668
671
  const
669
672
  ]]
@@ -51,10 +51,9 @@
51
51
  // NiceMock<MockFoo>.
52
52
  //
53
53
  // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
54
- // their respective base class, with up-to 10 arguments. Therefore
55
- // you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
56
- // where MockFoo has a constructor that accepts (int, const char*),
57
- // for example.
54
+ // their respective base class. Therefore you can write
55
+ // NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
56
+ // has a constructor that accepts (int, const char*), for example.
58
57
  //
59
58
  // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
60
59
  // and StrictMock<MockFoo> only works for mock methods defined using
@@ -63,10 +62,6 @@
63
62
  // or "strict" modifier may not affect it, depending on the compiler.
64
63
  // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
65
64
  // supported.
66
- //
67
- // Another known limitation is that the constructors of the base mock
68
- // cannot have arguments passed by non-const reference, which are
69
- // banned by the Google C++ style guide anyway.
70
65
 
71
66
  #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
72
67
  #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
@@ -79,15 +74,35 @@ namespace testing {
79
74
  template <class MockClass>
80
75
  class NiceMock : public MockClass {
81
76
  public:
82
- // We don't factor out the constructor body to a common method, as
83
- // we have to avoid a possible clash with members of MockClass.
84
- NiceMock() {
77
+ NiceMock() : MockClass() {
85
78
  ::testing::Mock::AllowUninterestingCalls(
86
79
  internal::ImplicitCast_<MockClass*>(this));
87
80
  }
88
81
 
89
- // C++ doesn't (yet) allow inheritance of constructors, so we have
90
- // to define it for each arity.
82
+ #if GTEST_LANG_CXX11
83
+ // Ideally, we would inherit base class's constructors through a using
84
+ // declaration, which would preserve their visibility. However, many existing
85
+ // tests rely on the fact that current implementation reexports protected
86
+ // constructors as public. These tests would need to be cleaned up first.
87
+
88
+ // Single argument constructor is special-cased so that it can be
89
+ // made explicit.
90
+ template <typename A>
91
+ explicit NiceMock(A&& arg) : MockClass(std::forward<A>(arg)) {
92
+ ::testing::Mock::AllowUninterestingCalls(
93
+ internal::ImplicitCast_<MockClass*>(this));
94
+ }
95
+
96
+ template <typename A1, typename A2, typename... An>
97
+ NiceMock(A1&& arg1, A2&& arg2, An&&... args)
98
+ : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
99
+ std::forward<An>(args)...) {
100
+ ::testing::Mock::AllowUninterestingCalls(
101
+ internal::ImplicitCast_<MockClass*>(this));
102
+ }
103
+ #else
104
+ // C++98 doesn't have variadic templates, so we have to define one
105
+ // for each arity.
91
106
  template <typename A1>
92
107
  explicit NiceMock(const A1& a1) : MockClass(a1) {
93
108
  ::testing::Mock::AllowUninterestingCalls(
@@ -163,7 +178,9 @@ class NiceMock : public MockClass {
163
178
  internal::ImplicitCast_<MockClass*>(this));
164
179
  }
165
180
 
166
- virtual ~NiceMock() {
181
+ #endif // GTEST_LANG_CXX11
182
+
183
+ ~NiceMock() {
167
184
  ::testing::Mock::UnregisterCallReaction(
168
185
  internal::ImplicitCast_<MockClass*>(this));
169
186
  }
@@ -175,15 +192,35 @@ class NiceMock : public MockClass {
175
192
  template <class MockClass>
176
193
  class NaggyMock : public MockClass {
177
194
  public:
178
- // We don't factor out the constructor body to a common method, as
179
- // we have to avoid a possible clash with members of MockClass.
180
- NaggyMock() {
195
+ NaggyMock() : MockClass() {
196
+ ::testing::Mock::WarnUninterestingCalls(
197
+ internal::ImplicitCast_<MockClass*>(this));
198
+ }
199
+
200
+ #if GTEST_LANG_CXX11
201
+ // Ideally, we would inherit base class's constructors through a using
202
+ // declaration, which would preserve their visibility. However, many existing
203
+ // tests rely on the fact that current implementation reexports protected
204
+ // constructors as public. These tests would need to be cleaned up first.
205
+
206
+ // Single argument constructor is special-cased so that it can be
207
+ // made explicit.
208
+ template <typename A>
209
+ explicit NaggyMock(A&& arg) : MockClass(std::forward<A>(arg)) {
181
210
  ::testing::Mock::WarnUninterestingCalls(
182
211
  internal::ImplicitCast_<MockClass*>(this));
183
212
  }
184
213
 
185
- // C++ doesn't (yet) allow inheritance of constructors, so we have
186
- // to define it for each arity.
214
+ template <typename A1, typename A2, typename... An>
215
+ NaggyMock(A1&& arg1, A2&& arg2, An&&... args)
216
+ : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
217
+ std::forward<An>(args)...) {
218
+ ::testing::Mock::WarnUninterestingCalls(
219
+ internal::ImplicitCast_<MockClass*>(this));
220
+ }
221
+ #else
222
+ // C++98 doesn't have variadic templates, so we have to define one
223
+ // for each arity.
187
224
  template <typename A1>
188
225
  explicit NaggyMock(const A1& a1) : MockClass(a1) {
189
226
  ::testing::Mock::WarnUninterestingCalls(
@@ -259,7 +296,9 @@ class NaggyMock : public MockClass {
259
296
  internal::ImplicitCast_<MockClass*>(this));
260
297
  }
261
298
 
262
- virtual ~NaggyMock() {
299
+ #endif // GTEST_LANG_CXX11
300
+
301
+ ~NaggyMock() {
263
302
  ::testing::Mock::UnregisterCallReaction(
264
303
  internal::ImplicitCast_<MockClass*>(this));
265
304
  }
@@ -271,15 +310,35 @@ class NaggyMock : public MockClass {
271
310
  template <class MockClass>
272
311
  class StrictMock : public MockClass {
273
312
  public:
274
- // We don't factor out the constructor body to a common method, as
275
- // we have to avoid a possible clash with members of MockClass.
276
- StrictMock() {
313
+ StrictMock() : MockClass() {
314
+ ::testing::Mock::FailUninterestingCalls(
315
+ internal::ImplicitCast_<MockClass*>(this));
316
+ }
317
+
318
+ #if GTEST_LANG_CXX11
319
+ // Ideally, we would inherit base class's constructors through a using
320
+ // declaration, which would preserve their visibility. However, many existing
321
+ // tests rely on the fact that current implementation reexports protected
322
+ // constructors as public. These tests would need to be cleaned up first.
323
+
324
+ // Single argument constructor is special-cased so that it can be
325
+ // made explicit.
326
+ template <typename A>
327
+ explicit StrictMock(A&& arg) : MockClass(std::forward<A>(arg)) {
277
328
  ::testing::Mock::FailUninterestingCalls(
278
329
  internal::ImplicitCast_<MockClass*>(this));
279
330
  }
280
331
 
281
- // C++ doesn't (yet) allow inheritance of constructors, so we have
282
- // to define it for each arity.
332
+ template <typename A1, typename A2, typename... An>
333
+ StrictMock(A1&& arg1, A2&& arg2, An&&... args)
334
+ : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
335
+ std::forward<An>(args)...) {
336
+ ::testing::Mock::FailUninterestingCalls(
337
+ internal::ImplicitCast_<MockClass*>(this));
338
+ }
339
+ #else
340
+ // C++98 doesn't have variadic templates, so we have to define one
341
+ // for each arity.
283
342
  template <typename A1>
284
343
  explicit StrictMock(const A1& a1) : MockClass(a1) {
285
344
  ::testing::Mock::FailUninterestingCalls(
@@ -355,7 +414,9 @@ class StrictMock : public MockClass {
355
414
  internal::ImplicitCast_<MockClass*>(this));
356
415
  }
357
416
 
358
- virtual ~StrictMock() {
417
+ #endif // GTEST_LANG_CXX11
418
+
419
+ ~StrictMock() {
359
420
  ::testing::Mock::UnregisterCallReaction(
360
421
  internal::ImplicitCast_<MockClass*>(this));
361
422
  }
@@ -1,6 +1,6 @@
1
1
  $$ -*- mode: c++; -*-
2
- $$ This is a Pump source file. Please use Pump to convert it to
3
- $$ gmock-generated-nice-strict.h.
2
+ $$ This is a Pump source file. Please use Pump to convert
3
+ $$ it to gmock-generated-nice-strict.h.
4
4
  $$
5
5
  $var n = 10 $$ The maximum arity we support.
6
6
  // Copyright 2008, Google Inc.
@@ -52,10 +52,9 @@ $var n = 10 $$ The maximum arity we support.
52
52
  // NiceMock<MockFoo>.
53
53
  //
54
54
  // NiceMock, NaggyMock, and StrictMock "inherit" the constructors of
55
- // their respective base class, with up-to $n arguments. Therefore
56
- // you can write NiceMock<MockFoo>(5, "a") to construct a nice mock
57
- // where MockFoo has a constructor that accepts (int, const char*),
58
- // for example.
55
+ // their respective base class. Therefore you can write
56
+ // NiceMock<MockFoo>(5, "a") to construct a nice mock where MockFoo
57
+ // has a constructor that accepts (int, const char*), for example.
59
58
  //
60
59
  // A known limitation is that NiceMock<MockFoo>, NaggyMock<MockFoo>,
61
60
  // and StrictMock<MockFoo> only works for mock methods defined using
@@ -64,10 +63,6 @@ $var n = 10 $$ The maximum arity we support.
64
63
  // or "strict" modifier may not affect it, depending on the compiler.
65
64
  // In particular, nesting NiceMock, NaggyMock, and StrictMock is NOT
66
65
  // supported.
67
- //
68
- // Another known limitation is that the constructors of the base mock
69
- // cannot have arguments passed by non-const reference, which are
70
- // banned by the Google C++ style guide anyway.
71
66
 
72
67
  #ifndef GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
73
68
  #define GMOCK_INCLUDE_GMOCK_GMOCK_GENERATED_NICE_STRICT_H_
@@ -91,15 +86,35 @@ $var method=[[$if kind==0 [[AllowUninterestingCalls]]
91
86
  template <class MockClass>
92
87
  class $clazz : public MockClass {
93
88
  public:
94
- // We don't factor out the constructor body to a common method, as
95
- // we have to avoid a possible clash with members of MockClass.
96
- $clazz() {
89
+ $clazz() : MockClass() {
90
+ ::testing::Mock::$method(
91
+ internal::ImplicitCast_<MockClass*>(this));
92
+ }
93
+
94
+ #if GTEST_LANG_CXX11
95
+ // Ideally, we would inherit base class's constructors through a using
96
+ // declaration, which would preserve their visibility. However, many existing
97
+ // tests rely on the fact that current implementation reexports protected
98
+ // constructors as public. These tests would need to be cleaned up first.
99
+
100
+ // Single argument constructor is special-cased so that it can be
101
+ // made explicit.
102
+ template <typename A>
103
+ explicit $clazz(A&& arg) : MockClass(std::forward<A>(arg)) {
97
104
  ::testing::Mock::$method(
98
105
  internal::ImplicitCast_<MockClass*>(this));
99
106
  }
100
107
 
101
- // C++ doesn't (yet) allow inheritance of constructors, so we have
102
- // to define it for each arity.
108
+ template <typename A1, typename A2, typename... An>
109
+ $clazz(A1&& arg1, A2&& arg2, An&&... args)
110
+ : MockClass(std::forward<A1>(arg1), std::forward<A2>(arg2),
111
+ std::forward<An>(args)...) {
112
+ ::testing::Mock::$method(
113
+ internal::ImplicitCast_<MockClass*>(this));
114
+ }
115
+ #else
116
+ // C++98 doesn't have variadic templates, so we have to define one
117
+ // for each arity.
103
118
  template <typename A1>
104
119
  explicit $clazz(const A1& a1) : MockClass(a1) {
105
120
  ::testing::Mock::$method(
@@ -117,7 +132,9 @@ $range j 1..i
117
132
 
118
133
 
119
134
  ]]
120
- virtual ~$clazz() {
135
+ #endif // GTEST_LANG_CXX11
136
+
137
+ ~$clazz() {
121
138
  ::testing::Mock::UnregisterCallReaction(
122
139
  internal::ImplicitCast_<MockClass*>(this));
123
140
  }
@@ -47,10 +47,9 @@
47
47
  #include <string>
48
48
  #include <utility>
49
49
  #include <vector>
50
-
50
+ #include "gtest/gtest.h"
51
51
  #include "gmock/internal/gmock-internal-utils.h"
52
52
  #include "gmock/internal/gmock-port.h"
53
- #include "gtest/gtest.h"
54
53
 
55
54
  #if GTEST_HAS_STD_INITIALIZER_LIST_
56
55
  # include <initializer_list> // NOLINT -- must be after gtest.h
@@ -180,13 +179,42 @@ class MatcherInterface : public MatcherDescriberInterface {
180
179
  // virtual void DescribeNegationTo(::std::ostream* os) const;
181
180
  };
182
181
 
182
+ namespace internal {
183
+
184
+ // Converts a MatcherInterface<T> to a MatcherInterface<const T&>.
185
+ template <typename T>
186
+ class MatcherInterfaceAdapter : public MatcherInterface<const T&> {
187
+ public:
188
+ explicit MatcherInterfaceAdapter(const MatcherInterface<T>* impl)
189
+ : impl_(impl) {}
190
+ virtual ~MatcherInterfaceAdapter() { delete impl_; }
191
+
192
+ virtual void DescribeTo(::std::ostream* os) const { impl_->DescribeTo(os); }
193
+
194
+ virtual void DescribeNegationTo(::std::ostream* os) const {
195
+ impl_->DescribeNegationTo(os);
196
+ }
197
+
198
+ virtual bool MatchAndExplain(const T& x,
199
+ MatchResultListener* listener) const {
200
+ return impl_->MatchAndExplain(x, listener);
201
+ }
202
+
203
+ private:
204
+ const MatcherInterface<T>* const impl_;
205
+
206
+ GTEST_DISALLOW_COPY_AND_ASSIGN_(MatcherInterfaceAdapter);
207
+ };
208
+
209
+ } // namespace internal
210
+
183
211
  // A match result listener that stores the explanation in a string.
184
212
  class StringMatchResultListener : public MatchResultListener {
185
213
  public:
186
214
  StringMatchResultListener() : MatchResultListener(&ss_) {}
187
215
 
188
216
  // Returns the explanation accumulated so far.
189
- internal::string str() const { return ss_.str(); }
217
+ std::string str() const { return ss_.str(); }
190
218
 
191
219
  // Clears the explanation accumulated so far.
192
220
  void Clear() { ss_.str(""); }
@@ -253,12 +281,13 @@ class MatcherBase {
253
281
  public:
254
282
  // Returns true iff the matcher matches x; also explains the match
255
283
  // result to 'listener'.
256
- bool MatchAndExplain(T x, MatchResultListener* listener) const {
284
+ bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
285
+ MatchResultListener* listener) const {
257
286
  return impl_->MatchAndExplain(x, listener);
258
287
  }
259
288
 
260
289
  // Returns true iff this matcher matches x.
261
- bool Matches(T x) const {
290
+ bool Matches(GTEST_REFERENCE_TO_CONST_(T) x) const {
262
291
  DummyMatchResultListener dummy;
263
292
  return MatchAndExplain(x, &dummy);
264
293
  }
@@ -272,7 +301,8 @@ class MatcherBase {
272
301
  }
273
302
 
274
303
  // Explains why x matches, or doesn't match, the matcher.
275
- void ExplainMatchResultTo(T x, ::std::ostream* os) const {
304
+ void ExplainMatchResultTo(GTEST_REFERENCE_TO_CONST_(T) x,
305
+ ::std::ostream* os) const {
276
306
  StreamMatchResultListener listener(os);
277
307
  MatchAndExplain(x, &listener);
278
308
  }
@@ -288,9 +318,18 @@ class MatcherBase {
288
318
  MatcherBase() {}
289
319
 
290
320
  // Constructs a matcher from its implementation.
291
- explicit MatcherBase(const MatcherInterface<T>* impl)
321
+ explicit MatcherBase(
322
+ const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl)
292
323
  : impl_(impl) {}
293
324
 
325
+ template <typename U>
326
+ explicit MatcherBase(
327
+ const MatcherInterface<U>* impl,
328
+ typename internal::EnableIf<
329
+ !internal::IsSame<U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* =
330
+ NULL)
331
+ : impl_(new internal::MatcherInterfaceAdapter<U>(impl)) {}
332
+
294
333
  virtual ~MatcherBase() {}
295
334
 
296
335
  private:
@@ -305,7 +344,9 @@ class MatcherBase {
305
344
  //
306
345
  // If performance becomes a problem, we should see if using
307
346
  // shared_ptr helps.
308
- ::testing::internal::linked_ptr<const MatcherInterface<T> > impl_;
347
+ ::testing::internal::linked_ptr<
348
+ const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> >
349
+ impl_;
309
350
  };
310
351
 
311
352
  } // namespace internal
@@ -324,7 +365,13 @@ class Matcher : public internal::MatcherBase<T> {
324
365
  explicit Matcher() {} // NOLINT
325
366
 
326
367
  // Constructs a matcher from its implementation.
327
- explicit Matcher(const MatcherInterface<T>* impl)
368
+ explicit Matcher(const MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)>* impl)
369
+ : internal::MatcherBase<T>(impl) {}
370
+
371
+ template <typename U>
372
+ explicit Matcher(const MatcherInterface<U>* impl,
373
+ typename internal::EnableIf<!internal::IsSame<
374
+ U, GTEST_REFERENCE_TO_CONST_(U)>::value>::type* = NULL)
328
375
  : internal::MatcherBase<T>(impl) {}
329
376
 
330
377
  // Implicit constructor here allows people to write
@@ -333,86 +380,170 @@ class Matcher : public internal::MatcherBase<T> {
333
380
  };
334
381
 
335
382
  // The following two specializations allow the user to write str
336
- // instead of Eq(str) and "foo" instead of Eq("foo") when a string
383
+ // instead of Eq(str) and "foo" instead of Eq("foo") when a std::string
337
384
  // matcher is expected.
338
385
  template <>
339
- class GTEST_API_ Matcher<const internal::string&>
340
- : public internal::MatcherBase<const internal::string&> {
386
+ class GTEST_API_ Matcher<const std::string&>
387
+ : public internal::MatcherBase<const std::string&> {
341
388
  public:
342
389
  Matcher() {}
343
390
 
344
- explicit Matcher(const MatcherInterface<const internal::string&>* impl)
345
- : internal::MatcherBase<const internal::string&>(impl) {}
391
+ explicit Matcher(const MatcherInterface<const std::string&>* impl)
392
+ : internal::MatcherBase<const std::string&>(impl) {}
346
393
 
347
394
  // Allows the user to write str instead of Eq(str) sometimes, where
348
- // str is a string object.
349
- Matcher(const internal::string& s); // NOLINT
395
+ // str is a std::string object.
396
+ Matcher(const std::string& s); // NOLINT
397
+
398
+ #if GTEST_HAS_GLOBAL_STRING
399
+ // Allows the user to write str instead of Eq(str) sometimes, where
400
+ // str is a ::string object.
401
+ Matcher(const ::string& s); // NOLINT
402
+ #endif // GTEST_HAS_GLOBAL_STRING
350
403
 
351
404
  // Allows the user to write "foo" instead of Eq("foo") sometimes.
352
405
  Matcher(const char* s); // NOLINT
353
406
  };
354
407
 
355
408
  template <>
356
- class GTEST_API_ Matcher<internal::string>
357
- : public internal::MatcherBase<internal::string> {
409
+ class GTEST_API_ Matcher<std::string>
410
+ : public internal::MatcherBase<std::string> {
358
411
  public:
359
412
  Matcher() {}
360
413
 
361
- explicit Matcher(const MatcherInterface<internal::string>* impl)
362
- : internal::MatcherBase<internal::string>(impl) {}
414
+ explicit Matcher(const MatcherInterface<const std::string&>* impl)
415
+ : internal::MatcherBase<std::string>(impl) {}
416
+ explicit Matcher(const MatcherInterface<std::string>* impl)
417
+ : internal::MatcherBase<std::string>(impl) {}
363
418
 
364
419
  // Allows the user to write str instead of Eq(str) sometimes, where
365
420
  // str is a string object.
366
- Matcher(const internal::string& s); // NOLINT
421
+ Matcher(const std::string& s); // NOLINT
422
+
423
+ #if GTEST_HAS_GLOBAL_STRING
424
+ // Allows the user to write str instead of Eq(str) sometimes, where
425
+ // str is a ::string object.
426
+ Matcher(const ::string& s); // NOLINT
427
+ #endif // GTEST_HAS_GLOBAL_STRING
367
428
 
368
429
  // Allows the user to write "foo" instead of Eq("foo") sometimes.
369
430
  Matcher(const char* s); // NOLINT
370
431
  };
371
432
 
372
- #if GTEST_HAS_STRING_PIECE_
433
+ #if GTEST_HAS_GLOBAL_STRING
373
434
  // The following two specializations allow the user to write str
374
- // instead of Eq(str) and "foo" instead of Eq("foo") when a StringPiece
435
+ // instead of Eq(str) and "foo" instead of Eq("foo") when a ::string
375
436
  // matcher is expected.
376
437
  template <>
377
- class GTEST_API_ Matcher<const StringPiece&>
378
- : public internal::MatcherBase<const StringPiece&> {
438
+ class GTEST_API_ Matcher<const ::string&>
439
+ : public internal::MatcherBase<const ::string&> {
379
440
  public:
380
441
  Matcher() {}
381
442
 
382
- explicit Matcher(const MatcherInterface<const StringPiece&>* impl)
383
- : internal::MatcherBase<const StringPiece&>(impl) {}
443
+ explicit Matcher(const MatcherInterface<const ::string&>* impl)
444
+ : internal::MatcherBase<const ::string&>(impl) {}
384
445
 
385
446
  // Allows the user to write str instead of Eq(str) sometimes, where
386
- // str is a string object.
387
- Matcher(const internal::string& s); // NOLINT
447
+ // str is a std::string object.
448
+ Matcher(const std::string& s); // NOLINT
449
+
450
+ // Allows the user to write str instead of Eq(str) sometimes, where
451
+ // str is a ::string object.
452
+ Matcher(const ::string& s); // NOLINT
388
453
 
389
454
  // Allows the user to write "foo" instead of Eq("foo") sometimes.
390
455
  Matcher(const char* s); // NOLINT
456
+ };
457
+
458
+ template <>
459
+ class GTEST_API_ Matcher< ::string>
460
+ : public internal::MatcherBase< ::string> {
461
+ public:
462
+ Matcher() {}
463
+
464
+ explicit Matcher(const MatcherInterface<const ::string&>* impl)
465
+ : internal::MatcherBase< ::string>(impl) {}
466
+ explicit Matcher(const MatcherInterface< ::string>* impl)
467
+ : internal::MatcherBase< ::string>(impl) {}
468
+
469
+ // Allows the user to write str instead of Eq(str) sometimes, where
470
+ // str is a std::string object.
471
+ Matcher(const std::string& s); // NOLINT
391
472
 
392
- // Allows the user to pass StringPieces directly.
393
- Matcher(StringPiece s); // NOLINT
473
+ // Allows the user to write str instead of Eq(str) sometimes, where
474
+ // str is a ::string object.
475
+ Matcher(const ::string& s); // NOLINT
476
+
477
+ // Allows the user to write "foo" instead of Eq("foo") sometimes.
478
+ Matcher(const char* s); // NOLINT
394
479
  };
480
+ #endif // GTEST_HAS_GLOBAL_STRING
395
481
 
482
+ #if GTEST_HAS_ABSL
483
+ // The following two specializations allow the user to write str
484
+ // instead of Eq(str) and "foo" instead of Eq("foo") when a absl::string_view
485
+ // matcher is expected.
396
486
  template <>
397
- class GTEST_API_ Matcher<StringPiece>
398
- : public internal::MatcherBase<StringPiece> {
487
+ class GTEST_API_ Matcher<const absl::string_view&>
488
+ : public internal::MatcherBase<const absl::string_view&> {
399
489
  public:
400
490
  Matcher() {}
401
491
 
402
- explicit Matcher(const MatcherInterface<StringPiece>* impl)
403
- : internal::MatcherBase<StringPiece>(impl) {}
492
+ explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
493
+ : internal::MatcherBase<const absl::string_view&>(impl) {}
404
494
 
405
495
  // Allows the user to write str instead of Eq(str) sometimes, where
406
- // str is a string object.
407
- Matcher(const internal::string& s); // NOLINT
496
+ // str is a std::string object.
497
+ Matcher(const std::string& s); // NOLINT
498
+
499
+ #if GTEST_HAS_GLOBAL_STRING
500
+ // Allows the user to write str instead of Eq(str) sometimes, where
501
+ // str is a ::string object.
502
+ Matcher(const ::string& s); // NOLINT
503
+ #endif // GTEST_HAS_GLOBAL_STRING
408
504
 
409
505
  // Allows the user to write "foo" instead of Eq("foo") sometimes.
410
506
  Matcher(const char* s); // NOLINT
411
507
 
412
- // Allows the user to pass StringPieces directly.
413
- Matcher(StringPiece s); // NOLINT
508
+ // Allows the user to pass absl::string_views directly.
509
+ Matcher(absl::string_view s); // NOLINT
414
510
  };
415
- #endif // GTEST_HAS_STRING_PIECE_
511
+
512
+ template <>
513
+ class GTEST_API_ Matcher<absl::string_view>
514
+ : public internal::MatcherBase<absl::string_view> {
515
+ public:
516
+ Matcher() {}
517
+
518
+ explicit Matcher(const MatcherInterface<const absl::string_view&>* impl)
519
+ : internal::MatcherBase<absl::string_view>(impl) {}
520
+ explicit Matcher(const MatcherInterface<absl::string_view>* impl)
521
+ : internal::MatcherBase<absl::string_view>(impl) {}
522
+
523
+ // Allows the user to write str instead of Eq(str) sometimes, where
524
+ // str is a std::string object.
525
+ Matcher(const std::string& s); // NOLINT
526
+
527
+ #if GTEST_HAS_GLOBAL_STRING
528
+ // Allows the user to write str instead of Eq(str) sometimes, where
529
+ // str is a ::string object.
530
+ Matcher(const ::string& s); // NOLINT
531
+ #endif // GTEST_HAS_GLOBAL_STRING
532
+
533
+ // Allows the user to write "foo" instead of Eq("foo") sometimes.
534
+ Matcher(const char* s); // NOLINT
535
+
536
+ // Allows the user to pass absl::string_views directly.
537
+ Matcher(absl::string_view s); // NOLINT
538
+ };
539
+ #endif // GTEST_HAS_ABSL
540
+
541
+ // Prints a matcher in a human-readable format.
542
+ template <typename T>
543
+ std::ostream& operator<<(std::ostream& os, const Matcher<T>& matcher) {
544
+ matcher.DescribeTo(&os);
545
+ return os;
546
+ }
416
547
 
417
548
  // The PolymorphicMatcher class template makes it easy to implement a
418
549
  // polymorphic matcher (i.e. a matcher that can match values of more
@@ -441,7 +572,7 @@ class PolymorphicMatcher {
441
572
 
442
573
  template <typename T>
443
574
  operator Matcher<T>() const {
444
- return Matcher<T>(new MonomorphicImpl<T>(impl_));
575
+ return Matcher<T>(new MonomorphicImpl<GTEST_REFERENCE_TO_CONST_(T)>(impl_));
445
576
  }
446
577
 
447
578
  private:
@@ -515,7 +646,7 @@ template <typename T, typename M>
515
646
  class MatcherCastImpl {
516
647
  public:
517
648
  static Matcher<T> Cast(const M& polymorphic_matcher_or_value) {
518
- // M can be a polymorhic matcher, in which case we want to use
649
+ // M can be a polymorphic matcher, in which case we want to use
519
650
  // its conversion operator to create Matcher<T>. Or it can be a value
520
651
  // that should be passed to the Matcher<T>'s constructor.
521
652
  //
@@ -531,21 +662,18 @@ class MatcherCastImpl {
531
662
  return CastImpl(
532
663
  polymorphic_matcher_or_value,
533
664
  BooleanConstant<
534
- internal::ImplicitlyConvertible<M, Matcher<T> >::value>());
665
+ internal::ImplicitlyConvertible<M, Matcher<T> >::value>(),
666
+ BooleanConstant<
667
+ internal::ImplicitlyConvertible<M, T>::value>());
535
668
  }
536
669
 
537
670
  private:
538
- static Matcher<T> CastImpl(const M& value, BooleanConstant<false>) {
539
- // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
540
- // matcher. It must be a value then. Use direct initialization to create
541
- // a matcher.
542
- return Matcher<T>(ImplicitCast_<T>(value));
543
- }
544
-
671
+ template <bool Ignore>
545
672
  static Matcher<T> CastImpl(const M& polymorphic_matcher_or_value,
546
- BooleanConstant<true>) {
673
+ BooleanConstant<true> /* convertible_to_matcher */,
674
+ BooleanConstant<Ignore>) {
547
675
  // M is implicitly convertible to Matcher<T>, which means that either
548
- // M is a polymorhpic matcher or Matcher<T> has an implicit constructor
676
+ // M is a polymorphic matcher or Matcher<T> has an implicit constructor
549
677
  // from M. In both cases using the implicit conversion will produce a
550
678
  // matcher.
551
679
  //
@@ -554,6 +682,29 @@ class MatcherCastImpl {
554
682
  // (first to create T from M and then to create Matcher<T> from T).
555
683
  return polymorphic_matcher_or_value;
556
684
  }
685
+
686
+ // M can't be implicitly converted to Matcher<T>, so M isn't a polymorphic
687
+ // matcher. It's a value of a type implicitly convertible to T. Use direct
688
+ // initialization to create a matcher.
689
+ static Matcher<T> CastImpl(
690
+ const M& value, BooleanConstant<false> /* convertible_to_matcher */,
691
+ BooleanConstant<true> /* convertible_to_T */) {
692
+ return Matcher<T>(ImplicitCast_<T>(value));
693
+ }
694
+
695
+ // M can't be implicitly converted to either Matcher<T> or T. Attempt to use
696
+ // polymorphic matcher Eq(value) in this case.
697
+ //
698
+ // Note that we first attempt to perform an implicit cast on the value and
699
+ // only fall back to the polymorphic Eq() matcher afterwards because the
700
+ // latter calls bool operator==(const Lhs& lhs, const Rhs& rhs) in the end
701
+ // which might be undefined even when Rhs is implicitly convertible to Lhs
702
+ // (e.g. std::pair<const int, int> vs. std::pair<int, int>).
703
+ //
704
+ // We don't define this method inline as we need the declaration of Eq().
705
+ static Matcher<T> CastImpl(
706
+ const M& value, BooleanConstant<false> /* convertible_to_matcher */,
707
+ BooleanConstant<false> /* convertible_to_T */);
557
708
  };
558
709
 
559
710
  // This more specialized version is used when MatcherCast()'s argument
@@ -574,6 +725,22 @@ class MatcherCastImpl<T, Matcher<U> > {
574
725
 
575
726
  // We delegate the matching logic to the source matcher.
576
727
  virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
728
+ #if GTEST_LANG_CXX11
729
+ using FromType = typename std::remove_cv<typename std::remove_pointer<
730
+ typename std::remove_reference<T>::type>::type>::type;
731
+ using ToType = typename std::remove_cv<typename std::remove_pointer<
732
+ typename std::remove_reference<U>::type>::type>::type;
733
+ // Do not allow implicitly converting base*/& to derived*/&.
734
+ static_assert(
735
+ // Do not trigger if only one of them is a pointer. That implies a
736
+ // regular conversion and not a down_cast.
737
+ (std::is_pointer<typename std::remove_reference<T>::type>::value !=
738
+ std::is_pointer<typename std::remove_reference<U>::type>::value) ||
739
+ std::is_same<FromType, ToType>::value ||
740
+ !std::is_base_of<FromType, ToType>::value,
741
+ "Can't implicitly convert from <base> to <derived>");
742
+ #endif // GTEST_LANG_CXX11
743
+
577
744
  return source_matcher_.MatchAndExplain(static_cast<U>(x), listener);
578
745
  }
579
746
 
@@ -646,7 +813,7 @@ class SafeMatcherCastImpl {
646
813
  // type U.
647
814
  GTEST_COMPILE_ASSERT_(
648
815
  internal::is_reference<T>::value || !internal::is_reference<U>::value,
649
- cannot_convert_non_referentce_arg_to_reference);
816
+ cannot_convert_non_reference_arg_to_reference);
650
817
  // In case both T and U are arithmetic types, enforce that the
651
818
  // conversion is not lossy.
652
819
  typedef GTEST_REMOVE_REFERENCE_AND_CONST_(T) RawT;
@@ -675,7 +842,7 @@ Matcher<T> A();
675
842
  namespace internal {
676
843
 
677
844
  // If the explanation is not empty, prints it to the ostream.
678
- inline void PrintIfNotEmpty(const internal::string& explanation,
845
+ inline void PrintIfNotEmpty(const std::string& explanation,
679
846
  ::std::ostream* os) {
680
847
  if (explanation != "" && os != NULL) {
681
848
  *os << ", " << explanation;
@@ -685,11 +852,11 @@ inline void PrintIfNotEmpty(const internal::string& explanation,
685
852
  // Returns true if the given type name is easy to read by a human.
686
853
  // This is used to decide whether printing the type of a value might
687
854
  // be helpful.
688
- inline bool IsReadableTypeName(const string& type_name) {
855
+ inline bool IsReadableTypeName(const std::string& type_name) {
689
856
  // We consider a type name readable if it's short or doesn't contain
690
857
  // a template or function type.
691
858
  return (type_name.length() <= 20 ||
692
- type_name.find_first_of("<(") == string::npos);
859
+ type_name.find_first_of("<(") == std::string::npos);
693
860
  }
694
861
 
695
862
  // Matches the value against the given matcher, prints the value and explains
@@ -711,7 +878,7 @@ bool MatchPrintAndExplain(Value& value, const Matcher<T>& matcher,
711
878
 
712
879
  UniversalPrint(value, listener->stream());
713
880
  #if GTEST_HAS_RTTI
714
- const string& type_name = GetTypeName<Value>();
881
+ const std::string& type_name = GetTypeName<Value>();
715
882
  if (IsReadableTypeName(type_name))
716
883
  *listener->stream() << " (of type " << type_name << ")";
717
884
  #endif
@@ -751,7 +918,7 @@ class TuplePrefix {
751
918
  typename tuple_element<N - 1, MatcherTuple>::type matcher =
752
919
  get<N - 1>(matchers);
753
920
  typedef typename tuple_element<N - 1, ValueTuple>::type Value;
754
- Value value = get<N - 1>(values);
921
+ GTEST_REFERENCE_TO_CONST_(Value) value = get<N - 1>(values);
755
922
  StringMatchResultListener listener;
756
923
  if (!matcher.MatchAndExplain(value, &listener)) {
757
924
  // TODO(wan): include in the message the name of the parameter
@@ -856,10 +1023,12 @@ OutIter TransformTupleValues(Func f, const Tuple& t, OutIter out) {
856
1023
 
857
1024
  // Implements A<T>().
858
1025
  template <typename T>
859
- class AnyMatcherImpl : public MatcherInterface<T> {
1026
+ class AnyMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
860
1027
  public:
861
- virtual bool MatchAndExplain(
862
- T /* x */, MatchResultListener* /* listener */) const { return true; }
1028
+ virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) /* x */,
1029
+ MatchResultListener* /* listener */) const {
1030
+ return true;
1031
+ }
863
1032
  virtual void DescribeTo(::std::ostream* os) const { *os << "is anything"; }
864
1033
  virtual void DescribeNegationTo(::std::ostream* os) const {
865
1034
  // This is mostly for completeness' safe, as it's not very useful
@@ -1129,6 +1298,19 @@ class StrEqualityMatcher {
1129
1298
  bool case_sensitive)
1130
1299
  : string_(str), expect_eq_(expect_eq), case_sensitive_(case_sensitive) {}
1131
1300
 
1301
+ #if GTEST_HAS_ABSL
1302
+ bool MatchAndExplain(const absl::string_view& s,
1303
+ MatchResultListener* listener) const {
1304
+ if (s.data() == NULL) {
1305
+ return !expect_eq_;
1306
+ }
1307
+ // This should fail to compile if absl::string_view is used with wide
1308
+ // strings.
1309
+ const StringType& str = string(s);
1310
+ return MatchAndExplain(str, listener);
1311
+ }
1312
+ #endif // GTEST_HAS_ABSL
1313
+
1132
1314
  // Accepts pointer types, particularly:
1133
1315
  // const char*
1134
1316
  // char*
@@ -1145,7 +1327,7 @@ class StrEqualityMatcher {
1145
1327
  // Matches anything that can convert to StringType.
1146
1328
  //
1147
1329
  // This is a template, not just a plain function with const StringType&,
1148
- // because StringPiece has some interfering non-explicit constructors.
1330
+ // because absl::string_view has some interfering non-explicit constructors.
1149
1331
  template <typename MatcheeStringType>
1150
1332
  bool MatchAndExplain(const MatcheeStringType& s,
1151
1333
  MatchResultListener* /* listener */) const {
@@ -1189,6 +1371,19 @@ class HasSubstrMatcher {
1189
1371
  explicit HasSubstrMatcher(const StringType& substring)
1190
1372
  : substring_(substring) {}
1191
1373
 
1374
+ #if GTEST_HAS_ABSL
1375
+ bool MatchAndExplain(const absl::string_view& s,
1376
+ MatchResultListener* listener) const {
1377
+ if (s.data() == NULL) {
1378
+ return false;
1379
+ }
1380
+ // This should fail to compile if absl::string_view is used with wide
1381
+ // strings.
1382
+ const StringType& str = string(s);
1383
+ return MatchAndExplain(str, listener);
1384
+ }
1385
+ #endif // GTEST_HAS_ABSL
1386
+
1192
1387
  // Accepts pointer types, particularly:
1193
1388
  // const char*
1194
1389
  // char*
@@ -1202,7 +1397,7 @@ class HasSubstrMatcher {
1202
1397
  // Matches anything that can convert to StringType.
1203
1398
  //
1204
1399
  // This is a template, not just a plain function with const StringType&,
1205
- // because StringPiece has some interfering non-explicit constructors.
1400
+ // because absl::string_view has some interfering non-explicit constructors.
1206
1401
  template <typename MatcheeStringType>
1207
1402
  bool MatchAndExplain(const MatcheeStringType& s,
1208
1403
  MatchResultListener* /* listener */) const {
@@ -1236,6 +1431,19 @@ class StartsWithMatcher {
1236
1431
  explicit StartsWithMatcher(const StringType& prefix) : prefix_(prefix) {
1237
1432
  }
1238
1433
 
1434
+ #if GTEST_HAS_ABSL
1435
+ bool MatchAndExplain(const absl::string_view& s,
1436
+ MatchResultListener* listener) const {
1437
+ if (s.data() == NULL) {
1438
+ return false;
1439
+ }
1440
+ // This should fail to compile if absl::string_view is used with wide
1441
+ // strings.
1442
+ const StringType& str = string(s);
1443
+ return MatchAndExplain(str, listener);
1444
+ }
1445
+ #endif // GTEST_HAS_ABSL
1446
+
1239
1447
  // Accepts pointer types, particularly:
1240
1448
  // const char*
1241
1449
  // char*
@@ -1249,7 +1457,7 @@ class StartsWithMatcher {
1249
1457
  // Matches anything that can convert to StringType.
1250
1458
  //
1251
1459
  // This is a template, not just a plain function with const StringType&,
1252
- // because StringPiece has some interfering non-explicit constructors.
1460
+ // because absl::string_view has some interfering non-explicit constructors.
1253
1461
  template <typename MatcheeStringType>
1254
1462
  bool MatchAndExplain(const MatcheeStringType& s,
1255
1463
  MatchResultListener* /* listener */) const {
@@ -1282,6 +1490,19 @@ class EndsWithMatcher {
1282
1490
  public:
1283
1491
  explicit EndsWithMatcher(const StringType& suffix) : suffix_(suffix) {}
1284
1492
 
1493
+ #if GTEST_HAS_ABSL
1494
+ bool MatchAndExplain(const absl::string_view& s,
1495
+ MatchResultListener* listener) const {
1496
+ if (s.data() == NULL) {
1497
+ return false;
1498
+ }
1499
+ // This should fail to compile if absl::string_view is used with wide
1500
+ // strings.
1501
+ const StringType& str = string(s);
1502
+ return MatchAndExplain(str, listener);
1503
+ }
1504
+ #endif // GTEST_HAS_ABSL
1505
+
1285
1506
  // Accepts pointer types, particularly:
1286
1507
  // const char*
1287
1508
  // char*
@@ -1295,7 +1516,7 @@ class EndsWithMatcher {
1295
1516
  // Matches anything that can convert to StringType.
1296
1517
  //
1297
1518
  // This is a template, not just a plain function with const StringType&,
1298
- // because StringPiece has some interfering non-explicit constructors.
1519
+ // because absl::string_view has some interfering non-explicit constructors.
1299
1520
  template <typename MatcheeStringType>
1300
1521
  bool MatchAndExplain(const MatcheeStringType& s,
1301
1522
  MatchResultListener* /* listener */) const {
@@ -1328,6 +1549,13 @@ class MatchesRegexMatcher {
1328
1549
  MatchesRegexMatcher(const RE* regex, bool full_match)
1329
1550
  : regex_(regex), full_match_(full_match) {}
1330
1551
 
1552
+ #if GTEST_HAS_ABSL
1553
+ bool MatchAndExplain(const absl::string_view& s,
1554
+ MatchResultListener* listener) const {
1555
+ return s.data() && MatchAndExplain(string(s), listener);
1556
+ }
1557
+ #endif // GTEST_HAS_ABSL
1558
+
1331
1559
  // Accepts pointer types, particularly:
1332
1560
  // const char*
1333
1561
  // char*
@@ -1335,17 +1563,17 @@ class MatchesRegexMatcher {
1335
1563
  // wchar_t*
1336
1564
  template <typename CharType>
1337
1565
  bool MatchAndExplain(CharType* s, MatchResultListener* listener) const {
1338
- return s != NULL && MatchAndExplain(internal::string(s), listener);
1566
+ return s != NULL && MatchAndExplain(std::string(s), listener);
1339
1567
  }
1340
1568
 
1341
- // Matches anything that can convert to internal::string.
1569
+ // Matches anything that can convert to std::string.
1342
1570
  //
1343
- // This is a template, not just a plain function with const internal::string&,
1344
- // because StringPiece has some interfering non-explicit constructors.
1571
+ // This is a template, not just a plain function with const std::string&,
1572
+ // because absl::string_view has some interfering non-explicit constructors.
1345
1573
  template <class MatcheeStringType>
1346
1574
  bool MatchAndExplain(const MatcheeStringType& s,
1347
1575
  MatchResultListener* /* listener */) const {
1348
- const internal::string& s2(s);
1576
+ const std::string& s2(s);
1349
1577
  return full_match_ ? RE::FullMatch(s2, *regex_) :
1350
1578
  RE::PartialMatch(s2, *regex_);
1351
1579
  }
@@ -1353,13 +1581,13 @@ class MatchesRegexMatcher {
1353
1581
  void DescribeTo(::std::ostream* os) const {
1354
1582
  *os << (full_match_ ? "matches" : "contains")
1355
1583
  << " regular expression ";
1356
- UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
1584
+ UniversalPrinter<std::string>::Print(regex_->pattern(), os);
1357
1585
  }
1358
1586
 
1359
1587
  void DescribeNegationTo(::std::ostream* os) const {
1360
1588
  *os << "doesn't " << (full_match_ ? "match" : "contain")
1361
1589
  << " regular expression ";
1362
- UniversalPrinter<internal::string>::Print(regex_->pattern(), os);
1590
+ UniversalPrinter<std::string>::Print(regex_->pattern(), os);
1363
1591
  }
1364
1592
 
1365
1593
  private:
@@ -1441,12 +1669,13 @@ class Ge2Matcher : public PairMatchBase<Ge2Matcher, AnyGe> {
1441
1669
  // will prevent different instantiations of NotMatcher from sharing
1442
1670
  // the same NotMatcherImpl<T> class.
1443
1671
  template <typename T>
1444
- class NotMatcherImpl : public MatcherInterface<T> {
1672
+ class NotMatcherImpl : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
1445
1673
  public:
1446
1674
  explicit NotMatcherImpl(const Matcher<T>& matcher)
1447
1675
  : matcher_(matcher) {}
1448
1676
 
1449
- virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
1677
+ virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
1678
+ MatchResultListener* listener) const {
1450
1679
  return !matcher_.MatchAndExplain(x, listener);
1451
1680
  }
1452
1681
 
@@ -1489,117 +1718,66 @@ class NotMatcher {
1489
1718
  // that will prevent different instantiations of BothOfMatcher from
1490
1719
  // sharing the same BothOfMatcherImpl<T> class.
1491
1720
  template <typename T>
1492
- class BothOfMatcherImpl : public MatcherInterface<T> {
1721
+ class AllOfMatcherImpl
1722
+ : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
1493
1723
  public:
1494
- BothOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
1495
- : matcher1_(matcher1), matcher2_(matcher2) {}
1724
+ explicit AllOfMatcherImpl(std::vector<Matcher<T> > matchers)
1725
+ : matchers_(internal::move(matchers)) {}
1496
1726
 
1497
1727
  virtual void DescribeTo(::std::ostream* os) const {
1498
1728
  *os << "(";
1499
- matcher1_.DescribeTo(os);
1500
- *os << ") and (";
1501
- matcher2_.DescribeTo(os);
1729
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1730
+ if (i != 0) *os << ") and (";
1731
+ matchers_[i].DescribeTo(os);
1732
+ }
1502
1733
  *os << ")";
1503
1734
  }
1504
1735
 
1505
1736
  virtual void DescribeNegationTo(::std::ostream* os) const {
1506
1737
  *os << "(";
1507
- matcher1_.DescribeNegationTo(os);
1508
- *os << ") or (";
1509
- matcher2_.DescribeNegationTo(os);
1738
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1739
+ if (i != 0) *os << ") or (";
1740
+ matchers_[i].DescribeNegationTo(os);
1741
+ }
1510
1742
  *os << ")";
1511
1743
  }
1512
1744
 
1513
- virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
1745
+ virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
1746
+ MatchResultListener* listener) const {
1514
1747
  // If either matcher1_ or matcher2_ doesn't match x, we only need
1515
1748
  // to explain why one of them fails.
1516
- StringMatchResultListener listener1;
1517
- if (!matcher1_.MatchAndExplain(x, &listener1)) {
1518
- *listener << listener1.str();
1519
- return false;
1520
- }
1749
+ std::string all_match_result;
1521
1750
 
1522
- StringMatchResultListener listener2;
1523
- if (!matcher2_.MatchAndExplain(x, &listener2)) {
1524
- *listener << listener2.str();
1525
- return false;
1751
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1752
+ StringMatchResultListener slistener;
1753
+ if (matchers_[i].MatchAndExplain(x, &slistener)) {
1754
+ if (all_match_result.empty()) {
1755
+ all_match_result = slistener.str();
1756
+ } else {
1757
+ std::string result = slistener.str();
1758
+ if (!result.empty()) {
1759
+ all_match_result += ", and ";
1760
+ all_match_result += result;
1761
+ }
1762
+ }
1763
+ } else {
1764
+ *listener << slistener.str();
1765
+ return false;
1766
+ }
1526
1767
  }
1527
1768
 
1528
1769
  // Otherwise we need to explain why *both* of them match.
1529
- const internal::string s1 = listener1.str();
1530
- const internal::string s2 = listener2.str();
1531
-
1532
- if (s1 == "") {
1533
- *listener << s2;
1534
- } else {
1535
- *listener << s1;
1536
- if (s2 != "") {
1537
- *listener << ", and " << s2;
1538
- }
1539
- }
1770
+ *listener << all_match_result;
1540
1771
  return true;
1541
1772
  }
1542
1773
 
1543
1774
  private:
1544
- const Matcher<T> matcher1_;
1545
- const Matcher<T> matcher2_;
1775
+ const std::vector<Matcher<T> > matchers_;
1546
1776
 
1547
- GTEST_DISALLOW_ASSIGN_(BothOfMatcherImpl);
1777
+ GTEST_DISALLOW_ASSIGN_(AllOfMatcherImpl);
1548
1778
  };
1549
1779
 
1550
1780
  #if GTEST_LANG_CXX11
1551
- // MatcherList provides mechanisms for storing a variable number of matchers in
1552
- // a list structure (ListType) and creating a combining matcher from such a
1553
- // list.
1554
- // The template is defined recursively using the following template paramters:
1555
- // * kSize is the length of the MatcherList.
1556
- // * Head is the type of the first matcher of the list.
1557
- // * Tail denotes the types of the remaining matchers of the list.
1558
- template <int kSize, typename Head, typename... Tail>
1559
- struct MatcherList {
1560
- typedef MatcherList<kSize - 1, Tail...> MatcherListTail;
1561
- typedef ::std::pair<Head, typename MatcherListTail::ListType> ListType;
1562
-
1563
- // BuildList stores variadic type values in a nested pair structure.
1564
- // Example:
1565
- // MatcherList<3, int, string, float>::BuildList(5, "foo", 2.0) will return
1566
- // the corresponding result of type pair<int, pair<string, float>>.
1567
- static ListType BuildList(const Head& matcher, const Tail&... tail) {
1568
- return ListType(matcher, MatcherListTail::BuildList(tail...));
1569
- }
1570
-
1571
- // CreateMatcher<T> creates a Matcher<T> from a given list of matchers (built
1572
- // by BuildList()). CombiningMatcher<T> is used to combine the matchers of the
1573
- // list. CombiningMatcher<T> must implement MatcherInterface<T> and have a
1574
- // constructor taking two Matcher<T>s as input.
1575
- template <typename T, template <typename /* T */> class CombiningMatcher>
1576
- static Matcher<T> CreateMatcher(const ListType& matchers) {
1577
- return Matcher<T>(new CombiningMatcher<T>(
1578
- SafeMatcherCast<T>(matchers.first),
1579
- MatcherListTail::template CreateMatcher<T, CombiningMatcher>(
1580
- matchers.second)));
1581
- }
1582
- };
1583
-
1584
- // The following defines the base case for the recursive definition of
1585
- // MatcherList.
1586
- template <typename Matcher1, typename Matcher2>
1587
- struct MatcherList<2, Matcher1, Matcher2> {
1588
- typedef ::std::pair<Matcher1, Matcher2> ListType;
1589
-
1590
- static ListType BuildList(const Matcher1& matcher1,
1591
- const Matcher2& matcher2) {
1592
- return ::std::pair<Matcher1, Matcher2>(matcher1, matcher2);
1593
- }
1594
-
1595
- template <typename T, template <typename /* T */> class CombiningMatcher>
1596
- static Matcher<T> CreateMatcher(const ListType& matchers) {
1597
- return Matcher<T>(new CombiningMatcher<T>(
1598
- SafeMatcherCast<T>(matchers.first),
1599
- SafeMatcherCast<T>(matchers.second)));
1600
- }
1601
- };
1602
-
1603
1781
  // VariadicMatcher is used for the variadic implementation of
1604
1782
  // AllOf(m_1, m_2, ...) and AnyOf(m_1, m_2, ...).
1605
1783
  // CombiningMatcher<T> is used to recursively combine the provided matchers
@@ -1608,27 +1786,40 @@ template <template <typename T> class CombiningMatcher, typename... Args>
1608
1786
  class VariadicMatcher {
1609
1787
  public:
1610
1788
  VariadicMatcher(const Args&... matchers) // NOLINT
1611
- : matchers_(MatcherListType::BuildList(matchers...)) {}
1789
+ : matchers_(matchers...) {
1790
+ static_assert(sizeof...(Args) > 0, "Must have at least one matcher.");
1791
+ }
1612
1792
 
1613
1793
  // This template type conversion operator allows an
1614
1794
  // VariadicMatcher<Matcher1, Matcher2...> object to match any type that
1615
1795
  // all of the provided matchers (Matcher1, Matcher2, ...) can match.
1616
1796
  template <typename T>
1617
1797
  operator Matcher<T>() const {
1618
- return MatcherListType::template CreateMatcher<T, CombiningMatcher>(
1619
- matchers_);
1798
+ std::vector<Matcher<T> > values;
1799
+ CreateVariadicMatcher<T>(&values, std::integral_constant<size_t, 0>());
1800
+ return Matcher<T>(new CombiningMatcher<T>(internal::move(values)));
1620
1801
  }
1621
1802
 
1622
1803
  private:
1623
- typedef MatcherList<sizeof...(Args), Args...> MatcherListType;
1804
+ template <typename T, size_t I>
1805
+ void CreateVariadicMatcher(std::vector<Matcher<T> >* values,
1806
+ std::integral_constant<size_t, I>) const {
1807
+ values->push_back(SafeMatcherCast<T>(std::get<I>(matchers_)));
1808
+ CreateVariadicMatcher<T>(values, std::integral_constant<size_t, I + 1>());
1809
+ }
1624
1810
 
1625
- const typename MatcherListType::ListType matchers_;
1811
+ template <typename T>
1812
+ void CreateVariadicMatcher(
1813
+ std::vector<Matcher<T> >*,
1814
+ std::integral_constant<size_t, sizeof...(Args)>) const {}
1815
+
1816
+ tuple<Args...> matchers_;
1626
1817
 
1627
1818
  GTEST_DISALLOW_ASSIGN_(VariadicMatcher);
1628
1819
  };
1629
1820
 
1630
1821
  template <typename... Args>
1631
- using AllOfMatcher = VariadicMatcher<BothOfMatcherImpl, Args...>;
1822
+ using AllOfMatcher = VariadicMatcher<AllOfMatcherImpl, Args...>;
1632
1823
 
1633
1824
  #endif // GTEST_LANG_CXX11
1634
1825
 
@@ -1645,8 +1836,10 @@ class BothOfMatcher {
1645
1836
  // both Matcher1 and Matcher2 can match.
1646
1837
  template <typename T>
1647
1838
  operator Matcher<T>() const {
1648
- return Matcher<T>(new BothOfMatcherImpl<T>(SafeMatcherCast<T>(matcher1_),
1649
- SafeMatcherCast<T>(matcher2_)));
1839
+ std::vector<Matcher<T> > values;
1840
+ values.push_back(SafeMatcherCast<T>(matcher1_));
1841
+ values.push_back(SafeMatcherCast<T>(matcher2_));
1842
+ return Matcher<T>(new AllOfMatcherImpl<T>(internal::move(values)));
1650
1843
  }
1651
1844
 
1652
1845
  private:
@@ -1661,68 +1854,69 @@ class BothOfMatcher {
1661
1854
  // that will prevent different instantiations of AnyOfMatcher from
1662
1855
  // sharing the same EitherOfMatcherImpl<T> class.
1663
1856
  template <typename T>
1664
- class EitherOfMatcherImpl : public MatcherInterface<T> {
1857
+ class AnyOfMatcherImpl
1858
+ : public MatcherInterface<GTEST_REFERENCE_TO_CONST_(T)> {
1665
1859
  public:
1666
- EitherOfMatcherImpl(const Matcher<T>& matcher1, const Matcher<T>& matcher2)
1667
- : matcher1_(matcher1), matcher2_(matcher2) {}
1860
+ explicit AnyOfMatcherImpl(std::vector<Matcher<T> > matchers)
1861
+ : matchers_(internal::move(matchers)) {}
1668
1862
 
1669
1863
  virtual void DescribeTo(::std::ostream* os) const {
1670
1864
  *os << "(";
1671
- matcher1_.DescribeTo(os);
1672
- *os << ") or (";
1673
- matcher2_.DescribeTo(os);
1865
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1866
+ if (i != 0) *os << ") or (";
1867
+ matchers_[i].DescribeTo(os);
1868
+ }
1674
1869
  *os << ")";
1675
1870
  }
1676
1871
 
1677
1872
  virtual void DescribeNegationTo(::std::ostream* os) const {
1678
1873
  *os << "(";
1679
- matcher1_.DescribeNegationTo(os);
1680
- *os << ") and (";
1681
- matcher2_.DescribeNegationTo(os);
1874
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1875
+ if (i != 0) *os << ") and (";
1876
+ matchers_[i].DescribeNegationTo(os);
1877
+ }
1682
1878
  *os << ")";
1683
1879
  }
1684
1880
 
1685
- virtual bool MatchAndExplain(T x, MatchResultListener* listener) const {
1881
+ virtual bool MatchAndExplain(GTEST_REFERENCE_TO_CONST_(T) x,
1882
+ MatchResultListener* listener) const {
1883
+ std::string no_match_result;
1884
+
1686
1885
  // If either matcher1_ or matcher2_ matches x, we just need to
1687
1886
  // explain why *one* of them matches.
1688
- StringMatchResultListener listener1;
1689
- if (matcher1_.MatchAndExplain(x, &listener1)) {
1690
- *listener << listener1.str();
1691
- return true;
1692
- }
1693
-
1694
- StringMatchResultListener listener2;
1695
- if (matcher2_.MatchAndExplain(x, &listener2)) {
1696
- *listener << listener2.str();
1697
- return true;
1887
+ for (size_t i = 0; i < matchers_.size(); ++i) {
1888
+ StringMatchResultListener slistener;
1889
+ if (matchers_[i].MatchAndExplain(x, &slistener)) {
1890
+ *listener << slistener.str();
1891
+ return true;
1892
+ } else {
1893
+ if (no_match_result.empty()) {
1894
+ no_match_result = slistener.str();
1895
+ } else {
1896
+ std::string result = slistener.str();
1897
+ if (!result.empty()) {
1898
+ no_match_result += ", and ";
1899
+ no_match_result += result;
1900
+ }
1901
+ }
1902
+ }
1698
1903
  }
1699
1904
 
1700
1905
  // Otherwise we need to explain why *both* of them fail.
1701
- const internal::string s1 = listener1.str();
1702
- const internal::string s2 = listener2.str();
1703
-
1704
- if (s1 == "") {
1705
- *listener << s2;
1706
- } else {
1707
- *listener << s1;
1708
- if (s2 != "") {
1709
- *listener << ", and " << s2;
1710
- }
1711
- }
1906
+ *listener << no_match_result;
1712
1907
  return false;
1713
1908
  }
1714
1909
 
1715
1910
  private:
1716
- const Matcher<T> matcher1_;
1717
- const Matcher<T> matcher2_;
1911
+ const std::vector<Matcher<T> > matchers_;
1718
1912
 
1719
- GTEST_DISALLOW_ASSIGN_(EitherOfMatcherImpl);
1913
+ GTEST_DISALLOW_ASSIGN_(AnyOfMatcherImpl);
1720
1914
  };
1721
1915
 
1722
1916
  #if GTEST_LANG_CXX11
1723
1917
  // AnyOfMatcher is used for the variadic implementation of AnyOf(m_1, m_2, ...).
1724
1918
  template <typename... Args>
1725
- using AnyOfMatcher = VariadicMatcher<EitherOfMatcherImpl, Args...>;
1919
+ using AnyOfMatcher = VariadicMatcher<AnyOfMatcherImpl, Args...>;
1726
1920
 
1727
1921
  #endif // GTEST_LANG_CXX11
1728
1922
 
@@ -1740,8 +1934,10 @@ class EitherOfMatcher {
1740
1934
  // both Matcher1 and Matcher2 can match.
1741
1935
  template <typename T>
1742
1936
  operator Matcher<T>() const {
1743
- return Matcher<T>(new EitherOfMatcherImpl<T>(
1744
- SafeMatcherCast<T>(matcher1_), SafeMatcherCast<T>(matcher2_)));
1937
+ std::vector<Matcher<T> > values;
1938
+ values.push_back(SafeMatcherCast<T>(matcher1_));
1939
+ values.push_back(SafeMatcherCast<T>(matcher2_));
1940
+ return Matcher<T>(new AnyOfMatcherImpl<T>(internal::move(values)));
1745
1941
  }
1746
1942
 
1747
1943
  private:
@@ -2037,6 +2233,82 @@ class FloatingEqMatcher {
2037
2233
  GTEST_DISALLOW_ASSIGN_(FloatingEqMatcher);
2038
2234
  };
2039
2235
 
2236
+ // A 2-tuple ("binary") wrapper around FloatingEqMatcher:
2237
+ // FloatingEq2Matcher() matches (x, y) by matching FloatingEqMatcher(x, false)
2238
+ // against y, and FloatingEq2Matcher(e) matches FloatingEqMatcher(x, false, e)
2239
+ // against y. The former implements "Eq", the latter "Near". At present, there
2240
+ // is no version that compares NaNs as equal.
2241
+ template <typename FloatType>
2242
+ class FloatingEq2Matcher {
2243
+ public:
2244
+ FloatingEq2Matcher() { Init(-1, false); }
2245
+
2246
+ explicit FloatingEq2Matcher(bool nan_eq_nan) { Init(-1, nan_eq_nan); }
2247
+
2248
+ explicit FloatingEq2Matcher(FloatType max_abs_error) {
2249
+ Init(max_abs_error, false);
2250
+ }
2251
+
2252
+ FloatingEq2Matcher(FloatType max_abs_error, bool nan_eq_nan) {
2253
+ Init(max_abs_error, nan_eq_nan);
2254
+ }
2255
+
2256
+ template <typename T1, typename T2>
2257
+ operator Matcher< ::testing::tuple<T1, T2> >() const {
2258
+ return MakeMatcher(
2259
+ new Impl< ::testing::tuple<T1, T2> >(max_abs_error_, nan_eq_nan_));
2260
+ }
2261
+ template <typename T1, typename T2>
2262
+ operator Matcher<const ::testing::tuple<T1, T2>&>() const {
2263
+ return MakeMatcher(
2264
+ new Impl<const ::testing::tuple<T1, T2>&>(max_abs_error_, nan_eq_nan_));
2265
+ }
2266
+
2267
+ private:
2268
+ static ::std::ostream& GetDesc(::std::ostream& os) { // NOLINT
2269
+ return os << "an almost-equal pair";
2270
+ }
2271
+
2272
+ template <typename Tuple>
2273
+ class Impl : public MatcherInterface<Tuple> {
2274
+ public:
2275
+ Impl(FloatType max_abs_error, bool nan_eq_nan) :
2276
+ max_abs_error_(max_abs_error),
2277
+ nan_eq_nan_(nan_eq_nan) {}
2278
+
2279
+ virtual bool MatchAndExplain(Tuple args,
2280
+ MatchResultListener* listener) const {
2281
+ if (max_abs_error_ == -1) {
2282
+ FloatingEqMatcher<FloatType> fm(::testing::get<0>(args), nan_eq_nan_);
2283
+ return static_cast<Matcher<FloatType> >(fm).MatchAndExplain(
2284
+ ::testing::get<1>(args), listener);
2285
+ } else {
2286
+ FloatingEqMatcher<FloatType> fm(::testing::get<0>(args), nan_eq_nan_,
2287
+ max_abs_error_);
2288
+ return static_cast<Matcher<FloatType> >(fm).MatchAndExplain(
2289
+ ::testing::get<1>(args), listener);
2290
+ }
2291
+ }
2292
+ virtual void DescribeTo(::std::ostream* os) const {
2293
+ *os << "are " << GetDesc;
2294
+ }
2295
+ virtual void DescribeNegationTo(::std::ostream* os) const {
2296
+ *os << "aren't " << GetDesc;
2297
+ }
2298
+
2299
+ private:
2300
+ FloatType max_abs_error_;
2301
+ const bool nan_eq_nan_;
2302
+ };
2303
+
2304
+ void Init(FloatType max_abs_error_val, bool nan_eq_nan_val) {
2305
+ max_abs_error_ = max_abs_error_val;
2306
+ nan_eq_nan_ = nan_eq_nan_val;
2307
+ }
2308
+ FloatType max_abs_error_;
2309
+ bool nan_eq_nan_;
2310
+ };
2311
+
2040
2312
  // Implements the Pointee(m) matcher for matching a pointer whose
2041
2313
  // pointee matches matcher m. The pointer can be either raw or smart.
2042
2314
  template <typename InnerMatcher>
@@ -2054,7 +2326,8 @@ class PointeeMatcher {
2054
2326
  // enough for implementing the DescribeTo() method of Pointee().
2055
2327
  template <typename Pointer>
2056
2328
  operator Matcher<Pointer>() const {
2057
- return MakeMatcher(new Impl<Pointer>(matcher_));
2329
+ return Matcher<Pointer>(
2330
+ new Impl<GTEST_REFERENCE_TO_CONST_(Pointer)>(matcher_));
2058
2331
  }
2059
2332
 
2060
2333
  private:
@@ -2098,6 +2371,7 @@ class PointeeMatcher {
2098
2371
  GTEST_DISALLOW_ASSIGN_(PointeeMatcher);
2099
2372
  };
2100
2373
 
2374
+ #if GTEST_HAS_RTTI
2101
2375
  // Implements the WhenDynamicCastTo<T>(m) matcher that matches a pointer or
2102
2376
  // reference that matches inner_matcher when dynamic_cast<T> is applied.
2103
2377
  // The result of dynamic_cast<To> is forwarded to the inner matcher.
@@ -2123,12 +2397,8 @@ class WhenDynamicCastToMatcherBase {
2123
2397
  protected:
2124
2398
  const Matcher<To> matcher_;
2125
2399
 
2126
- static string GetToName() {
2127
- #if GTEST_HAS_RTTI
2400
+ static std::string GetToName() {
2128
2401
  return GetTypeName<To>();
2129
- #else // GTEST_HAS_RTTI
2130
- return "the target type";
2131
- #endif // GTEST_HAS_RTTI
2132
2402
  }
2133
2403
 
2134
2404
  private:
@@ -2174,6 +2444,7 @@ class WhenDynamicCastToMatcher<To&> : public WhenDynamicCastToMatcherBase<To&> {
2174
2444
  return MatchPrintAndExplain(*to, this->matcher_, listener);
2175
2445
  }
2176
2446
  };
2447
+ #endif // GTEST_HAS_RTTI
2177
2448
 
2178
2449
  // Implements the Field() matcher for matching a field (i.e. member
2179
2450
  // variable) of an object.
@@ -2182,15 +2453,21 @@ class FieldMatcher {
2182
2453
  public:
2183
2454
  FieldMatcher(FieldType Class::*field,
2184
2455
  const Matcher<const FieldType&>& matcher)
2185
- : field_(field), matcher_(matcher) {}
2456
+ : field_(field), matcher_(matcher), whose_field_("whose given field ") {}
2457
+
2458
+ FieldMatcher(const std::string& field_name, FieldType Class::*field,
2459
+ const Matcher<const FieldType&>& matcher)
2460
+ : field_(field),
2461
+ matcher_(matcher),
2462
+ whose_field_("whose field `" + field_name + "` ") {}
2186
2463
 
2187
2464
  void DescribeTo(::std::ostream* os) const {
2188
- *os << "is an object whose given field ";
2465
+ *os << "is an object " << whose_field_;
2189
2466
  matcher_.DescribeTo(os);
2190
2467
  }
2191
2468
 
2192
2469
  void DescribeNegationTo(::std::ostream* os) const {
2193
- *os << "is an object whose given field ";
2470
+ *os << "is an object " << whose_field_;
2194
2471
  matcher_.DescribeNegationTo(os);
2195
2472
  }
2196
2473
 
@@ -2208,7 +2485,7 @@ class FieldMatcher {
2208
2485
  // true_type iff the Field() matcher is used to match a pointer.
2209
2486
  bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
2210
2487
  MatchResultListener* listener) const {
2211
- *listener << "whose given field is ";
2488
+ *listener << whose_field_ << "is ";
2212
2489
  return MatchPrintAndExplain(obj.*field_, matcher_, listener);
2213
2490
  }
2214
2491
 
@@ -2227,12 +2504,19 @@ class FieldMatcher {
2227
2504
  const FieldType Class::*field_;
2228
2505
  const Matcher<const FieldType&> matcher_;
2229
2506
 
2507
+ // Contains either "whose given field " if the name of the field is unknown
2508
+ // or "whose field `name_of_field` " if the name is known.
2509
+ const std::string whose_field_;
2510
+
2230
2511
  GTEST_DISALLOW_ASSIGN_(FieldMatcher);
2231
2512
  };
2232
2513
 
2233
2514
  // Implements the Property() matcher for matching a property
2234
2515
  // (i.e. return value of a getter method) of an object.
2235
- template <typename Class, typename PropertyType>
2516
+ //
2517
+ // Property is a const-qualified member function of Class returning
2518
+ // PropertyType.
2519
+ template <typename Class, typename PropertyType, typename Property>
2236
2520
  class PropertyMatcher {
2237
2521
  public:
2238
2522
  // The property may have a reference type, so 'const PropertyType&'
@@ -2241,17 +2525,24 @@ class PropertyMatcher {
2241
2525
  // PropertyType being a reference or not.
2242
2526
  typedef GTEST_REFERENCE_TO_CONST_(PropertyType) RefToConstProperty;
2243
2527
 
2244
- PropertyMatcher(PropertyType (Class::*property)() const,
2528
+ PropertyMatcher(Property property, const Matcher<RefToConstProperty>& matcher)
2529
+ : property_(property),
2530
+ matcher_(matcher),
2531
+ whose_property_("whose given property ") {}
2532
+
2533
+ PropertyMatcher(const std::string& property_name, Property property,
2245
2534
  const Matcher<RefToConstProperty>& matcher)
2246
- : property_(property), matcher_(matcher) {}
2535
+ : property_(property),
2536
+ matcher_(matcher),
2537
+ whose_property_("whose property `" + property_name + "` ") {}
2247
2538
 
2248
2539
  void DescribeTo(::std::ostream* os) const {
2249
- *os << "is an object whose given property ";
2540
+ *os << "is an object " << whose_property_;
2250
2541
  matcher_.DescribeTo(os);
2251
2542
  }
2252
2543
 
2253
2544
  void DescribeNegationTo(::std::ostream* os) const {
2254
- *os << "is an object whose given property ";
2545
+ *os << "is an object " << whose_property_;
2255
2546
  matcher_.DescribeNegationTo(os);
2256
2547
  }
2257
2548
 
@@ -2269,7 +2560,7 @@ class PropertyMatcher {
2269
2560
  // true_type iff the Property() matcher is used to match a pointer.
2270
2561
  bool MatchAndExplainImpl(false_type /* is_not_pointer */, const Class& obj,
2271
2562
  MatchResultListener* listener) const {
2272
- *listener << "whose given property is ";
2563
+ *listener << whose_property_ << "is ";
2273
2564
  // Cannot pass the return value (for example, int) to MatchPrintAndExplain,
2274
2565
  // which takes a non-const reference as argument.
2275
2566
  #if defined(_PREFAST_ ) && _MSC_VER == 1800
@@ -2295,9 +2586,13 @@ class PropertyMatcher {
2295
2586
  return MatchAndExplainImpl(false_type(), *p, listener);
2296
2587
  }
2297
2588
 
2298
- PropertyType (Class::*property_)() const;
2589
+ Property property_;
2299
2590
  const Matcher<RefToConstProperty> matcher_;
2300
2591
 
2592
+ // Contains either "whose given property " if the name of the property is
2593
+ // unknown or "whose property `name_of_property` " if the name is known.
2594
+ const std::string whose_property_;
2595
+
2301
2596
  GTEST_DISALLOW_ASSIGN_(PropertyMatcher);
2302
2597
  };
2303
2598
 
@@ -2378,7 +2673,7 @@ class ResultOfMatcher {
2378
2673
 
2379
2674
  private:
2380
2675
  // Functors often define operator() as non-const method even though
2381
- // they are actualy stateless. But we need to use them even when
2676
+ // they are actually stateless. But we need to use them even when
2382
2677
  // 'this' is a const pointer. It's the user's responsibility not to
2383
2678
  // use stateful callables with ResultOf(), which does't guarantee
2384
2679
  // how many times the callable will be invoked.
@@ -2691,6 +2986,10 @@ class WhenSortedByMatcher {
2691
2986
  // container and the RHS container respectively.
2692
2987
  template <typename TupleMatcher, typename RhsContainer>
2693
2988
  class PointwiseMatcher {
2989
+ GTEST_COMPILE_ASSERT_(
2990
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(RhsContainer)>::value,
2991
+ use_UnorderedPointwise_with_hash_tables);
2992
+
2694
2993
  public:
2695
2994
  typedef internal::StlContainerView<RhsContainer> RhsView;
2696
2995
  typedef typename RhsView::type RhsStlContainer;
@@ -2708,6 +3007,10 @@ class PointwiseMatcher {
2708
3007
 
2709
3008
  template <typename LhsContainer>
2710
3009
  operator Matcher<LhsContainer>() const {
3010
+ GTEST_COMPILE_ASSERT_(
3011
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(LhsContainer)>::value,
3012
+ use_UnorderedPointwise_with_hash_tables);
3013
+
2711
3014
  return MakeMatcher(new Impl<LhsContainer>(tuple_matcher_, rhs_));
2712
3015
  }
2713
3016
 
@@ -2758,12 +3061,15 @@ class PointwiseMatcher {
2758
3061
  typename LhsStlContainer::const_iterator left = lhs_stl_container.begin();
2759
3062
  typename RhsStlContainer::const_iterator right = rhs_.begin();
2760
3063
  for (size_t i = 0; i != actual_size; ++i, ++left, ++right) {
2761
- const InnerMatcherArg value_pair(*left, *right);
2762
-
2763
3064
  if (listener->IsInterested()) {
2764
3065
  StringMatchResultListener inner_listener;
3066
+ // Create InnerMatcherArg as a temporarily object to avoid it outlives
3067
+ // *left and *right. Dereference or the conversion to `const T&` may
3068
+ // return temp objects, e.g for vector<bool>.
2765
3069
  if (!mono_tuple_matcher_.MatchAndExplain(
2766
- value_pair, &inner_listener)) {
3070
+ InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
3071
+ ImplicitCast_<const RhsValue&>(*right)),
3072
+ &inner_listener)) {
2767
3073
  *listener << "where the value pair (";
2768
3074
  UniversalPrint(*left, listener->stream());
2769
3075
  *listener << ", ";
@@ -2773,7 +3079,9 @@ class PointwiseMatcher {
2773
3079
  return false;
2774
3080
  }
2775
3081
  } else {
2776
- if (!mono_tuple_matcher_.Matches(value_pair))
3082
+ if (!mono_tuple_matcher_.Matches(
3083
+ InnerMatcherArg(ImplicitCast_<const LhsValue&>(*left),
3084
+ ImplicitCast_<const RhsValue&>(*right))))
2777
3085
  return false;
2778
3086
  }
2779
3087
  }
@@ -2931,6 +3239,50 @@ class EachMatcher {
2931
3239
  GTEST_DISALLOW_ASSIGN_(EachMatcher);
2932
3240
  };
2933
3241
 
3242
+ struct Rank1 {};
3243
+ struct Rank0 : Rank1 {};
3244
+
3245
+ namespace pair_getters {
3246
+ #if GTEST_LANG_CXX11
3247
+ using std::get;
3248
+ template <typename T>
3249
+ auto First(T& x, Rank1) -> decltype(get<0>(x)) { // NOLINT
3250
+ return get<0>(x);
3251
+ }
3252
+ template <typename T>
3253
+ auto First(T& x, Rank0) -> decltype((x.first)) { // NOLINT
3254
+ return x.first;
3255
+ }
3256
+
3257
+ template <typename T>
3258
+ auto Second(T& x, Rank1) -> decltype(get<1>(x)) { // NOLINT
3259
+ return get<1>(x);
3260
+ }
3261
+ template <typename T>
3262
+ auto Second(T& x, Rank0) -> decltype((x.second)) { // NOLINT
3263
+ return x.second;
3264
+ }
3265
+ #else
3266
+ template <typename T>
3267
+ typename T::first_type& First(T& x, Rank0) { // NOLINT
3268
+ return x.first;
3269
+ }
3270
+ template <typename T>
3271
+ const typename T::first_type& First(const T& x, Rank0) {
3272
+ return x.first;
3273
+ }
3274
+
3275
+ template <typename T>
3276
+ typename T::second_type& Second(T& x, Rank0) { // NOLINT
3277
+ return x.second;
3278
+ }
3279
+ template <typename T>
3280
+ const typename T::second_type& Second(const T& x, Rank0) {
3281
+ return x.second;
3282
+ }
3283
+ #endif // GTEST_LANG_CXX11
3284
+ } // namespace pair_getters
3285
+
2934
3286
  // Implements Key(inner_matcher) for the given argument pair type.
2935
3287
  // Key(inner_matcher) matches an std::pair whose 'first' field matches
2936
3288
  // inner_matcher. For example, Contains(Key(Ge(5))) can be used to match an
@@ -2951,9 +3303,9 @@ class KeyMatcherImpl : public MatcherInterface<PairType> {
2951
3303
  virtual bool MatchAndExplain(PairType key_value,
2952
3304
  MatchResultListener* listener) const {
2953
3305
  StringMatchResultListener inner_listener;
2954
- const bool match = inner_matcher_.MatchAndExplain(key_value.first,
2955
- &inner_listener);
2956
- const internal::string explanation = inner_listener.str();
3306
+ const bool match = inner_matcher_.MatchAndExplain(
3307
+ pair_getters::First(key_value, Rank0()), &inner_listener);
3308
+ const std::string explanation = inner_listener.str();
2957
3309
  if (explanation != "") {
2958
3310
  *listener << "whose first field is a value " << explanation;
2959
3311
  }
@@ -3035,18 +3387,18 @@ class PairMatcherImpl : public MatcherInterface<PairType> {
3035
3387
  if (!listener->IsInterested()) {
3036
3388
  // If the listener is not interested, we don't need to construct the
3037
3389
  // explanation.
3038
- return first_matcher_.Matches(a_pair.first) &&
3039
- second_matcher_.Matches(a_pair.second);
3390
+ return first_matcher_.Matches(pair_getters::First(a_pair, Rank0())) &&
3391
+ second_matcher_.Matches(pair_getters::Second(a_pair, Rank0()));
3040
3392
  }
3041
3393
  StringMatchResultListener first_inner_listener;
3042
- if (!first_matcher_.MatchAndExplain(a_pair.first,
3394
+ if (!first_matcher_.MatchAndExplain(pair_getters::First(a_pair, Rank0()),
3043
3395
  &first_inner_listener)) {
3044
3396
  *listener << "whose first field does not match";
3045
3397
  PrintIfNotEmpty(first_inner_listener.str(), listener->stream());
3046
3398
  return false;
3047
3399
  }
3048
3400
  StringMatchResultListener second_inner_listener;
3049
- if (!second_matcher_.MatchAndExplain(a_pair.second,
3401
+ if (!second_matcher_.MatchAndExplain(pair_getters::Second(a_pair, Rank0()),
3050
3402
  &second_inner_listener)) {
3051
3403
  *listener << "whose second field does not match";
3052
3404
  PrintIfNotEmpty(second_inner_listener.str(), listener->stream());
@@ -3058,8 +3410,8 @@ class PairMatcherImpl : public MatcherInterface<PairType> {
3058
3410
  }
3059
3411
 
3060
3412
  private:
3061
- void ExplainSuccess(const internal::string& first_explanation,
3062
- const internal::string& second_explanation,
3413
+ void ExplainSuccess(const std::string& first_explanation,
3414
+ const std::string& second_explanation,
3063
3415
  MatchResultListener* listener) const {
3064
3416
  *listener << "whose both fields match";
3065
3417
  if (first_explanation != "") {
@@ -3166,7 +3518,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
3166
3518
  const bool listener_interested = listener->IsInterested();
3167
3519
 
3168
3520
  // explanations[i] is the explanation of the element at index i.
3169
- ::std::vector<internal::string> explanations(count());
3521
+ ::std::vector<std::string> explanations(count());
3170
3522
  StlContainerReference stl_container = View::ConstReference(container);
3171
3523
  typename StlContainer::const_iterator it = stl_container.begin();
3172
3524
  size_t exam_pos = 0;
@@ -3225,7 +3577,7 @@ class ElementsAreMatcherImpl : public MatcherInterface<Container> {
3225
3577
  if (listener_interested) {
3226
3578
  bool reason_printed = false;
3227
3579
  for (size_t i = 0; i != count(); ++i) {
3228
- const internal::string& s = explanations[i];
3580
+ const std::string& s = explanations[i];
3229
3581
  if (!s.empty()) {
3230
3582
  if (reason_printed) {
3231
3583
  *listener << ",\nand ";
@@ -3278,7 +3630,7 @@ class GTEST_API_ MatchMatrix {
3278
3630
 
3279
3631
  void Randomize();
3280
3632
 
3281
- string DebugString() const;
3633
+ std::string DebugString() const;
3282
3634
 
3283
3635
  private:
3284
3636
  size_t SpaceIndex(size_t ilhs, size_t irhs) const {
@@ -3302,14 +3654,23 @@ typedef ::std::vector<ElementMatcherPair> ElementMatcherPairs;
3302
3654
  GTEST_API_ ElementMatcherPairs
3303
3655
  FindMaxBipartiteMatching(const MatchMatrix& g);
3304
3656
 
3305
- GTEST_API_ bool FindPairing(const MatchMatrix& matrix,
3306
- MatchResultListener* listener);
3657
+ struct UnorderedMatcherRequire {
3658
+ enum Flags {
3659
+ Superset = 1 << 0,
3660
+ Subset = 1 << 1,
3661
+ ExactMatch = Superset | Subset,
3662
+ };
3663
+ };
3307
3664
 
3308
3665
  // Untyped base class for implementing UnorderedElementsAre. By
3309
3666
  // putting logic that's not specific to the element type here, we
3310
3667
  // reduce binary bloat and increase compilation speed.
3311
3668
  class GTEST_API_ UnorderedElementsAreMatcherImplBase {
3312
3669
  protected:
3670
+ explicit UnorderedElementsAreMatcherImplBase(
3671
+ UnorderedMatcherRequire::Flags matcher_flags)
3672
+ : match_flags_(matcher_flags) {}
3673
+
3313
3674
  // A vector of matcher describers, one for each element matcher.
3314
3675
  // Does not own the describers (and thus can be used only when the
3315
3676
  // element matchers are alive).
@@ -3321,10 +3682,12 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase {
3321
3682
  // Describes the negation of this UnorderedElementsAre matcher.
3322
3683
  void DescribeNegationToImpl(::std::ostream* os) const;
3323
3684
 
3324
- bool VerifyAllElementsAndMatchersAreMatched(
3325
- const ::std::vector<string>& element_printouts,
3326
- const MatchMatrix& matrix,
3327
- MatchResultListener* listener) const;
3685
+ bool VerifyMatchMatrix(const ::std::vector<std::string>& element_printouts,
3686
+ const MatchMatrix& matrix,
3687
+ MatchResultListener* listener) const;
3688
+
3689
+ bool FindPairing(const MatchMatrix& matrix,
3690
+ MatchResultListener* listener) const;
3328
3691
 
3329
3692
  MatcherDescriberVec& matcher_describers() {
3330
3693
  return matcher_describers_;
@@ -3334,13 +3697,17 @@ class GTEST_API_ UnorderedElementsAreMatcherImplBase {
3334
3697
  return Message() << n << " element" << (n == 1 ? "" : "s");
3335
3698
  }
3336
3699
 
3700
+ UnorderedMatcherRequire::Flags match_flags() const { return match_flags_; }
3701
+
3337
3702
  private:
3703
+ UnorderedMatcherRequire::Flags match_flags_;
3338
3704
  MatcherDescriberVec matcher_describers_;
3339
3705
 
3340
3706
  GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImplBase);
3341
3707
  };
3342
3708
 
3343
- // Implements unordered ElementsAre and unordered ElementsAreArray.
3709
+ // Implements UnorderedElementsAre, UnorderedElementsAreArray, IsSubsetOf, and
3710
+ // IsSupersetOf.
3344
3711
  template <typename Container>
3345
3712
  class UnorderedElementsAreMatcherImpl
3346
3713
  : public MatcherInterface<Container>,
@@ -3353,10 +3720,10 @@ class UnorderedElementsAreMatcherImpl
3353
3720
  typedef typename StlContainer::const_iterator StlContainerConstIterator;
3354
3721
  typedef typename StlContainer::value_type Element;
3355
3722
 
3356
- // Constructs the matcher from a sequence of element values or
3357
- // element matchers.
3358
3723
  template <typename InputIter>
3359
- UnorderedElementsAreMatcherImpl(InputIter first, InputIter last) {
3724
+ UnorderedElementsAreMatcherImpl(UnorderedMatcherRequire::Flags matcher_flags,
3725
+ InputIter first, InputIter last)
3726
+ : UnorderedElementsAreMatcherImplBase(matcher_flags) {
3360
3727
  for (; first != last; ++first) {
3361
3728
  matchers_.push_back(MatcherCast<const Element&>(*first));
3362
3729
  matcher_describers().push_back(matchers_.back().GetDescriber());
@@ -3376,38 +3743,36 @@ class UnorderedElementsAreMatcherImpl
3376
3743
  virtual bool MatchAndExplain(Container container,
3377
3744
  MatchResultListener* listener) const {
3378
3745
  StlContainerReference stl_container = View::ConstReference(container);
3379
- ::std::vector<string> element_printouts;
3380
- MatchMatrix matrix = AnalyzeElements(stl_container.begin(),
3381
- stl_container.end(),
3382
- &element_printouts,
3383
- listener);
3384
-
3385
- const size_t actual_count = matrix.LhsSize();
3386
- if (actual_count == 0 && matchers_.empty()) {
3746
+ ::std::vector<std::string> element_printouts;
3747
+ MatchMatrix matrix =
3748
+ AnalyzeElements(stl_container.begin(), stl_container.end(),
3749
+ &element_printouts, listener);
3750
+
3751
+ if (matrix.LhsSize() == 0 && matrix.RhsSize() == 0) {
3387
3752
  return true;
3388
3753
  }
3389
- if (actual_count != matchers_.size()) {
3390
- // The element count doesn't match. If the container is empty,
3391
- // there's no need to explain anything as Google Mock already
3392
- // prints the empty container. Otherwise we just need to show
3393
- // how many elements there actually are.
3394
- if (actual_count != 0 && listener->IsInterested()) {
3395
- *listener << "which has " << Elements(actual_count);
3754
+
3755
+ if (match_flags() == UnorderedMatcherRequire::ExactMatch) {
3756
+ if (matrix.LhsSize() != matrix.RhsSize()) {
3757
+ // The element count doesn't match. If the container is empty,
3758
+ // there's no need to explain anything as Google Mock already
3759
+ // prints the empty container. Otherwise we just need to show
3760
+ // how many elements there actually are.
3761
+ if (matrix.LhsSize() != 0 && listener->IsInterested()) {
3762
+ *listener << "which has " << Elements(matrix.LhsSize());
3763
+ }
3764
+ return false;
3396
3765
  }
3397
- return false;
3398
3766
  }
3399
3767
 
3400
- return VerifyAllElementsAndMatchersAreMatched(element_printouts,
3401
- matrix, listener) &&
3768
+ return VerifyMatchMatrix(element_printouts, matrix, listener) &&
3402
3769
  FindPairing(matrix, listener);
3403
3770
  }
3404
3771
 
3405
3772
  private:
3406
- typedef ::std::vector<Matcher<const Element&> > MatcherVec;
3407
-
3408
3773
  template <typename ElementIter>
3409
3774
  MatchMatrix AnalyzeElements(ElementIter elem_first, ElementIter elem_last,
3410
- ::std::vector<string>* element_printouts,
3775
+ ::std::vector<std::string>* element_printouts,
3411
3776
  MatchResultListener* listener) const {
3412
3777
  element_printouts->clear();
3413
3778
  ::std::vector<char> did_match;
@@ -3431,7 +3796,7 @@ class UnorderedElementsAreMatcherImpl
3431
3796
  return matrix;
3432
3797
  }
3433
3798
 
3434
- MatcherVec matchers_;
3799
+ ::std::vector<Matcher<const Element&> > matchers_;
3435
3800
 
3436
3801
  GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreMatcherImpl);
3437
3802
  };
@@ -3464,7 +3829,7 @@ class UnorderedElementsAreMatcher {
3464
3829
  TransformTupleValues(CastAndAppendTransform<const Element&>(), matchers_,
3465
3830
  ::std::back_inserter(matchers));
3466
3831
  return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
3467
- matchers.begin(), matchers.end()));
3832
+ UnorderedMatcherRequire::ExactMatch, matchers.begin(), matchers.end()));
3468
3833
  }
3469
3834
 
3470
3835
  private:
@@ -3480,6 +3845,11 @@ class ElementsAreMatcher {
3480
3845
 
3481
3846
  template <typename Container>
3482
3847
  operator Matcher<Container>() const {
3848
+ GTEST_COMPILE_ASSERT_(
3849
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value ||
3850
+ ::testing::tuple_size<MatcherTuple>::value < 2,
3851
+ use_UnorderedElementsAre_with_hash_tables);
3852
+
3483
3853
  typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Container) RawContainer;
3484
3854
  typedef typename internal::StlContainerView<RawContainer>::type View;
3485
3855
  typedef typename View::value_type Element;
@@ -3497,24 +3867,23 @@ class ElementsAreMatcher {
3497
3867
  GTEST_DISALLOW_ASSIGN_(ElementsAreMatcher);
3498
3868
  };
3499
3869
 
3500
- // Implements UnorderedElementsAreArray().
3870
+ // Implements UnorderedElementsAreArray(), IsSubsetOf(), and IsSupersetOf().
3501
3871
  template <typename T>
3502
3872
  class UnorderedElementsAreArrayMatcher {
3503
3873
  public:
3504
- UnorderedElementsAreArrayMatcher() {}
3505
-
3506
3874
  template <typename Iter>
3507
- UnorderedElementsAreArrayMatcher(Iter first, Iter last)
3508
- : matchers_(first, last) {}
3875
+ UnorderedElementsAreArrayMatcher(UnorderedMatcherRequire::Flags match_flags,
3876
+ Iter first, Iter last)
3877
+ : match_flags_(match_flags), matchers_(first, last) {}
3509
3878
 
3510
3879
  template <typename Container>
3511
3880
  operator Matcher<Container>() const {
3512
- return MakeMatcher(
3513
- new UnorderedElementsAreMatcherImpl<Container>(matchers_.begin(),
3514
- matchers_.end()));
3881
+ return MakeMatcher(new UnorderedElementsAreMatcherImpl<Container>(
3882
+ match_flags_, matchers_.begin(), matchers_.end()));
3515
3883
  }
3516
3884
 
3517
3885
  private:
3886
+ UnorderedMatcherRequire::Flags match_flags_;
3518
3887
  ::std::vector<T> matchers_;
3519
3888
 
3520
3889
  GTEST_DISALLOW_ASSIGN_(UnorderedElementsAreArrayMatcher);
@@ -3529,6 +3898,10 @@ class ElementsAreArrayMatcher {
3529
3898
 
3530
3899
  template <typename Container>
3531
3900
  operator Matcher<Container>() const {
3901
+ GTEST_COMPILE_ASSERT_(
3902
+ !IsHashTable<GTEST_REMOVE_REFERENCE_AND_CONST_(Container)>::value,
3903
+ use_UnorderedElementsAreArray_with_hash_tables);
3904
+
3532
3905
  return MakeMatcher(new ElementsAreMatcherImpl<Container>(
3533
3906
  matchers_.begin(), matchers_.end()));
3534
3907
  }
@@ -3619,13 +3992,189 @@ BoundSecondMatcher<Tuple2Matcher, Second> MatcherBindSecond(
3619
3992
  // 'negation' is false; otherwise returns the description of the
3620
3993
  // negation of the matcher. 'param_values' contains a list of strings
3621
3994
  // that are the print-out of the matcher's parameters.
3622
- GTEST_API_ string FormatMatcherDescription(bool negation,
3623
- const char* matcher_name,
3624
- const Strings& param_values);
3995
+ GTEST_API_ std::string FormatMatcherDescription(bool negation,
3996
+ const char* matcher_name,
3997
+ const Strings& param_values);
3998
+
3999
+ // Implements a matcher that checks the value of a optional<> type variable.
4000
+ template <typename ValueMatcher>
4001
+ class OptionalMatcher {
4002
+ public:
4003
+ explicit OptionalMatcher(const ValueMatcher& value_matcher)
4004
+ : value_matcher_(value_matcher) {}
3625
4005
 
4006
+ template <typename Optional>
4007
+ operator Matcher<Optional>() const {
4008
+ return MakeMatcher(new Impl<Optional>(value_matcher_));
4009
+ }
4010
+
4011
+ template <typename Optional>
4012
+ class Impl : public MatcherInterface<Optional> {
4013
+ public:
4014
+ typedef GTEST_REMOVE_REFERENCE_AND_CONST_(Optional) OptionalView;
4015
+ typedef typename OptionalView::value_type ValueType;
4016
+ explicit Impl(const ValueMatcher& value_matcher)
4017
+ : value_matcher_(MatcherCast<ValueType>(value_matcher)) {}
4018
+
4019
+ virtual void DescribeTo(::std::ostream* os) const {
4020
+ *os << "value ";
4021
+ value_matcher_.DescribeTo(os);
4022
+ }
4023
+
4024
+ virtual void DescribeNegationTo(::std::ostream* os) const {
4025
+ *os << "value ";
4026
+ value_matcher_.DescribeNegationTo(os);
4027
+ }
4028
+
4029
+ virtual bool MatchAndExplain(Optional optional,
4030
+ MatchResultListener* listener) const {
4031
+ if (!optional) {
4032
+ *listener << "which is not engaged";
4033
+ return false;
4034
+ }
4035
+ const ValueType& value = *optional;
4036
+ StringMatchResultListener value_listener;
4037
+ const bool match = value_matcher_.MatchAndExplain(value, &value_listener);
4038
+ *listener << "whose value " << PrintToString(value)
4039
+ << (match ? " matches" : " doesn't match");
4040
+ PrintIfNotEmpty(value_listener.str(), listener->stream());
4041
+ return match;
4042
+ }
4043
+
4044
+ private:
4045
+ const Matcher<ValueType> value_matcher_;
4046
+ GTEST_DISALLOW_ASSIGN_(Impl);
4047
+ };
4048
+
4049
+ private:
4050
+ const ValueMatcher value_matcher_;
4051
+ GTEST_DISALLOW_ASSIGN_(OptionalMatcher);
4052
+ };
4053
+
4054
+ namespace variant_matcher {
4055
+ // Overloads to allow VariantMatcher to do proper ADL lookup.
4056
+ template <typename T>
4057
+ void holds_alternative() {}
4058
+ template <typename T>
4059
+ void get() {}
4060
+
4061
+ // Implements a matcher that checks the value of a variant<> type variable.
4062
+ template <typename T>
4063
+ class VariantMatcher {
4064
+ public:
4065
+ explicit VariantMatcher(::testing::Matcher<const T&> matcher)
4066
+ : matcher_(internal::move(matcher)) {}
4067
+
4068
+ template <typename Variant>
4069
+ bool MatchAndExplain(const Variant& value,
4070
+ ::testing::MatchResultListener* listener) const {
4071
+ if (!listener->IsInterested()) {
4072
+ return holds_alternative<T>(value) && matcher_.Matches(get<T>(value));
4073
+ }
4074
+
4075
+ if (!holds_alternative<T>(value)) {
4076
+ *listener << "whose value is not of type '" << GetTypeName() << "'";
4077
+ return false;
4078
+ }
4079
+
4080
+ const T& elem = get<T>(value);
4081
+ StringMatchResultListener elem_listener;
4082
+ const bool match = matcher_.MatchAndExplain(elem, &elem_listener);
4083
+ *listener << "whose value " << PrintToString(elem)
4084
+ << (match ? " matches" : " doesn't match");
4085
+ PrintIfNotEmpty(elem_listener.str(), listener->stream());
4086
+ return match;
4087
+ }
4088
+
4089
+ void DescribeTo(std::ostream* os) const {
4090
+ *os << "is a variant<> with value of type '" << GetTypeName()
4091
+ << "' and the value ";
4092
+ matcher_.DescribeTo(os);
4093
+ }
4094
+
4095
+ void DescribeNegationTo(std::ostream* os) const {
4096
+ *os << "is a variant<> with value of type other than '" << GetTypeName()
4097
+ << "' or the value ";
4098
+ matcher_.DescribeNegationTo(os);
4099
+ }
4100
+
4101
+ private:
4102
+ static std::string GetTypeName() {
4103
+ #if GTEST_HAS_RTTI
4104
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
4105
+ return internal::GetTypeName<T>());
4106
+ #endif
4107
+ return "the element type";
4108
+ }
4109
+
4110
+ const ::testing::Matcher<const T&> matcher_;
4111
+ };
4112
+
4113
+ } // namespace variant_matcher
4114
+
4115
+ namespace any_cast_matcher {
4116
+
4117
+ // Overloads to allow AnyCastMatcher to do proper ADL lookup.
4118
+ template <typename T>
4119
+ void any_cast() {}
4120
+
4121
+ // Implements a matcher that any_casts the value.
4122
+ template <typename T>
4123
+ class AnyCastMatcher {
4124
+ public:
4125
+ explicit AnyCastMatcher(const ::testing::Matcher<const T&>& matcher)
4126
+ : matcher_(matcher) {}
4127
+
4128
+ template <typename AnyType>
4129
+ bool MatchAndExplain(const AnyType& value,
4130
+ ::testing::MatchResultListener* listener) const {
4131
+ if (!listener->IsInterested()) {
4132
+ const T* ptr = any_cast<T>(&value);
4133
+ return ptr != NULL && matcher_.Matches(*ptr);
4134
+ }
4135
+
4136
+ const T* elem = any_cast<T>(&value);
4137
+ if (elem == NULL) {
4138
+ *listener << "whose value is not of type '" << GetTypeName() << "'";
4139
+ return false;
4140
+ }
4141
+
4142
+ StringMatchResultListener elem_listener;
4143
+ const bool match = matcher_.MatchAndExplain(*elem, &elem_listener);
4144
+ *listener << "whose value " << PrintToString(*elem)
4145
+ << (match ? " matches" : " doesn't match");
4146
+ PrintIfNotEmpty(elem_listener.str(), listener->stream());
4147
+ return match;
4148
+ }
4149
+
4150
+ void DescribeTo(std::ostream* os) const {
4151
+ *os << "is an 'any' type with value of type '" << GetTypeName()
4152
+ << "' and the value ";
4153
+ matcher_.DescribeTo(os);
4154
+ }
4155
+
4156
+ void DescribeNegationTo(std::ostream* os) const {
4157
+ *os << "is an 'any' type with value of type other than '" << GetTypeName()
4158
+ << "' or the value ";
4159
+ matcher_.DescribeNegationTo(os);
4160
+ }
4161
+
4162
+ private:
4163
+ static std::string GetTypeName() {
4164
+ #if GTEST_HAS_RTTI
4165
+ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(
4166
+ return internal::GetTypeName<T>());
4167
+ #endif
4168
+ return "the element type";
4169
+ }
4170
+
4171
+ const ::testing::Matcher<const T&> matcher_;
4172
+ };
4173
+
4174
+ } // namespace any_cast_matcher
3626
4175
  } // namespace internal
3627
4176
 
3628
- // ElementsAreArray(first, last)
4177
+ // ElementsAreArray(iterator_first, iterator_last)
3629
4178
  // ElementsAreArray(pointer, count)
3630
4179
  // ElementsAreArray(array)
3631
4180
  // ElementsAreArray(container)
@@ -3674,20 +4223,26 @@ ElementsAreArray(::std::initializer_list<T> xs) {
3674
4223
  }
3675
4224
  #endif
3676
4225
 
3677
- // UnorderedElementsAreArray(first, last)
4226
+ // UnorderedElementsAreArray(iterator_first, iterator_last)
3678
4227
  // UnorderedElementsAreArray(pointer, count)
3679
4228
  // UnorderedElementsAreArray(array)
3680
4229
  // UnorderedElementsAreArray(container)
3681
4230
  // UnorderedElementsAreArray({ e1, e2, ..., en })
3682
4231
  //
3683
- // The UnorderedElementsAreArray() functions are like
3684
- // ElementsAreArray(...), but allow matching the elements in any order.
4232
+ // UnorderedElementsAreArray() verifies that a bijective mapping onto a
4233
+ // collection of matchers exists.
4234
+ //
4235
+ // The matchers can be specified as an array, a pointer and count, a container,
4236
+ // an initializer list, or an STL iterator range. In each of these cases, the
4237
+ // underlying matchers can be either values or matchers.
4238
+
3685
4239
  template <typename Iter>
3686
4240
  inline internal::UnorderedElementsAreArrayMatcher<
3687
4241
  typename ::std::iterator_traits<Iter>::value_type>
3688
4242
  UnorderedElementsAreArray(Iter first, Iter last) {
3689
4243
  typedef typename ::std::iterator_traits<Iter>::value_type T;
3690
- return internal::UnorderedElementsAreArrayMatcher<T>(first, last);
4244
+ return internal::UnorderedElementsAreArrayMatcher<T>(
4245
+ internal::UnorderedMatcherRequire::ExactMatch, first, last);
3691
4246
  }
3692
4247
 
3693
4248
  template <typename T>
@@ -3729,7 +4284,9 @@ UnorderedElementsAreArray(::std::initializer_list<T> xs) {
3729
4284
  const internal::AnythingMatcher _ = {};
3730
4285
  // Creates a matcher that matches any value of the given type T.
3731
4286
  template <typename T>
3732
- inline Matcher<T> A() { return MakeMatcher(new internal::AnyMatcherImpl<T>()); }
4287
+ inline Matcher<T> A() {
4288
+ return Matcher<T>(new internal::AnyMatcherImpl<T>());
4289
+ }
3733
4290
 
3734
4291
  // Creates a matcher that matches any value of the given type T.
3735
4292
  template <typename T>
@@ -3746,6 +4303,14 @@ inline internal::EqMatcher<T> Eq(T x) { return internal::EqMatcher<T>(x); }
3746
4303
  template <typename T>
3747
4304
  Matcher<T>::Matcher(T value) { *this = Eq(value); }
3748
4305
 
4306
+ template <typename T, typename M>
4307
+ Matcher<T> internal::MatcherCastImpl<T, M>::CastImpl(
4308
+ const M& value,
4309
+ internal::BooleanConstant<false> /* convertible_to_matcher */,
4310
+ internal::BooleanConstant<false> /* convertible_to_T */) {
4311
+ return Eq(value);
4312
+ }
4313
+
3749
4314
  // Creates a monomorphic matcher that matches anything with type Lhs
3750
4315
  // and equal to rhs. A user may need to use this instead of Eq(...)
3751
4316
  // in order to resolve an overloading ambiguity.
@@ -3874,6 +4439,7 @@ inline internal::PointeeMatcher<InnerMatcher> Pointee(
3874
4439
  return internal::PointeeMatcher<InnerMatcher>(inner_matcher);
3875
4440
  }
3876
4441
 
4442
+ #if GTEST_HAS_RTTI
3877
4443
  // Creates a matcher that matches a pointer or reference that matches
3878
4444
  // inner_matcher when dynamic_cast<To> is applied.
3879
4445
  // The result of dynamic_cast<To> is forwarded to the inner matcher.
@@ -3886,6 +4452,7 @@ WhenDynamicCastTo(const Matcher<To>& inner_matcher) {
3886
4452
  return MakePolymorphicMatcher(
3887
4453
  internal::WhenDynamicCastToMatcher<To>(inner_matcher));
3888
4454
  }
4455
+ #endif // GTEST_HAS_RTTI
3889
4456
 
3890
4457
  // Creates a matcher that matches an object whose given field matches
3891
4458
  // 'matcher'. For example,
@@ -3904,16 +4471,28 @@ inline PolymorphicMatcher<
3904
4471
  // to compile where bar is an int32 and m is a matcher for int64.
3905
4472
  }
3906
4473
 
4474
+ // Same as Field() but also takes the name of the field to provide better error
4475
+ // messages.
4476
+ template <typename Class, typename FieldType, typename FieldMatcher>
4477
+ inline PolymorphicMatcher<internal::FieldMatcher<Class, FieldType> > Field(
4478
+ const std::string& field_name, FieldType Class::*field,
4479
+ const FieldMatcher& matcher) {
4480
+ return MakePolymorphicMatcher(internal::FieldMatcher<Class, FieldType>(
4481
+ field_name, field, MatcherCast<const FieldType&>(matcher)));
4482
+ }
4483
+
3907
4484
  // Creates a matcher that matches an object whose given property
3908
4485
  // matches 'matcher'. For example,
3909
4486
  // Property(&Foo::str, StartsWith("hi"))
3910
4487
  // matches a Foo object x iff x.str() starts with "hi".
3911
4488
  template <typename Class, typename PropertyType, typename PropertyMatcher>
3912
- inline PolymorphicMatcher<
3913
- internal::PropertyMatcher<Class, PropertyType> > Property(
3914
- PropertyType (Class::*property)() const, const PropertyMatcher& matcher) {
4489
+ inline PolymorphicMatcher<internal::PropertyMatcher<
4490
+ Class, PropertyType, PropertyType (Class::*)() const> >
4491
+ Property(PropertyType (Class::*property)() const,
4492
+ const PropertyMatcher& matcher) {
3915
4493
  return MakePolymorphicMatcher(
3916
- internal::PropertyMatcher<Class, PropertyType>(
4494
+ internal::PropertyMatcher<Class, PropertyType,
4495
+ PropertyType (Class::*)() const>(
3917
4496
  property,
3918
4497
  MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
3919
4498
  // The call to MatcherCast() is required for supporting inner
@@ -3922,6 +4501,36 @@ inline PolymorphicMatcher<
3922
4501
  // to compile where bar() returns an int32 and m is a matcher for int64.
3923
4502
  }
3924
4503
 
4504
+ // Same as Property() above, but also takes the name of the property to provide
4505
+ // better error messages.
4506
+ template <typename Class, typename PropertyType, typename PropertyMatcher>
4507
+ inline PolymorphicMatcher<internal::PropertyMatcher<
4508
+ Class, PropertyType, PropertyType (Class::*)() const> >
4509
+ Property(const std::string& property_name,
4510
+ PropertyType (Class::*property)() const,
4511
+ const PropertyMatcher& matcher) {
4512
+ return MakePolymorphicMatcher(
4513
+ internal::PropertyMatcher<Class, PropertyType,
4514
+ PropertyType (Class::*)() const>(
4515
+ property_name, property,
4516
+ MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
4517
+ }
4518
+
4519
+ #if GTEST_LANG_CXX11
4520
+ // The same as above but for reference-qualified member functions.
4521
+ template <typename Class, typename PropertyType, typename PropertyMatcher>
4522
+ inline PolymorphicMatcher<internal::PropertyMatcher<
4523
+ Class, PropertyType, PropertyType (Class::*)() const &> >
4524
+ Property(PropertyType (Class::*property)() const &,
4525
+ const PropertyMatcher& matcher) {
4526
+ return MakePolymorphicMatcher(
4527
+ internal::PropertyMatcher<Class, PropertyType,
4528
+ PropertyType (Class::*)() const &>(
4529
+ property,
4530
+ MatcherCast<GTEST_REFERENCE_TO_CONST_(PropertyType)>(matcher)));
4531
+ }
4532
+ #endif
4533
+
3925
4534
  // Creates a matcher that matches an object iff the result of applying
3926
4535
  // a callable to x matches 'matcher'.
3927
4536
  // For example,
@@ -3935,6 +4544,7 @@ inline PolymorphicMatcher<
3935
4544
  // concurrent access.
3936
4545
  // * If it is a function object, it has to define type result_type.
3937
4546
  // We recommend deriving your functor classes from std::unary_function.
4547
+ //
3938
4548
  template <typename Callable, typename ResultOfMatcher>
3939
4549
  internal::ResultOfMatcher<Callable> ResultOf(
3940
4550
  Callable callable, const ResultOfMatcher& matcher) {
@@ -3951,53 +4561,52 @@ internal::ResultOfMatcher<Callable> ResultOf(
3951
4561
  // String matchers.
3952
4562
 
3953
4563
  // Matches a string equal to str.
3954
- inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
3955
- StrEq(const internal::string& str) {
3956
- return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
3957
- str, true, true));
4564
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrEq(
4565
+ const std::string& str) {
4566
+ return MakePolymorphicMatcher(
4567
+ internal::StrEqualityMatcher<std::string>(str, true, true));
3958
4568
  }
3959
4569
 
3960
4570
  // Matches a string not equal to str.
3961
- inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
3962
- StrNe(const internal::string& str) {
3963
- return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
3964
- str, false, true));
4571
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrNe(
4572
+ const std::string& str) {
4573
+ return MakePolymorphicMatcher(
4574
+ internal::StrEqualityMatcher<std::string>(str, false, true));
3965
4575
  }
3966
4576
 
3967
4577
  // Matches a string equal to str, ignoring case.
3968
- inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
3969
- StrCaseEq(const internal::string& str) {
3970
- return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
3971
- str, true, false));
4578
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseEq(
4579
+ const std::string& str) {
4580
+ return MakePolymorphicMatcher(
4581
+ internal::StrEqualityMatcher<std::string>(str, true, false));
3972
4582
  }
3973
4583
 
3974
4584
  // Matches a string not equal to str, ignoring case.
3975
- inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::string> >
3976
- StrCaseNe(const internal::string& str) {
3977
- return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::string>(
3978
- str, false, false));
4585
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::string> > StrCaseNe(
4586
+ const std::string& str) {
4587
+ return MakePolymorphicMatcher(
4588
+ internal::StrEqualityMatcher<std::string>(str, false, false));
3979
4589
  }
3980
4590
 
3981
4591
  // Creates a matcher that matches any string, std::string, or C string
3982
4592
  // that contains the given substring.
3983
- inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::string> >
3984
- HasSubstr(const internal::string& substring) {
3985
- return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::string>(
3986
- substring));
4593
+ inline PolymorphicMatcher<internal::HasSubstrMatcher<std::string> > HasSubstr(
4594
+ const std::string& substring) {
4595
+ return MakePolymorphicMatcher(
4596
+ internal::HasSubstrMatcher<std::string>(substring));
3987
4597
  }
3988
4598
 
3989
4599
  // Matches a string that starts with 'prefix' (case-sensitive).
3990
- inline PolymorphicMatcher<internal::StartsWithMatcher<internal::string> >
3991
- StartsWith(const internal::string& prefix) {
3992
- return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::string>(
3993
- prefix));
4600
+ inline PolymorphicMatcher<internal::StartsWithMatcher<std::string> > StartsWith(
4601
+ const std::string& prefix) {
4602
+ return MakePolymorphicMatcher(
4603
+ internal::StartsWithMatcher<std::string>(prefix));
3994
4604
  }
3995
4605
 
3996
4606
  // Matches a string that ends with 'suffix' (case-sensitive).
3997
- inline PolymorphicMatcher<internal::EndsWithMatcher<internal::string> >
3998
- EndsWith(const internal::string& suffix) {
3999
- return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::string>(
4000
- suffix));
4607
+ inline PolymorphicMatcher<internal::EndsWithMatcher<std::string> > EndsWith(
4608
+ const std::string& suffix) {
4609
+ return MakePolymorphicMatcher(internal::EndsWithMatcher<std::string>(suffix));
4001
4610
  }
4002
4611
 
4003
4612
  // Matches a string that fully matches regular expression 'regex'.
@@ -4007,7 +4616,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
4007
4616
  return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, true));
4008
4617
  }
4009
4618
  inline PolymorphicMatcher<internal::MatchesRegexMatcher> MatchesRegex(
4010
- const internal::string& regex) {
4619
+ const std::string& regex) {
4011
4620
  return MatchesRegex(new internal::RE(regex));
4012
4621
  }
4013
4622
 
@@ -4018,7 +4627,7 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
4018
4627
  return MakePolymorphicMatcher(internal::MatchesRegexMatcher(regex, false));
4019
4628
  }
4020
4629
  inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
4021
- const internal::string& regex) {
4630
+ const std::string& regex) {
4022
4631
  return ContainsRegex(new internal::RE(regex));
4023
4632
  }
4024
4633
 
@@ -4026,53 +4635,53 @@ inline PolymorphicMatcher<internal::MatchesRegexMatcher> ContainsRegex(
4026
4635
  // Wide string matchers.
4027
4636
 
4028
4637
  // Matches a string equal to str.
4029
- inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
4030
- StrEq(const internal::wstring& str) {
4031
- return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
4032
- str, true, true));
4638
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrEq(
4639
+ const std::wstring& str) {
4640
+ return MakePolymorphicMatcher(
4641
+ internal::StrEqualityMatcher<std::wstring>(str, true, true));
4033
4642
  }
4034
4643
 
4035
4644
  // Matches a string not equal to str.
4036
- inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
4037
- StrNe(const internal::wstring& str) {
4038
- return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
4039
- str, false, true));
4645
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> > StrNe(
4646
+ const std::wstring& str) {
4647
+ return MakePolymorphicMatcher(
4648
+ internal::StrEqualityMatcher<std::wstring>(str, false, true));
4040
4649
  }
4041
4650
 
4042
4651
  // Matches a string equal to str, ignoring case.
4043
- inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
4044
- StrCaseEq(const internal::wstring& str) {
4045
- return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
4046
- str, true, false));
4652
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
4653
+ StrCaseEq(const std::wstring& str) {
4654
+ return MakePolymorphicMatcher(
4655
+ internal::StrEqualityMatcher<std::wstring>(str, true, false));
4047
4656
  }
4048
4657
 
4049
4658
  // Matches a string not equal to str, ignoring case.
4050
- inline PolymorphicMatcher<internal::StrEqualityMatcher<internal::wstring> >
4051
- StrCaseNe(const internal::wstring& str) {
4052
- return MakePolymorphicMatcher(internal::StrEqualityMatcher<internal::wstring>(
4053
- str, false, false));
4659
+ inline PolymorphicMatcher<internal::StrEqualityMatcher<std::wstring> >
4660
+ StrCaseNe(const std::wstring& str) {
4661
+ return MakePolymorphicMatcher(
4662
+ internal::StrEqualityMatcher<std::wstring>(str, false, false));
4054
4663
  }
4055
4664
 
4056
- // Creates a matcher that matches any wstring, std::wstring, or C wide string
4665
+ // Creates a matcher that matches any ::wstring, std::wstring, or C wide string
4057
4666
  // that contains the given substring.
4058
- inline PolymorphicMatcher<internal::HasSubstrMatcher<internal::wstring> >
4059
- HasSubstr(const internal::wstring& substring) {
4060
- return MakePolymorphicMatcher(internal::HasSubstrMatcher<internal::wstring>(
4061
- substring));
4667
+ inline PolymorphicMatcher<internal::HasSubstrMatcher<std::wstring> > HasSubstr(
4668
+ const std::wstring& substring) {
4669
+ return MakePolymorphicMatcher(
4670
+ internal::HasSubstrMatcher<std::wstring>(substring));
4062
4671
  }
4063
4672
 
4064
4673
  // Matches a string that starts with 'prefix' (case-sensitive).
4065
- inline PolymorphicMatcher<internal::StartsWithMatcher<internal::wstring> >
4066
- StartsWith(const internal::wstring& prefix) {
4067
- return MakePolymorphicMatcher(internal::StartsWithMatcher<internal::wstring>(
4068
- prefix));
4674
+ inline PolymorphicMatcher<internal::StartsWithMatcher<std::wstring> >
4675
+ StartsWith(const std::wstring& prefix) {
4676
+ return MakePolymorphicMatcher(
4677
+ internal::StartsWithMatcher<std::wstring>(prefix));
4069
4678
  }
4070
4679
 
4071
4680
  // Matches a string that ends with 'suffix' (case-sensitive).
4072
- inline PolymorphicMatcher<internal::EndsWithMatcher<internal::wstring> >
4073
- EndsWith(const internal::wstring& suffix) {
4074
- return MakePolymorphicMatcher(internal::EndsWithMatcher<internal::wstring>(
4075
- suffix));
4681
+ inline PolymorphicMatcher<internal::EndsWithMatcher<std::wstring> > EndsWith(
4682
+ const std::wstring& suffix) {
4683
+ return MakePolymorphicMatcher(
4684
+ internal::EndsWithMatcher<std::wstring>(suffix));
4076
4685
  }
4077
4686
 
4078
4687
  #endif // GTEST_HAS_GLOBAL_WSTRING || GTEST_HAS_STD_WSTRING
@@ -4101,6 +4710,58 @@ inline internal::Lt2Matcher Lt() { return internal::Lt2Matcher(); }
4101
4710
  // first field != the second field.
4102
4711
  inline internal::Ne2Matcher Ne() { return internal::Ne2Matcher(); }
4103
4712
 
4713
+ // Creates a polymorphic matcher that matches a 2-tuple where
4714
+ // FloatEq(first field) matches the second field.
4715
+ inline internal::FloatingEq2Matcher<float> FloatEq() {
4716
+ return internal::FloatingEq2Matcher<float>();
4717
+ }
4718
+
4719
+ // Creates a polymorphic matcher that matches a 2-tuple where
4720
+ // DoubleEq(first field) matches the second field.
4721
+ inline internal::FloatingEq2Matcher<double> DoubleEq() {
4722
+ return internal::FloatingEq2Matcher<double>();
4723
+ }
4724
+
4725
+ // Creates a polymorphic matcher that matches a 2-tuple where
4726
+ // FloatEq(first field) matches the second field with NaN equality.
4727
+ inline internal::FloatingEq2Matcher<float> NanSensitiveFloatEq() {
4728
+ return internal::FloatingEq2Matcher<float>(true);
4729
+ }
4730
+
4731
+ // Creates a polymorphic matcher that matches a 2-tuple where
4732
+ // DoubleEq(first field) matches the second field with NaN equality.
4733
+ inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleEq() {
4734
+ return internal::FloatingEq2Matcher<double>(true);
4735
+ }
4736
+
4737
+ // Creates a polymorphic matcher that matches a 2-tuple where
4738
+ // FloatNear(first field, max_abs_error) matches the second field.
4739
+ inline internal::FloatingEq2Matcher<float> FloatNear(float max_abs_error) {
4740
+ return internal::FloatingEq2Matcher<float>(max_abs_error);
4741
+ }
4742
+
4743
+ // Creates a polymorphic matcher that matches a 2-tuple where
4744
+ // DoubleNear(first field, max_abs_error) matches the second field.
4745
+ inline internal::FloatingEq2Matcher<double> DoubleNear(double max_abs_error) {
4746
+ return internal::FloatingEq2Matcher<double>(max_abs_error);
4747
+ }
4748
+
4749
+ // Creates a polymorphic matcher that matches a 2-tuple where
4750
+ // FloatNear(first field, max_abs_error) matches the second field with NaN
4751
+ // equality.
4752
+ inline internal::FloatingEq2Matcher<float> NanSensitiveFloatNear(
4753
+ float max_abs_error) {
4754
+ return internal::FloatingEq2Matcher<float>(max_abs_error, true);
4755
+ }
4756
+
4757
+ // Creates a polymorphic matcher that matches a 2-tuple where
4758
+ // DoubleNear(first field, max_abs_error) matches the second field with NaN
4759
+ // equality.
4760
+ inline internal::FloatingEq2Matcher<double> NanSensitiveDoubleNear(
4761
+ double max_abs_error) {
4762
+ return internal::FloatingEq2Matcher<double>(max_abs_error, true);
4763
+ }
4764
+
4104
4765
  // Creates a matcher that matches any value of type T that m doesn't
4105
4766
  // match.
4106
4767
  template <typename InnerMatcher>
@@ -4283,6 +4944,128 @@ inline internal::ContainsMatcher<M> Contains(M matcher) {
4283
4944
  return internal::ContainsMatcher<M>(matcher);
4284
4945
  }
4285
4946
 
4947
+ // IsSupersetOf(iterator_first, iterator_last)
4948
+ // IsSupersetOf(pointer, count)
4949
+ // IsSupersetOf(array)
4950
+ // IsSupersetOf(container)
4951
+ // IsSupersetOf({e1, e2, ..., en})
4952
+ //
4953
+ // IsSupersetOf() verifies that a surjective partial mapping onto a collection
4954
+ // of matchers exists. In other words, a container matches
4955
+ // IsSupersetOf({e1, ..., en}) if and only if there is a permutation
4956
+ // {y1, ..., yn} of some of the container's elements where y1 matches e1,
4957
+ // ..., and yn matches en. Obviously, the size of the container must be >= n
4958
+ // in order to have a match. Examples:
4959
+ //
4960
+ // - {1, 2, 3} matches IsSupersetOf({Ge(3), Ne(0)}), as 3 matches Ge(3) and
4961
+ // 1 matches Ne(0).
4962
+ // - {1, 2} doesn't match IsSupersetOf({Eq(1), Lt(2)}), even though 1 matches
4963
+ // both Eq(1) and Lt(2). The reason is that different matchers must be used
4964
+ // for elements in different slots of the container.
4965
+ // - {1, 1, 2} matches IsSupersetOf({Eq(1), Lt(2)}), as (the first) 1 matches
4966
+ // Eq(1) and (the second) 1 matches Lt(2).
4967
+ // - {1, 2, 3} matches IsSupersetOf(Gt(1), Gt(1)), as 2 matches (the first)
4968
+ // Gt(1) and 3 matches (the second) Gt(1).
4969
+ //
4970
+ // The matchers can be specified as an array, a pointer and count, a container,
4971
+ // an initializer list, or an STL iterator range. In each of these cases, the
4972
+ // underlying matchers can be either values or matchers.
4973
+
4974
+ template <typename Iter>
4975
+ inline internal::UnorderedElementsAreArrayMatcher<
4976
+ typename ::std::iterator_traits<Iter>::value_type>
4977
+ IsSupersetOf(Iter first, Iter last) {
4978
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
4979
+ return internal::UnorderedElementsAreArrayMatcher<T>(
4980
+ internal::UnorderedMatcherRequire::Superset, first, last);
4981
+ }
4982
+
4983
+ template <typename T>
4984
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4985
+ const T* pointer, size_t count) {
4986
+ return IsSupersetOf(pointer, pointer + count);
4987
+ }
4988
+
4989
+ template <typename T, size_t N>
4990
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
4991
+ const T (&array)[N]) {
4992
+ return IsSupersetOf(array, N);
4993
+ }
4994
+
4995
+ template <typename Container>
4996
+ inline internal::UnorderedElementsAreArrayMatcher<
4997
+ typename Container::value_type>
4998
+ IsSupersetOf(const Container& container) {
4999
+ return IsSupersetOf(container.begin(), container.end());
5000
+ }
5001
+
5002
+ #if GTEST_HAS_STD_INITIALIZER_LIST_
5003
+ template <typename T>
5004
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSupersetOf(
5005
+ ::std::initializer_list<T> xs) {
5006
+ return IsSupersetOf(xs.begin(), xs.end());
5007
+ }
5008
+ #endif
5009
+
5010
+ // IsSubsetOf(iterator_first, iterator_last)
5011
+ // IsSubsetOf(pointer, count)
5012
+ // IsSubsetOf(array)
5013
+ // IsSubsetOf(container)
5014
+ // IsSubsetOf({e1, e2, ..., en})
5015
+ //
5016
+ // IsSubsetOf() verifies that an injective mapping onto a collection of matchers
5017
+ // exists. In other words, a container matches IsSubsetOf({e1, ..., en}) if and
5018
+ // only if there is a subset of matchers {m1, ..., mk} which would match the
5019
+ // container using UnorderedElementsAre. Obviously, the size of the container
5020
+ // must be <= n in order to have a match. Examples:
5021
+ //
5022
+ // - {1} matches IsSubsetOf({Gt(0), Lt(0)}), as 1 matches Gt(0).
5023
+ // - {1, -1} matches IsSubsetOf({Lt(0), Gt(0)}), as 1 matches Gt(0) and -1
5024
+ // matches Lt(0).
5025
+ // - {1, 2} doesn't matches IsSubsetOf({Gt(0), Lt(0)}), even though 1 and 2 both
5026
+ // match Gt(0). The reason is that different matchers must be used for
5027
+ // elements in different slots of the container.
5028
+ //
5029
+ // The matchers can be specified as an array, a pointer and count, a container,
5030
+ // an initializer list, or an STL iterator range. In each of these cases, the
5031
+ // underlying matchers can be either values or matchers.
5032
+
5033
+ template <typename Iter>
5034
+ inline internal::UnorderedElementsAreArrayMatcher<
5035
+ typename ::std::iterator_traits<Iter>::value_type>
5036
+ IsSubsetOf(Iter first, Iter last) {
5037
+ typedef typename ::std::iterator_traits<Iter>::value_type T;
5038
+ return internal::UnorderedElementsAreArrayMatcher<T>(
5039
+ internal::UnorderedMatcherRequire::Subset, first, last);
5040
+ }
5041
+
5042
+ template <typename T>
5043
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
5044
+ const T* pointer, size_t count) {
5045
+ return IsSubsetOf(pointer, pointer + count);
5046
+ }
5047
+
5048
+ template <typename T, size_t N>
5049
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
5050
+ const T (&array)[N]) {
5051
+ return IsSubsetOf(array, N);
5052
+ }
5053
+
5054
+ template <typename Container>
5055
+ inline internal::UnorderedElementsAreArrayMatcher<
5056
+ typename Container::value_type>
5057
+ IsSubsetOf(const Container& container) {
5058
+ return IsSubsetOf(container.begin(), container.end());
5059
+ }
5060
+
5061
+ #if GTEST_HAS_STD_INITIALIZER_LIST_
5062
+ template <typename T>
5063
+ inline internal::UnorderedElementsAreArrayMatcher<T> IsSubsetOf(
5064
+ ::std::initializer_list<T> xs) {
5065
+ return IsSubsetOf(xs.begin(), xs.end());
5066
+ }
5067
+ #endif
5068
+
4286
5069
  // Matches an STL-style container or a native array that contains only
4287
5070
  // elements matching the given value or matcher.
4288
5071
  //
@@ -4356,19 +5139,58 @@ inline bool ExplainMatchResult(
4356
5139
  return SafeMatcherCast<const T&>(matcher).MatchAndExplain(value, listener);
4357
5140
  }
4358
5141
 
5142
+ // Returns a string representation of the given matcher. Useful for description
5143
+ // strings of matchers defined using MATCHER_P* macros that accept matchers as
5144
+ // their arguments. For example:
5145
+ //
5146
+ // MATCHER_P(XAndYThat, matcher,
5147
+ // "X that " + DescribeMatcher<int>(matcher, negation) +
5148
+ // " and Y that " + DescribeMatcher<double>(matcher, negation)) {
5149
+ // return ExplainMatchResult(matcher, arg.x(), result_listener) &&
5150
+ // ExplainMatchResult(matcher, arg.y(), result_listener);
5151
+ // }
5152
+ template <typename T, typename M>
5153
+ std::string DescribeMatcher(const M& matcher, bool negation = false) {
5154
+ ::std::stringstream ss;
5155
+ Matcher<T> monomorphic_matcher = SafeMatcherCast<T>(matcher);
5156
+ if (negation) {
5157
+ monomorphic_matcher.DescribeNegationTo(&ss);
5158
+ } else {
5159
+ monomorphic_matcher.DescribeTo(&ss);
5160
+ }
5161
+ return ss.str();
5162
+ }
5163
+
4359
5164
  #if GTEST_LANG_CXX11
4360
5165
  // Define variadic matcher versions. They are overloaded in
4361
5166
  // gmock-generated-matchers.h for the cases supported by pre C++11 compilers.
4362
5167
  template <typename... Args>
4363
- inline internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
5168
+ internal::AllOfMatcher<Args...> AllOf(const Args&... matchers) {
4364
5169
  return internal::AllOfMatcher<Args...>(matchers...);
4365
5170
  }
4366
5171
 
4367
5172
  template <typename... Args>
4368
- inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
5173
+ internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
4369
5174
  return internal::AnyOfMatcher<Args...>(matchers...);
4370
5175
  }
4371
5176
 
5177
+ template <typename... Args>
5178
+ internal::ElementsAreMatcher<tuple<typename std::decay<const Args&>::type...>>
5179
+ ElementsAre(const Args&... matchers) {
5180
+ return internal::ElementsAreMatcher<
5181
+ tuple<typename std::decay<const Args&>::type...>>(
5182
+ make_tuple(matchers...));
5183
+ }
5184
+
5185
+ template <typename... Args>
5186
+ internal::UnorderedElementsAreMatcher<
5187
+ tuple<typename std::decay<const Args&>::type...>>
5188
+ UnorderedElementsAre(const Args&... matchers) {
5189
+ return internal::UnorderedElementsAreMatcher<
5190
+ tuple<typename std::decay<const Args&>::type...>>(
5191
+ make_tuple(matchers...));
5192
+ }
5193
+
4372
5194
  #endif // GTEST_LANG_CXX11
4373
5195
 
4374
5196
  // AllArgs(m) is a synonym of m. This is useful in
@@ -4381,6 +5203,39 @@ inline internal::AnyOfMatcher<Args...> AnyOf(const Args&... matchers) {
4381
5203
  template <typename InnerMatcher>
4382
5204
  inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
4383
5205
 
5206
+ // Returns a matcher that matches the value of an optional<> type variable.
5207
+ // The matcher implementation only uses '!arg' and requires that the optional<>
5208
+ // type has a 'value_type' member type and that '*arg' is of type 'value_type'
5209
+ // and is printable using 'PrintToString'. It is compatible with
5210
+ // std::optional/std::experimental::optional.
5211
+ // Note that to compare an optional type variable against nullopt you should
5212
+ // use Eq(nullopt) and not Optional(Eq(nullopt)). The latter implies that the
5213
+ // optional value contains an optional itself.
5214
+ template <typename ValueMatcher>
5215
+ inline internal::OptionalMatcher<ValueMatcher> Optional(
5216
+ const ValueMatcher& value_matcher) {
5217
+ return internal::OptionalMatcher<ValueMatcher>(value_matcher);
5218
+ }
5219
+
5220
+ // Returns a matcher that matches the value of a absl::any type variable.
5221
+ template <typename T>
5222
+ PolymorphicMatcher<internal::any_cast_matcher::AnyCastMatcher<T> > AnyWith(
5223
+ const Matcher<const T&>& matcher) {
5224
+ return MakePolymorphicMatcher(
5225
+ internal::any_cast_matcher::AnyCastMatcher<T>(matcher));
5226
+ }
5227
+
5228
+ // Returns a matcher that matches the value of a variant<> type variable.
5229
+ // The matcher implementation uses ADL to find the holds_alternative and get
5230
+ // functions.
5231
+ // It is compatible with std::variant.
5232
+ template <typename T>
5233
+ PolymorphicMatcher<internal::variant_matcher::VariantMatcher<T> > VariantWith(
5234
+ const Matcher<const T&>& matcher) {
5235
+ return MakePolymorphicMatcher(
5236
+ internal::variant_matcher::VariantMatcher<T>(matcher));
5237
+ }
5238
+
4384
5239
  // These macros allow using matchers to check values in Google Test
4385
5240
  // tests. ASSERT_THAT(value, matcher) and EXPECT_THAT(value, matcher)
4386
5241
  // succeed iff the value matches the matcher. If the assertion fails,
@@ -4396,4 +5251,5 @@ inline InnerMatcher AllArgs(const InnerMatcher& matcher) { return matcher; }
4396
5251
  // We must include this header at the end to make sure it can use the
4397
5252
  // declarations from this file.
4398
5253
  #include "gmock/internal/custom/gmock-matchers.h"
5254
+
4399
5255
  #endif // GMOCK_INCLUDE_GMOCK_GMOCK_MATCHERS_H_