Revert "[clang-repl] Implement partial translation units and error recovery."
[llvm-project.git] / parallel-libs / acxxel / tests / status_test.cpp
blobedd0f2a44639e94044c62a84331bd9472db4d47c
1 //===--- status_test.cpp - Tests for the Status and Expected classes ------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "status.h"
11 #include "gtest/gtest.h"
13 #include <memory>
15 namespace {
17 struct RefCounter {
18 static int Count;
20 RefCounter() { ++Count; }
21 ~RefCounter() { --Count; }
22 RefCounter(const RefCounter &) = delete;
23 RefCounter &operator=(const RefCounter &) = delete;
26 int RefCounter::Count;
28 TEST(Expected, RefCounter) {
29 RefCounter::Count = 0;
30 using uptr = std::unique_ptr<RefCounter>;
32 acxxel::Expected<uptr> E0(uptr(new RefCounter));
33 EXPECT_FALSE(E0.isError());
34 EXPECT_EQ(1, RefCounter::Count);
36 acxxel::Expected<uptr> E1(std::move(E0));
37 EXPECT_FALSE(E1.isError());
38 EXPECT_EQ(1, RefCounter::Count);
40 acxxel::Expected<uptr> E2(acxxel::Status("nothing in here yet"));
41 EXPECT_TRUE(E2.isError());
42 EXPECT_EQ(1, RefCounter::Count);
43 E2 = std::move(E1);
44 EXPECT_FALSE(E2.isError());
45 EXPECT_EQ(1, RefCounter::Count);
47 EXPECT_EQ(1, E2.getValue()->Count);
48 EXPECT_FALSE(E2.isError());
49 EXPECT_EQ(1, RefCounter::Count);
51 EXPECT_EQ(1, E2.takeValue()->Count);
52 EXPECT_EQ(0, RefCounter::Count);
55 } // namespace