#include <stdplus/pinned.hpp>

#include <string>

#include <gtest/gtest.h>

namespace stdplus
{

static_assert(noexcept(Pinned<int>(4)));
static_assert(!noexcept(Pinned<std::string>("4")));

TEST(Pinned, Basic)
{
    EXPECT_EQ("hi", Pinned<std::string>("hi"));
    EXPECT_EQ("hi", Pinned(std::string("hi")));
    auto s = std::string("hi");
    EXPECT_EQ("hi", Pinned(s));
    EXPECT_EQ("hi", Pinned(std::move(s)));
    Pinned<std::string> ps = "hi";
    EXPECT_EQ("hi", Pinned<std::string>(ps));
    // EXPECT_EQ("hi", Pinned<std::string>(std::move(ps)));
    ps = "hi";
    EXPECT_EQ("hi", ps);
    s = std::string("hi");
    ps = s;
    EXPECT_EQ("hi", ps);
    ps = std::move(s);
    EXPECT_EQ("hi", ps);
    Pinned<std::string> ps2;
    ps2 = ps;
    EXPECT_EQ("hi", ps2);
    // ps2 = std::move(ps);
    // std::string s2 = std::move(ps2);
    EXPECT_EQ("hi", [](std::string& f) { return f; }(ps2));
    EXPECT_EQ("hi", [](std::string f) { return f; }(ps2));
}

TEST(Pinned, Fundamental)
{
    Pinned pi = 4;
    // NOLINTNEXTLINE(clang-analyzer-core.uninitialized.UndefReturn)
    EXPECT_EQ(4, [](int& f) { return f; }(pi));
    EXPECT_EQ(4, [](int f) { return f; }(pi));
}

struct NoMove1
{
    NoMove1() = default;
    NoMove1(NoMove1&&) = delete;
    NoMove1& operator=(NoMove1&&) = default;
};

struct NoMove2
{
    NoMove2() = default;
    NoMove2(NoMove2&&) = default;
    NoMove2& operator=(NoMove2&&) = delete;
};

struct NoMove3
{
    NoMove3() = default;
    NoMove3(NoMove3&&) = delete;
    NoMove3& operator=(NoMove3&&) = delete;
};

TEST(PinnedRef, Basic)
{
    Pinned<std::string> pstr("hi");
    EXPECT_EQ("hi", PinnedRef<std::string>(pstr).get());
    EXPECT_EQ("hi", PinnedRef<const std::string>(pstr).get());
    EXPECT_EQ("hi", PinnedRef(pstr).get());

    const Pinned<std::string> cpstr("hi");
    // EXPECT_EQ("hi", PinnedRef<std::string>(cpstr).get());
    EXPECT_EQ("hi", PinnedRef<const std::string>(cpstr).get());
    EXPECT_EQ("hi", PinnedRef(cpstr).get());
}

TEST(PinnedRef, Fundamental)
{
    Pinned<int> pi = 4;
    EXPECT_EQ(4, PinnedRef<int>(pi));
    EXPECT_EQ(4, PinnedRef<const int>(pi));
    EXPECT_EQ(4, PinnedRef(pi));

    const Pinned<int> cpi = 4;
    // EXPECT_EQ(4, PinnedRef<int>(cpi));
    EXPECT_EQ(4, PinnedRef<const int>(cpi));
    EXPECT_EQ(4, PinnedRef(cpi));
}

TEST(PinnedRef, NoMove)
{
    // int i;
    // PinnedRef<int> ri(i);
    // NoMove1 nm1;
    // PinnedRef<NoMove1> rnm1(nm1);
    // NoMove2 nm2;
    // PinnedRef<NoMove2> rnm2(nm2);

    NoMove3 nm3;
    PinnedRef<NoMove3> rnm3(nm3);
    PinnedRef<const NoMove3> rnm3c(nm3);
    PinnedRef<const NoMove3> rnm3cr(rnm3);
    PinnedRef rnm3i(nm3);
    [[maybe_unused]] PinnedRef rnm3ir(rnm3);
    [[maybe_unused]] PinnedRef rnm3ic(rnm3c);

    const NoMove3 cnm3;
    // PinnedRef<NoMove3> crnm3(cnm3);
    PinnedRef<const NoMove3> crnm3c(cnm3);
    PinnedRef crnm3i(cnm3);
}

} // namespace stdplus
