mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-26 01:20:25 +00:00
73fdbba59c
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. :^)
43 lines
847 B
C++
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)
|