semantics_ir_test_helpers.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_SEMANTICS_IR_TEST_HELPERS_H_
  5. #define CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_TEST_HELPERS_H_
  6. #include <gmock/gmock.h>
  7. #include <gtest/gtest.h>
  8. #include "common/check.h"
  9. #include "common/ostream.h"
  10. #include "llvm/ADT/StringExtras.h"
  11. #include "toolchain/semantics/nodes/declared_name_test_matchers.h"
  12. #include "toolchain/semantics/nodes/function_test_matchers.h"
  13. #include "toolchain/semantics/nodes/infix_operator_test_matchers.h"
  14. #include "toolchain/semantics/nodes/literal_test_matchers.h"
  15. #include "toolchain/semantics/nodes/pattern_binding_test_matchers.h"
  16. #include "toolchain/semantics/nodes/return_test_matchers.h"
  17. #include "toolchain/semantics/semantics_ir_for_test.h"
  18. namespace Carbon::Testing {
  19. // TODO: Relocate these matchers.
  20. inline auto MappedNode(::testing::Matcher<std::string> key,
  21. ::testing::Matcher<Semantics::Declaration> value)
  22. -> ::testing::Matcher<llvm::StringMapEntry<Semantics::Declaration>> {
  23. return ::testing::AllOf(
  24. ::testing::Property(
  25. "key", &llvm::StringMapEntry<Semantics::Declaration>::getKey, key),
  26. ::testing::Property(
  27. "value", &llvm::StringMapEntry<Semantics::Declaration>::getValue,
  28. value));
  29. }
  30. // Avoids gtest confusion of how to print llvm::None.
  31. MATCHER(IsNone, "is llvm::None") { return arg == llvm::None; }
  32. inline auto StatementBlock(
  33. ::testing::Matcher<llvm::ArrayRef<Semantics::Statement>> nodes_matcher,
  34. ::testing::Matcher<llvm::StringMap<Semantics::Statement>>
  35. name_lookup_matcher) -> ::testing::Matcher<Semantics::StatementBlock> {
  36. return ::testing::AllOf(
  37. ::testing::Property("nodes", &Semantics::StatementBlock::nodes,
  38. nodes_matcher),
  39. ::testing::Property("name_lookup",
  40. &Semantics::StatementBlock::name_lookup,
  41. name_lookup_matcher));
  42. }
  43. } // namespace Carbon::Testing
  44. #endif // CARBON_TOOLCHAIN_SEMANTICS_SEMANTICS_IR_TEST_HELPERS_H_