| 1 |
//===-- ContextTests.cpp - Context tests ------------------------*- C++ -*-===// |
| 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 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
#include "support/Context.h" |
| 10 |
|
| 11 |
#include "gtest/gtest.h" |
| 12 |
|
| 13 |
namespace clang { |
| 14 |
namespace clangd { |
| 15 |
|
| 16 |
TEST(ContextTests, Simple) { |
| 17 |
Key<int> IntParam; |
| 18 |
Key<int> ExtraIntParam; |
| 19 |
|
| 20 |
Context Ctx = Context::empty().derive(IntParam, 10).derive(ExtraIntParam, 20); |
| 21 |
|
| 22 |
EXPECT_EQ(*Ctx.get(IntParam), 10); |
| 23 |
EXPECT_EQ(*Ctx.get(ExtraIntParam), 20); |
| 24 |
} |
| 25 |
|
| 26 |
TEST(ContextTests, MoveOps) { |
| 27 |
Key<std::unique_ptr<int>> Param; |
| 28 |
|
| 29 |
Context Ctx = Context::empty().derive(Param, std::make_unique<int>(10)); |
| 30 |
EXPECT_EQ(**Ctx.get(Param), 10); |
| 31 |
|
| 32 |
Context NewCtx = std::move(Ctx); |
| 33 |
EXPECT_EQ(**NewCtx.get(Param), 10); |
| 34 |
} |
| 35 |
|
| 36 |
TEST(ContextTests, Builders) { |
| 37 |
Key<int> ParentParam; |
| 38 |
Key<int> ParentAndChildParam; |
| 39 |
Key<int> ChildParam; |
| 40 |
|
| 41 |
Context ParentCtx = |
| 42 |
Context::empty().derive(ParentParam, 10).derive(ParentAndChildParam, 20); |
| 43 |
Context ChildCtx = |
| 44 |
ParentCtx.derive(ParentAndChildParam, 30).derive(ChildParam, 40); |
| 45 |
|
| 46 |
EXPECT_EQ(*ParentCtx.get(ParentParam), 10); |
| 47 |
EXPECT_EQ(*ParentCtx.get(ParentAndChildParam), 20); |
| 48 |
EXPECT_EQ(ParentCtx.get(ChildParam), nullptr); |
| 49 |
|
| 50 |
EXPECT_EQ(*ChildCtx.get(ParentParam), 10); |
| 51 |
EXPECT_EQ(*ChildCtx.get(ParentAndChildParam), 30); |
| 52 |
EXPECT_EQ(*ChildCtx.get(ChildParam), 40); |
| 53 |
} |
| 54 |
|
| 55 |
} // namespace clangd |
| 56 |
} // namespace clang |