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