[TargetVersion] Only enable on RISC-V and AArch64 (#115991)
[llvm-project.git] / clang-tools-extra / clangd / unittests / support / FunctionTests.cpp
blobbfb1ea49434db5c456c90091c4f8447ff93b2b00
1 //===-- FunctionTests.cpp -------------------------------------------------===//
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 "support/Function.h"
10 #include "gmock/gmock.h"
11 #include "gtest/gtest.h"
13 namespace clang {
14 namespace clangd {
15 namespace {
17 TEST(EventTest, Subscriptions) {
18 Event<int> E;
19 int N = 0;
21 Event<int>::Subscription SubA;
22 // No subscriptions are active.
23 E.broadcast(42);
24 EXPECT_EQ(0, N);
26 Event<int>::Subscription SubB = E.observe([&](int) { ++N; });
27 // Now one is active.
28 E.broadcast(42);
29 EXPECT_EQ(1, N);
31 SubA = E.observe([&](int) { ++N; });
32 // Both are active.
33 EXPECT_EQ(1, N);
34 E.broadcast(42);
35 EXPECT_EQ(3, N);
37 SubA = std::move(SubB);
38 // One is active.
39 EXPECT_EQ(3, N);
40 E.broadcast(42);
41 EXPECT_EQ(4, N);
43 // None are active.
44 EXPECT_EQ(4, N);
45 E.broadcast(42);
46 EXPECT_EQ(4, N);
49 } // namespace
50 } // namespace clangd
51 } // namespace clang