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

Side by Side 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, 4 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
« no previous file with comments | « base/optional.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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/optional.h" 5 #include "base/optional.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
10 10
(...skipping 1280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 TEST(OptionalTest, Hash_UseInSet) { 1291 TEST(OptionalTest, Hash_UseInSet) {
1292 std::set<Optional<int>> setOptInt; 1292 std::set<Optional<int>> setOptInt;
1293 1293
1294 EXPECT_EQ(setOptInt.end(), setOptInt.find(42)); 1294 EXPECT_EQ(setOptInt.end(), setOptInt.find(42));
1295 1295
1296 setOptInt.insert(Optional<int>(3)); 1296 setOptInt.insert(Optional<int>(3));
1297 EXPECT_EQ(setOptInt.end(), setOptInt.find(42)); 1297 EXPECT_EQ(setOptInt.end(), setOptInt.find(42));
1298 EXPECT_NE(setOptInt.end(), setOptInt.find(3)); 1298 EXPECT_NE(setOptInt.end(), setOptInt.find(3));
1299 } 1299 }
1300 1300
1301 TEST(OptionalTest, HasValue) {
1302 Optional<int> a;
1303 EXPECT_FALSE(a.has_value());
1304
1305 a = 42;
1306 EXPECT_TRUE(a.has_value());
1307
1308 a = nullopt;
1309 EXPECT_FALSE(a.has_value());
1310
1311 a = 0;
1312 EXPECT_TRUE(a.has_value());
1313
1314 a = Optional<int>();
1315 EXPECT_FALSE(a.has_value());
1316 }
1317
1318 TEST(OptionalTest, Reset_int) {
1319 Optional<int> a(0);
1320 EXPECT_TRUE(a.has_value());
1321 EXPECT_EQ(0, a.value());
1322
1323 a.reset();
1324 EXPECT_FALSE(a.has_value());
1325 EXPECT_EQ(-1, a.value_or(-1));
1326 }
1327
1328 TEST(OptionalTest, Reset_Object) {
1329 Optional<TestObject> a(TestObject(0, 0.1));
1330 EXPECT_TRUE(a.has_value());
1331 EXPECT_EQ(TestObject(0, 0.1), a.value());
1332
1333 a.reset();
1334 EXPECT_FALSE(a.has_value());
1335 EXPECT_EQ(TestObject(42, 0.0), a.value_or(TestObject(42, 0.0)));
1336 }
1337
1338 TEST(OptionalTest, Reset_NoOp) {
1339 Optional<int> a;
1340 EXPECT_FALSE(a.has_value());
1341
1342 a.reset();
1343 EXPECT_FALSE(a.has_value());
1344 }
1345
1301 } // namespace base 1346 } // namespace base
OLDNEW
« 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