function_test_matchers.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  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_FUNCTION_TEST_MATCHERS_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_NODES_FUNCTION_TEST_MATCHERS_H_
  6. #include <gmock/gmock.h>
  7. #include "llvm/ADT/StringExtras.h"
  8. #include "toolchain/semantics/nodes/function.h"
  9. #include "toolchain/semantics/semantics_ir_for_test.h"
  10. namespace Carbon::Testing {
  11. MATCHER_P2(Function, id_matcher, body_matcher,
  12. llvm::formatv(
  13. "Function(%{0}, {1})",
  14. ::testing::DescribeMatcher<int32_t>(id_matcher),
  15. ::testing::DescribeMatcher<llvm::ArrayRef<Semantics::NodeRef>>(
  16. body_matcher))) {
  17. const Semantics::NodeRef& node_ref = arg;
  18. if (auto function =
  19. SemanticsIRForTest::GetNode<Semantics::Function>(node_ref)) {
  20. return ExplainMatchResult(id_matcher, function->id(), result_listener) &&
  21. ExplainMatchResult(body_matcher, function->body(), result_listener);
  22. } else {
  23. *result_listener << "node is not a Function";
  24. return result_listener;
  25. }
  26. }
  27. } // namespace Carbon::Testing
  28. #endif // CARBON_TOOLCHAIN_SEMANTICS_NODES_FUNCTION_TEST_MATCHERS_H_