value_store_test.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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 "toolchain/base/value_store.h"
  5. #include <gmock/gmock.h>
  6. #include <gtest/gtest.h>
  7. #include <string>
  8. #include "toolchain/base/value_ids.h"
  9. namespace Carbon::Testing {
  10. namespace {
  11. using ::testing::Eq;
  12. using ::testing::Not;
  13. TEST(ValueStore, Real) {
  14. Real real1{.mantissa = llvm::APInt(64, 1),
  15. .exponent = llvm::APInt(64, 11),
  16. .is_decimal = true};
  17. Real real2{.mantissa = llvm::APInt(64, 2),
  18. .exponent = llvm::APInt(64, 22),
  19. .is_decimal = false};
  20. ValueStore<RealId, Real> reals;
  21. RealId id1 = reals.Add(real1);
  22. RealId id2 = reals.Add(real2);
  23. ASSERT_TRUE(id1.has_value());
  24. ASSERT_TRUE(id2.has_value());
  25. EXPECT_THAT(id1, Not(Eq(id2)));
  26. const auto& real1_copy = reals.Get(id1);
  27. EXPECT_THAT(real1.mantissa, Eq(real1_copy.mantissa));
  28. EXPECT_THAT(real1.exponent, Eq(real1_copy.exponent));
  29. EXPECT_THAT(real1.is_decimal, Eq(real1_copy.is_decimal));
  30. const auto& real2_copy = reals.Get(id2);
  31. EXPECT_THAT(real2.mantissa, Eq(real2_copy.mantissa));
  32. EXPECT_THAT(real2.exponent, Eq(real2_copy.exponent));
  33. EXPECT_THAT(real2.is_decimal, Eq(real2_copy.is_decimal));
  34. }
  35. } // namespace
  36. } // namespace Carbon::Testing