set_name_test_matchers.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  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_SET_NAME_TEST_MATCHERS_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_NODES_SET_NAME_TEST_MATCHERS_H_
  6. #include <gmock/gmock.h>
  7. #include "llvm/ADT/StringExtras.h"
  8. #include "toolchain/semantics/nodes/set_name.h"
  9. #include "toolchain/semantics/semantics_ir_for_test.h"
  10. namespace Carbon::Testing {
  11. MATCHER_P2(
  12. SetName, name_matcher, target_id_matcher,
  13. llvm::formatv("SetName(`{0}`, %`{1}`)",
  14. ::testing::DescribeMatcher<llvm::StringRef>(name_matcher),
  15. ::testing::DescribeMatcher<int32_t>(target_id_matcher))) {
  16. const Semantics::NodeRef& node_ref = arg;
  17. if (auto node = SemanticsIRForTest::GetNode<Semantics::SetName>(node_ref)) {
  18. return ExplainMatchResult(name_matcher, node->name(), result_listener) &&
  19. ExplainMatchResult(target_id_matcher, node->target_id(),
  20. result_listener);
  21. } else {
  22. *result_listener << "node is not a SetName";
  23. return result_listener;
  24. }
  25. }
  26. } // namespace Carbon::Testing
  27. #endif // CARBON_TOOLCHAIN_SEMANTICS_NODES_SET_NAME_TEST_MATCHERS_H_