diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-08-05 21:47:36 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-08-05 21:47:36 +0200 |
commit | 9553ecfe016845eb8ee704928b4e20be8d5aa04d (patch) | |
tree | ccdfcf917ccd1424a93488d4bb62300bbb130493 /AK/Tests | |
parent | cd08c8e1bf9a1a326db797c8c6fbf19daa7be7b0 (diff) | |
download | serenity-9553ecfe016845eb8ee704928b4e20be8d5aa04d.zip |
AK: Optional::operator=(Optional&&) should clear movee's has_value bit
We were forgetting to clear m_has_value in the Optional being moved
from when using operator=(Optional&&).
Diffstat (limited to 'AK/Tests')
-rw-r--r-- | AK/Tests/Makefile | 3 | ||||
-rw-r--r-- | AK/Tests/TestOptional.cpp | 30 |
2 files changed, 33 insertions, 0 deletions
diff --git a/AK/Tests/Makefile b/AK/Tests/Makefile index dc9837e915..30e940dc3a 100644 --- a/AK/Tests/Makefile +++ b/AK/Tests/Makefile @@ -48,6 +48,9 @@ TestNonnullRefPtr: TestNonnullRefPtr.o $(SHARED_TEST_OBJS) TestRefPtr: TestRefPtr.o $(SHARED_TEST_OBJS) $(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestRefPtr.o $(SHARED_TEST_OBJS) +TestOptional: TestOptional.o $(SHARED_TEST_OBJS) + $(PRE_CXX) $(CXX) $(CXXFLAGS) -o $@ TestOptional.o $(SHARED_TEST_OBJS) + clean: rm -f $(SHARED_TEST_OBJS) rm -f $(PROGRAMS) diff --git a/AK/Tests/TestOptional.cpp b/AK/Tests/TestOptional.cpp new file mode 100644 index 0000000000..02db877cea --- /dev/null +++ b/AK/Tests/TestOptional.cpp @@ -0,0 +1,30 @@ +#include <AK/TestSuite.h> + +#include <AK/AKString.h> +#include <AK/Optional.h> + +TEST_CASE(basic_optional) +{ + Optional<int> 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<int> x; + EXPECT_EQ(x.has_value(), false); + x = 3; + EXPECT_EQ(x.has_value(), true); + EXPECT_EQ(x.value(), 3); + + Optional<int> y; + y = move(x); + EXPECT_EQ(y.has_value(), true); + EXPECT_EQ(y.value(), 3); + EXPECT_EQ(x.has_value(), false); +} + +TEST_MAIN(Optional) |