|
|
|
@ -33,7 +33,7 @@ TEST(Variant, EmptyCTor) |
|
|
|
|
EXPECT_EQ("", util::get<std::string>(vsi)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(Variant, ValueMoveCTor) |
|
|
|
|
TEST(Variant, ConvertingCTorMove) |
|
|
|
|
{ |
|
|
|
|
util::variant<int> vi(42); |
|
|
|
|
EXPECT_EQ(0u, vi.index()); |
|
|
|
@ -55,16 +55,23 @@ TEST(Variant, ValueMoveCTor) |
|
|
|
|
EXPECT_EQ(0u, vsi.index()); |
|
|
|
|
EXPECT_EQ("2017", util::get<std::string>(vsi)); |
|
|
|
|
|
|
|
|
|
std::string rvs("2017"); |
|
|
|
|
util::variant<std::string, int> vsi3(std::move(rvs)); |
|
|
|
|
EXPECT_EQ(0u, vsi3.index()); |
|
|
|
|
EXPECT_EQ("2017", util::get<std::string>(vsi3)); |
|
|
|
|
EXPECT_EQ("", rvs) <<"Rvalue source argument was not moved from while should?"; |
|
|
|
|
|
|
|
|
|
util::variant<std::string, int> vsi2(42); |
|
|
|
|
EXPECT_EQ(1u, vsi2.index()); |
|
|
|
|
EXPECT_EQ(42, util::get<int>(vsi2)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(Variant, ValueCopyCTor) |
|
|
|
|
TEST(Variant, ConvertingCTorCopy) |
|
|
|
|
{ |
|
|
|
|
const int i42 = 42; |
|
|
|
|
const int i17 = 2017; |
|
|
|
|
const std::string s17 = "2017"; |
|
|
|
|
std::string s17_lvref = s17; |
|
|
|
|
|
|
|
|
|
util::variant<int> vi(i42); |
|
|
|
|
EXPECT_EQ(0u, vi.index()); |
|
|
|
@ -82,6 +89,11 @@ TEST(Variant, ValueCopyCTor) |
|
|
|
|
EXPECT_EQ(0u, vs.index()); |
|
|
|
|
EXPECT_EQ(s17, util::get<std::string>(vs)); |
|
|
|
|
|
|
|
|
|
util::variant<std::string> vs_lv(s17_lvref); |
|
|
|
|
EXPECT_EQ(0u, vs_lv.index()); |
|
|
|
|
EXPECT_EQ(s17, s17_lvref); |
|
|
|
|
EXPECT_EQ(s17_lvref, util::get<std::string>(vs_lv)); |
|
|
|
|
|
|
|
|
|
util::variant<std::string, int> vsi(s17); |
|
|
|
|
EXPECT_EQ(0u, vsi.index()); |
|
|
|
|
EXPECT_EQ(s17, util::get<std::string>(vsi)); |
|
|
|
@ -151,6 +163,20 @@ TEST(Variant, Assign_ValueUpdate_DiffType) |
|
|
|
|
EXPECT_EQ("42", util::get<std::string>(vis)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(Variant, Assign_RValueRef_DiffType) |
|
|
|
|
{ |
|
|
|
|
TestVar vis(42); |
|
|
|
|
|
|
|
|
|
EXPECT_EQ(0u, vis.index()); |
|
|
|
|
EXPECT_EQ(42, util::get<int>(vis)); |
|
|
|
|
|
|
|
|
|
std::string s("42"); |
|
|
|
|
vis = std::move(s); |
|
|
|
|
EXPECT_EQ(1u, vis.index()); |
|
|
|
|
EXPECT_EQ("42", util::get<std::string>(vis)); |
|
|
|
|
EXPECT_EQ("", s) << "right hand side argument of assignment operation was not moved from while should?";; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(Variant, Assign_LValueRef_DiffType) |
|
|
|
|
{ |
|
|
|
|
TestVar vis(42); |
|
|
|
@ -162,6 +188,7 @@ TEST(Variant, Assign_LValueRef_DiffType) |
|
|
|
|
vis = s; |
|
|
|
|
EXPECT_EQ(1u, vis.index()); |
|
|
|
|
EXPECT_EQ("42", util::get<std::string>(vis)); |
|
|
|
|
EXPECT_EQ("42", s) << "right hand side argument of assignment operation was moved from while should not ?"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(Variant, Assign_ValueUpdate_Const) |
|
|
|
@ -198,7 +225,7 @@ TEST(Variant, Assign_ValueUpdate_Const_DiffType) |
|
|
|
|
EXPECT_EQ("42", util::get<std::string>(va)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
TEST(Variant, Assign_Move) |
|
|
|
|
TEST(Variant, Assign_Move_Variant) |
|
|
|
|
{ |
|
|
|
|
TestVar va(42); |
|
|
|
|
TestVar vb(std::string("42")); |
|
|
|
|