1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
// 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());
EXPECT_TRUE(b.IsJust());
Maybe<MoveOnlyType> c = Nothing<MoveOnlyType>();
c = std::move(a);
EXPECT_TRUE(c.IsJust());
MoveOnlyType d = std::move(b.FromJust());
}
} // namespace headless
|