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

Unified Diff: base/optional_unittest.cc

Issue 2198673002: Implement Optional::has_value() and Optional::reset(). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/optional.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/optional_unittest.cc
diff --git a/base/optional_unittest.cc b/base/optional_unittest.cc
index d6bf2636918077e34b3d8620f39a0313a1a71e7c..565b6cd6c74cad6679c02c68953176b0dce11c6f 100644
--- a/base/optional_unittest.cc
+++ b/base/optional_unittest.cc
@@ -1298,4 +1298,49 @@ TEST(OptionalTest, Hash_UseInSet) {
EXPECT_NE(setOptInt.end(), setOptInt.find(3));
}
+TEST(OptionalTest, HasValue) {
+ Optional<int> a;
+ EXPECT_FALSE(a.has_value());
+
+ a = 42;
+ EXPECT_TRUE(a.has_value());
+
+ a = nullopt;
+ EXPECT_FALSE(a.has_value());
+
+ a = 0;
+ EXPECT_TRUE(a.has_value());
+
+ a = Optional<int>();
+ EXPECT_FALSE(a.has_value());
+}
+
+TEST(OptionalTest, Reset_int) {
+ Optional<int> a(0);
+ EXPECT_TRUE(a.has_value());
+ EXPECT_EQ(0, a.value());
+
+ a.reset();
+ EXPECT_FALSE(a.has_value());
+ EXPECT_EQ(-1, a.value_or(-1));
+}
+
+TEST(OptionalTest, Reset_Object) {
+ Optional<TestObject> a(TestObject(0, 0.1));
+ EXPECT_TRUE(a.has_value());
+ EXPECT_EQ(TestObject(0, 0.1), a.value());
+
+ a.reset();
+ EXPECT_FALSE(a.has_value());
+ EXPECT_EQ(TestObject(42, 0.0), a.value_or(TestObject(42, 0.0)));
+}
+
+TEST(OptionalTest, Reset_NoOp) {
+ Optional<int> a;
+ EXPECT_FALSE(a.has_value());
+
+ a.reset();
+ EXPECT_FALSE(a.has_value());
+}
+
} // namespace base
« no previous file with comments | « base/optional.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698