mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:57:35 +00:00
AK: Fix Variant construction from lvalue references
Fixes #7371 and appends its test cases.
This commit is contained in:
parent
3f350c3b65
commit
6b4d7b6c19
2 changed files with 64 additions and 21 deletions
|
@ -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!");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue