/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #include #include #include TEST_CASE(basic_optional) { Optional x; EXPECT_EQ(x.has_value(), false); x = 3; EXPECT_EQ(x.has_value(), true); EXPECT_EQ(x.value(), 3); } TEST_CASE(move_optional) { Optional x; EXPECT_EQ(x.has_value(), false); x = 3; EXPECT_EQ(x.has_value(), true); EXPECT_EQ(x.value(), 3); Optional y; y = move(x); EXPECT_EQ(y.has_value(), true); EXPECT_EQ(y.value(), 3); EXPECT_EQ(x.has_value(), false); } TEST_CASE(optional_leak_1) { struct Structure { Optional str; }; // This used to leak, it does not anymore. Vector vec; vec.append({ "foo" }); EXPECT_EQ(vec[0].str.has_value(), true); EXPECT_EQ(vec[0].str.value(), "foo"); } TEST_CASE(short_notation) { Optional value = "foo"; EXPECT_EQ(value->length(), 3u); EXPECT_EQ(*value, "foo"); } TEST_MAIN(Optional)