binary_operator_test_matchers.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_SEMANTICS_NODES_BINARY_OPERATOR_TEST_MATCHERS_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_NODES_BINARY_OPERATOR_TEST_MATCHERS_H_
  6. #include <gmock/gmock.h>
  7. #include "llvm/ADT/StringExtras.h"
  8. #include "toolchain/semantics/nodes/binary_operator.h"
  9. #include "toolchain/semantics/semantics_ir_for_test.h"
  10. namespace Carbon::Testing {
  11. MATCHER_P4(
  12. BinaryOperator, id_matcher, op_matcher, lhs_id_matcher, rhs_id_matcher,
  13. llvm::formatv(
  14. "BinaryOperator(%{0}, {1}, %{2}, %{3})",
  15. ::testing::DescribeMatcher<int32_t>(id_matcher),
  16. ::testing::DescribeMatcher<Semantics::BinaryOperator::Op>(op_matcher),
  17. ::testing::DescribeMatcher<int32_t>(lhs_id_matcher),
  18. ::testing::DescribeMatcher<int32_t>(rhs_id_matcher))) {
  19. const Semantics::NodeRef& node_ref = arg;
  20. if (auto op =
  21. SemanticsIRForTest::GetNode<Semantics::BinaryOperator>(node_ref)) {
  22. return ExplainMatchResult(id_matcher, op->id(), result_listener) &&
  23. ExplainMatchResult(op_matcher, op->op(), result_listener) &&
  24. ExplainMatchResult(lhs_id_matcher, op->lhs_id(), result_listener) &&
  25. ExplainMatchResult(rhs_id_matcher, op->rhs_id(), result_listener);
  26. } else {
  27. *result_listener << "node is not a BinaryOperator";
  28. return result_listener;
  29. }
  30. }
  31. } // namespace Carbon::Testing
  32. #endif // CARBON_TOOLCHAIN_SEMANTICS_NODES_BINARY_OPERATOR_TEST_MATCHERS_H_