ladybird/AK/Tests/TestOptional.cpp
Andreas Kling 73fdbba59c AK: Rename <AK/AKString.h> to <AK/String.h>
This was a workaround to be able to build on case-insensitive file
systems where it might get confused about <string.h> vs <String.h>.

Let's just not support building that way, so String.h can have an
objectively nicer name. :^)
2019-09-06 15:36:54 +02:00

43 lines
847 B
C++

#include <AK/TestSuite.h>
#include <AK/String.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_CASE(optional_leak_1)
{
struct Structure {
Optional<String> str;
};
// This used to leak, it does not anymore.
Vector<Structure> vec;
vec.append({ "foo" });
EXPECT_EQ(vec[0].str.has_value(), true);
EXPECT_EQ(vec[0].str.value(), "foo");
}
TEST_MAIN(Optional)