1 | //===-- DefineOutline.cpp ---------------------------------------*- 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 "TweakTesting.h" |
10 | #include "gtest/gtest.h" |
11 | |
12 | namespace clang::clangd { |
13 | namespace { |
14 | |
15 | TWEAK_TEST(ScopifyEnum); |
16 | |
17 | TEST_F(ScopifyEnumTest, TriggersOnUnscopedEnumDecl) { |
18 | FileName = "Test.hpp" ; |
19 | // Not available for scoped enum. |
20 | EXPECT_UNAVAILABLE(R"cpp(enum class ^E { V };)cpp" ); |
21 | |
22 | // Not available for non-definition. |
23 | EXPECT_UNAVAILABLE(R"cpp( |
24 | enum E { V }; |
25 | enum ^E; |
26 | )cpp" ); |
27 | } |
28 | |
29 | TEST_F(ScopifyEnumTest, ApplyTest) { |
30 | std::string Original = R"cpp( |
31 | enum ^E { EV1, EV2, EV3 }; |
32 | enum E; |
33 | E func(E in) |
34 | { |
35 | E out = EV1; |
36 | if (in == EV2) |
37 | out = E::EV3; |
38 | return out; |
39 | } |
40 | )cpp" ; |
41 | std::string Expected = R"cpp( |
42 | enum class E { EV1, EV2, EV3 }; |
43 | enum class E; |
44 | E func(E in) |
45 | { |
46 | E out = E::EV1; |
47 | if (in == E::EV2) |
48 | out = E::EV3; |
49 | return out; |
50 | } |
51 | )cpp" ; |
52 | FileName = "Test.cpp" ; |
53 | SCOPED_TRACE(Original); |
54 | EXPECT_EQ(apply(Original), Expected); |
55 | } |
56 | |
57 | } // namespace |
58 | } // namespace clang::clangd |
59 | |