|
12 | 12 | using __llvm_libc::cpp::nullopt;
|
13 | 13 | using __llvm_libc::cpp::optional;
|
14 | 14 |
|
15 |
| -// This has clase has two properties for testing: |
16 |
| -// 1) No default constructor |
17 |
| -// 2) A non-trivial destructor with an observable side-effect |
| 15 | +// This class has three properties for testing: |
| 16 | +// 1) No default constructor. |
| 17 | +// 2) A non-trivial destructor with an observable side-effect. |
| 18 | +// 3) Functions that can be called explicitly. |
18 | 19 | class Contrived {
|
19 | 20 | int *_a;
|
20 | 21 |
|
21 | 22 | public:
|
22 | 23 | Contrived(int *a) : _a(a) {}
|
23 | 24 | ~Contrived() { (*_a)++; }
|
| 25 | + |
| 26 | + int get_a() { return *_a; } |
| 27 | + void inc_a() { (*_a)++; } |
24 | 28 | };
|
25 | 29 |
|
26 | 30 | TEST(LlvmLibcOptionalTest, Tests) {
|
@@ -59,4 +63,16 @@ TEST(LlvmLibcOptionalTest, Tests) {
|
59 | 63 | ASSERT_FALSE(Trivial5.has_value());
|
60 | 64 | optional<int> Trivial6 = Trivial5;
|
61 | 65 | ASSERT_FALSE(Trivial6.has_value());
|
| 66 | + |
| 67 | + // Test operator-> |
| 68 | + int arrow_num = 5; |
| 69 | + optional<Contrived> arrow_test(&arrow_num); |
| 70 | + ASSERT_TRUE(arrow_test.has_value()); |
| 71 | + ASSERT_EQ(arrow_test->get_a(), arrow_num); |
| 72 | + arrow_num = 10; |
| 73 | + ASSERT_EQ(arrow_test->get_a(), arrow_num); |
| 74 | + arrow_test->inc_a(); |
| 75 | + ASSERT_EQ(arrow_test->get_a(), arrow_num); |
| 76 | + ASSERT_EQ(arrow_num, 11); |
| 77 | + arrow_test.reset(); |
62 | 78 | }
|
0 commit comments