#include #include #include TEST(Any, Assign) { sled::Any any1; sled::Any any2(any1); sled::Any any3(1); sled::Any any4(any3); sled::Any any5 = 1; EXPECT_FALSE(any1.HasValue()); EXPECT_FALSE(any2.HasValue()); EXPECT_TRUE(any3.HasValue()); EXPECT_TRUE(any4.HasValue()); EXPECT_TRUE(any5.HasValue()); EXPECT_EQ(any3.Cast(), 1); EXPECT_EQ(any4.Cast(), 1); EXPECT_EQ(any5.Cast(), 1); EXPECT_EQ(any3.CastOr("def"), "def"); EXPECT_EQ(any4.CastOr("def"), "def"); EXPECT_EQ(any5.CastOr("def"), "def"); EXPECT_EQ(any3.CastOr(11), 1); } TEST(Any, std_swap) { sled::Any a; sled::Any b = 2; EXPECT_FALSE(a.HasValue()); EXPECT_TRUE(b.HasValue()); std::swap(a, b); EXPECT_TRUE(a.HasValue()); EXPECT_FALSE(b.HasValue()); EXPECT_EQ(a.Cast(), 2); } TEST(Any, custom_swap) { sled::Any a; sled::Any b = 2; EXPECT_FALSE(a.HasValue()); EXPECT_TRUE(b.HasValue()); a.swap(b); EXPECT_TRUE(a.HasValue()); EXPECT_FALSE(b.HasValue()); EXPECT_EQ(a.Cast(), 2); }