Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(40)

Side by Side Diff: headless/public/util/maybe_unittest.cc

Issue 1866063002: headless: Add a Maybe-type (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« headless/public/util/maybe.h ('K') | « headless/public/util/maybe.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "headless/public/util/maybe.h"
6 #include "testing/gtest/include/gtest/gtest.h"
7
8 namespace headless {
9 namespace {
10
11 class MoveOnlyType {
12 public:
13 MoveOnlyType() {}
14 MoveOnlyType(MoveOnlyType&& other) {}
15
16 void operator=(MoveOnlyType&& other) {}
17
18 private:
19 DISALLOW_COPY_AND_ASSIGN(MoveOnlyType);
20 };
21
22 } // namespace
23
24 TEST(MaybeTest, Nothing) {
25 Maybe<int> maybe;
26 EXPECT_TRUE(maybe.IsNothing());
27 EXPECT_FALSE(maybe.IsJust());
28 }
29
30 TEST(MaybeTest, Just) {
31 Maybe<int> maybe = Just(1);
32 EXPECT_FALSE(maybe.IsNothing());
33 EXPECT_TRUE(maybe.IsJust());
34 EXPECT_EQ(1, maybe.FromJust());
35
36 const Maybe<int> const_maybe = Just(2);
37 EXPECT_EQ(2, const_maybe.FromJust());
38 }
39
40 TEST(MaybeTest, Equality) {
41 Maybe<int> a;
42 Maybe<int> b;
43 EXPECT_EQ(a, b);
44 EXPECT_EQ(b, a);
45
46 a = Just(1);
47 EXPECT_NE(a, b);
48 EXPECT_NE(b, a);
49
50 b = Just(2);
51 EXPECT_NE(a, b);
52 EXPECT_NE(b, a);
53
54 b = Just(1);
55 EXPECT_EQ(a, b);
56 EXPECT_EQ(b, a);
57 }
58
59 TEST(MaybeTest, Assignment) {
60 Maybe<int> a = Just(1);
61 Maybe<int> b = Nothing<int>();
62 EXPECT_NE(a, b);
63
64 b = a;
65 EXPECT_EQ(a, b);
66 }
67
68 TEST(MaybeTest, MoveOnlyType) {
69 MoveOnlyType value;
70 Maybe<MoveOnlyType> a = Just(std::move(value));
71 EXPECT_TRUE(a.IsJust());
72
73 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.
74 EXPECT_TRUE(b.IsJust());
75
76 Maybe<MoveOnlyType> c = Nothing<MoveOnlyType>();
77 c = std::move(b);
78 EXPECT_TRUE(c.IsJust());
79 }
80
81 } // namespace headless
OLDNEW
« headless/public/util/maybe.h ('K') | « headless/public/util/maybe.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698