diff options
Diffstat (limited to 'Tests/AK')
-rw-r--r-- | Tests/AK/TestVariant.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/Tests/AK/TestVariant.cpp b/Tests/AK/TestVariant.cpp index f05c629022..af87669671 100644 --- a/Tests/AK/TestVariant.cpp +++ b/Tests/AK/TestVariant.cpp @@ -31,9 +31,22 @@ TEST_CASE(visit) bool correct = false; Variant<int, String, float> the_value { 42.0f }; the_value.visit( - [&](const int&) { correct = false; }, - [&](const String&) { correct = false; }, - [&](const float&) { correct = true; }); + [&](int const&) { correct = false; }, + [&](String const&) { correct = false; }, + [&](float const&) { correct = true; }); + EXPECT(correct); +} + +TEST_CASE(visit_const) +{ + bool correct = false; + Variant<int, String> const the_value { "42"sv }; + + the_value.visit( + [&](String const&) { correct = true; }, + [&](auto&) {}, + [&](auto const&) {}); + EXPECT(correct); } @@ -139,9 +152,9 @@ TEST_CASE(return_values) MyVariant the_value { 42.0f }; float value = the_value.visit( - [&](const int&) { return 1.0f; }, - [&](const String&) { return 2.0f; }, - [&](const float& f) { return f; }); + [&](int const&) { return 1.0f; }, + [&](String const&) { return 2.0f; }, + [&](float const& f) { return f; }); EXPECT_EQ(value, 42.0f); } { @@ -157,9 +170,9 @@ TEST_CASE(return_values) const MyVariant the_value { "str" }; String value = the_value.visit( - [&](const int&) { return String { "wrong" }; }, - [&](const String& s) { return s; }, - [&](const float&) { return String { "wrong" }; }); + [&](int const&) { return String { "wrong" }; }, + [&](String const& s) { return s; }, + [&](float const&) { return String { "wrong" }; }); EXPECT_EQ(value, "str"); } } @@ -170,9 +183,9 @@ TEST_CASE(return_values_by_reference) Variant<int, String, float> the_value { 42.0f }; auto& value = the_value.visit( - [&](const int&) -> RefPtr<Object>& { return ref; }, - [&](const String&) -> RefPtr<Object>& { return ref; }, - [&](const float&) -> RefPtr<Object>& { return ref; }); + [&](int const&) -> RefPtr<Object>& { return ref; }, + [&](String const&) -> RefPtr<Object>& { return ref; }, + [&](float const&) -> RefPtr<Object>& { return ref; }); EXPECT_EQ(ref, value); EXPECT_EQ(ref->ref_count(), 1u); |