v8/test/unittests/api/v8-maybe-unittest.cc
Anton Bikineev 2655d3d18d api: Allow v8::Maybe<MovableType>.
Change-Id: I29bcdf3302f37568e8c8925e70a01ba342c17925
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3606229
Reviewed-by: Michael Lippautz <mlippautz@chromium.org>
Commit-Queue: Anton Bikineev <bikineev@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80288}
2022-04-30 21:47:24 +00:00

43 lines
996 B
C++

// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "include/v8-maybe.h"
#include "src/base/compiler-specific.h"
#include "src/base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace v8 {
namespace internal {
namespace {
struct Movable {
Movable() = default;
Movable(const Movable&) = delete;
Movable& operator=(const Movable&) = delete;
Movable(Movable&&) V8_NOEXCEPT = default;
Movable& operator=(Movable&&) V8_NOEXCEPT = default;
};
} // namespace
TEST(MaybeTest, AllowMovableTypes) {
Maybe<Movable> m1 = Just(Movable{});
EXPECT_TRUE(m1.IsJust());
Maybe<Movable> m2 = Just<Movable>({});
EXPECT_TRUE(m2.IsJust());
Maybe<Movable> m3 = Nothing<Movable>();
EXPECT_TRUE(m3.IsNothing());
Maybe<Movable> m4 = Just(Movable{});
Movable mm = std::move(m4).FromJust();
USE(mm);
}
} // namespace internal
} // namespace v8