Chromium Code Reviews| Index: headless/public/util/maybe_unittest.cc |
| diff --git a/headless/public/util/maybe_unittest.cc b/headless/public/util/maybe_unittest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d390c0cb7a68c5eb63d16ffb9545d798b9ec9ab7 |
| --- /dev/null |
| +++ b/headless/public/util/maybe_unittest.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright 2016 The Chromium 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 "headless/public/util/maybe.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| + |
| +namespace headless { |
| +namespace { |
| + |
| +class MoveOnlyType { |
| + public: |
| + MoveOnlyType() {} |
| + MoveOnlyType(MoveOnlyType&& other) {} |
| + |
| + void operator=(MoveOnlyType&& other) {} |
| + |
| + private: |
| + DISALLOW_COPY_AND_ASSIGN(MoveOnlyType); |
| +}; |
| + |
| +} // namespace |
| + |
| +TEST(MaybeTest, Nothing) { |
| + Maybe<int> maybe; |
| + EXPECT_TRUE(maybe.IsNothing()); |
| + EXPECT_FALSE(maybe.IsJust()); |
| +} |
| + |
| +TEST(MaybeTest, Just) { |
| + Maybe<int> maybe = Just(1); |
| + EXPECT_FALSE(maybe.IsNothing()); |
| + EXPECT_TRUE(maybe.IsJust()); |
| + EXPECT_EQ(1, maybe.FromJust()); |
| + |
| + const Maybe<int> const_maybe = Just(2); |
| + EXPECT_EQ(2, const_maybe.FromJust()); |
| +} |
| + |
| +TEST(MaybeTest, Equality) { |
| + Maybe<int> a; |
| + Maybe<int> b; |
| + EXPECT_EQ(a, b); |
| + EXPECT_EQ(b, a); |
| + |
| + a = Just(1); |
| + EXPECT_NE(a, b); |
| + EXPECT_NE(b, a); |
| + |
| + b = Just(2); |
| + EXPECT_NE(a, b); |
| + EXPECT_NE(b, a); |
| + |
| + b = Just(1); |
| + EXPECT_EQ(a, b); |
| + EXPECT_EQ(b, a); |
| +} |
| + |
| +TEST(MaybeTest, Assignment) { |
| + Maybe<int> a = Just(1); |
| + Maybe<int> b = Nothing<int>(); |
| + EXPECT_NE(a, b); |
| + |
| + b = a; |
| + EXPECT_EQ(a, b); |
| +} |
| + |
| +TEST(MaybeTest, MoveOnlyType) { |
| + MoveOnlyType value; |
| + Maybe<MoveOnlyType> a = Just(std::move(value)); |
| + EXPECT_TRUE(a.IsJust()); |
| + |
| + Maybe<MoveOnlyType> b = Just(MoveOnlyType()); |
|
alex clarke (OOO till 29th)
2016/04/07 12:00:05
Can you do this:
MoveOnlyType foo = std::move(b.F
Sami
2016/04/07 12:08:52
Added a test for it.
|
| + EXPECT_TRUE(b.IsJust()); |
| + |
| + Maybe<MoveOnlyType> c = Nothing<MoveOnlyType>(); |
| + c = std::move(b); |
| + EXPECT_TRUE(c.IsJust()); |
| +} |
| + |
| +} // namespace headless |