// Part of the Crubit project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "lifetime_analysis/object_set.h"

#include <optional>

#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "lifetime_analysis/object.h"
#include "lifetime_annotations/lifetime.h"
#include "lifetime_annotations/lifetime_annotations.h"
#include "lifetime_annotations/test/run_on_code.h"
#include "clang/AST/ASTContext.h"

namespace clang {
namespace tidy {
namespace lifetimes {
namespace {

using testing::UnorderedElementsAre;

TEST(ObjectSet, AccessObjects) {
  runOnCodeWithLifetimeHandlers(
      "",
      [](const clang::ASTContext& ast_context,
         const LifetimeAnnotationContext&) {
        Object object_static(Lifetime::Static(), ast_context.IntTy,
                             std::nullopt);
        ObjectSet object_set = {&object_static};

        EXPECT_THAT(object_set, UnorderedElementsAre(&object_static));
      },
      {});
}

TEST(ObjectSet, Contains) {
  runOnCodeWithLifetimeHandlers(
      "",
      [](const clang::ASTContext& ast_context,
         const LifetimeAnnotationContext&) {
        Object o1(Lifetime::CreateLocal(), ast_context.IntTy, std::nullopt);
        Object o2(Lifetime::CreateLocal(), ast_context.IntTy, std::nullopt);

        EXPECT_TRUE(ObjectSet({&o1, &o2}).Contains(&o1));
        EXPECT_TRUE(ObjectSet({&o1, &o2}).Contains(&o2));
        EXPECT_FALSE(ObjectSet({&o1}).Contains(&o2));

        EXPECT_TRUE(ObjectSet({&o1, &o2}).Contains(ObjectSet()));
        EXPECT_TRUE(ObjectSet({&o1, &o2}).Contains(ObjectSet{&o1}));
        EXPECT_TRUE(ObjectSet({&o1, &o2}).Contains(ObjectSet{&o2}));
        EXPECT_TRUE(ObjectSet({&o1, &o2}).Contains({&o1, &o2}));
        EXPECT_TRUE(ObjectSet({&o1}).Contains(ObjectSet{&o1}));
        EXPECT_FALSE(ObjectSet({&o1}).Contains(ObjectSet{&o2}));
        EXPECT_TRUE(ObjectSet().Contains(ObjectSet()));
      },
      {});
}

TEST(ObjectSet, Union) {
  runOnCodeWithLifetimeHandlers(
      "",
      [](const clang::ASTContext& ast_context,
         const LifetimeAnnotationContext&) {
        Object object_static(Lifetime::Static(), ast_context.IntTy,
                             std::nullopt);
        ObjectSet set_1 = {&object_static};
        Object object_local(Lifetime::CreateLocal(), ast_context.IntTy,
                            std::nullopt);
        ObjectSet set_2 = {&object_local};

        ObjectSet set_union = set_1.Union(set_2);

        EXPECT_THAT(set_union,
                    UnorderedElementsAre(&object_static, &object_local));
      },
      {});
}

TEST(ObjectSet, Add) {
  runOnCodeWithLifetimeHandlers(
      "",
      [](const clang::ASTContext& ast_context,
         const LifetimeAnnotationContext&) {
        Object o1(Lifetime::CreateLocal(), ast_context.IntTy, std::nullopt);
        Object o2(Lifetime::CreateLocal(), ast_context.IntTy, std::nullopt);
        Object o3(Lifetime::CreateLocal(), ast_context.IntTy, std::nullopt);

        {
          ObjectSet object_set = {&o1};
          object_set.Add(&o2);
          EXPECT_THAT(object_set, UnorderedElementsAre(&o1, &o2));
        }
        {
          ObjectSet object_set = {&o1, &o2};
          object_set.Add(&o2);
          EXPECT_THAT(object_set, UnorderedElementsAre(&o1, &o2));
        }
        {
          ObjectSet object_set = {&o1};
          object_set.Add({&o2, &o3});
          EXPECT_THAT(object_set, UnorderedElementsAre(&o1, &o2, &o3));
        }
        {
          ObjectSet object_set = {&o1, &o2};
          object_set.Add({&o2, &o3});
          EXPECT_THAT(object_set, UnorderedElementsAre(&o1, &o2, &o3));
        }
      },
      {});
}

TEST(ObjectSet, Equality) {
  runOnCodeWithLifetimeHandlers(
      "",
      [](const clang::ASTContext& ast_context,
         const LifetimeAnnotationContext&) {
        Object object_static(Lifetime::Static(), ast_context.IntTy,
                             std::nullopt);
        Object object_local(Lifetime::CreateLocal(), ast_context.IntTy,
                            std::nullopt);
        ObjectSet set_1 = {&object_static};
        ObjectSet set_2 = {&object_static};
        ObjectSet set_3 = {&object_static, &object_local};

        EXPECT_EQ(set_1, set_2);
        EXPECT_NE(set_1, set_3);
      },
      {});
}

}  // namespace
}  // namespace lifetimes
}  // namespace tidy
}  // namespace clang
