Commit d0dea8e5 authored by Ingvar Stepanyan's avatar Ingvar Stepanyan Committed by Kenton Varda

Test that immovable types are allowed in Maybe

Immovable types can be already wrapped into `Maybe`, which can be constructed as default `nullptr`, set to a constructed value via `.emplace()`, but couldn't be cleared back to `nullptr`. The previous commit fixed the bug, this commit adds a test.
parent ad9f2050
......@@ -45,6 +45,11 @@ struct ImplicitToInt {
}
};
struct Immovable {
Immovable() = default;
KJ_DISALLOW_COPY(Immovable);
};
TEST(Common, Maybe) {
{
Maybe<int> m = 123;
......@@ -63,6 +68,23 @@ TEST(Common, Maybe) {
EXPECT_EQ(123, m.orDefault(456));
}
{
Maybe<int> m = 0;
EXPECT_FALSE(m == nullptr);
EXPECT_TRUE(m != nullptr);
KJ_IF_MAYBE(v, m) {
EXPECT_EQ(0, *v);
} else {
ADD_FAILURE();
}
KJ_IF_MAYBE(v, mv(m)) {
EXPECT_EQ(0, *v);
} else {
ADD_FAILURE();
}
EXPECT_EQ(0, m.orDefault(456));
}
{
Maybe<int> m = nullptr;
EXPECT_TRUE(m == nullptr);
......@@ -216,6 +238,16 @@ TEST(Common, Maybe) {
ADD_FAILURE();
}
}
{
// Test usage of immovable types.
Maybe<Immovable> m;
KJ_EXPECT(m == nullptr);
m.emplace();
KJ_EXPECT(m != nullptr);
m = nullptr;
KJ_EXPECT(m == nullptr);
}
}
TEST(Common, MaybeConstness) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment