decompose_test.cpp 929 B

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. #include "explorer/base/decompose.h"
  5. #include <gtest/gtest.h>
  6. namespace Carbon {
  7. namespace {
  8. struct Decomposeable : public HashFromDecompose<Decomposeable> {
  9. template <typename F>
  10. auto Decompose(F f) const {
  11. return f(i, s);
  12. }
  13. int i = 0;
  14. std::string s;
  15. };
  16. TEST(HashFromDecomposeTest, EqualValues) {
  17. Decomposeable d1 = {.i = 42, .s = "foo"};
  18. Decomposeable d2 = {.i = 42, .s = "foo"};
  19. EXPECT_TRUE(d1 == d2);
  20. EXPECT_TRUE(hash_value(d1) == hash_value(d2));
  21. }
  22. TEST(HashFromDecomposeTest, NonEqualValues) {
  23. Decomposeable d1 = {.i = 42, .s = "foo"};
  24. Decomposeable d2 = {.i = 42, .s = "bar"};
  25. EXPECT_FALSE(d1 == d2);
  26. EXPECT_FALSE(hash_value(d1) == hash_value(d2));
  27. }
  28. } // namespace
  29. } // namespace Carbon