diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2021-05-22 09:46:40 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-05-22 09:34:31 +0200 |
commit | 6b4d7b6c19e81c4ee6b635ca4d2f145f38e96d01 (patch) | |
tree | 416f4dbb012f830ca804f03c53872cdc1dbd18a2 /Tests/AK | |
parent | 3f350c3b65eed61c1fe4ec364debe890199deffd (diff) | |
download | serenity-6b4d7b6c19e81c4ee6b635ca4d2f145f38e96d01.zip |
AK: Fix Variant construction from lvalue references
Fixes #7371 and appends its test cases.
Diffstat (limited to 'Tests/AK')
-rw-r--r-- | Tests/AK/TestVariant.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/Tests/AK/TestVariant.cpp b/Tests/AK/TestVariant.cpp index 28dc92340c..547ec3db24 100644 --- a/Tests/AK/TestVariant.cpp +++ b/Tests/AK/TestVariant.cpp @@ -172,3 +172,44 @@ TEST_CASE(return_values_by_reference) EXPECT_EQ(ref->ref_count(), 1u); EXPECT_EQ(value->ref_count(), 1u); } + +struct HoldsInt { + int i; +}; +struct HoldsFloat { + float f; +}; + +TEST_CASE(copy_assign) +{ + { + Variant<int, String, float> the_value { 42.0f }; + + VERIFY(the_value.has<float>()); + EXPECT_EQ(the_value.get<float>(), 42.0f); + + int twelve = 12; + the_value = twelve; + VERIFY(the_value.has<int>()); + EXPECT_EQ(the_value.get<int>(), 12); + + the_value = String("Hello, world!"); + VERIFY(the_value.has<String>()); + EXPECT_EQ(the_value.get<String>(), "Hello, world!"); + } + { + Variant<HoldsInt, String, HoldsFloat> the_value { HoldsFloat { 42.0f } }; + + VERIFY(the_value.has<HoldsFloat>()); + EXPECT_EQ(the_value.get<HoldsFloat>().f, 42.0f); + + HoldsInt twelve { 12 }; + the_value = twelve; + VERIFY(the_value.has<HoldsInt>()); + EXPECT_EQ(the_value.get<HoldsInt>().i, 12); + + the_value = String("Hello, world!"); + VERIFY(the_value.has<String>()); + EXPECT_EQ(the_value.get<String>(), "Hello, world!"); + } +} |