clang-tools 20.0.0git
ScopifyEnumTests.cpp
Go to the documentation of this file.
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
12namespace clang::clangd {
13namespace {
14
15TWEAK_TEST(ScopifyEnum);
16
17TEST_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.
24enum E { V };
25enum ^E;
26)cpp");
27}
28
29TEST_F(ScopifyEnumTest, ApplyTestWithPrefix) {
30 std::string Original = R"cpp(
31enum ^E { EV1, EV2, EV3 };
32enum E;
33E 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(
42enum class E { V1, V2, V3 };
43enum class E;
44E func(E in)
45{
46 E out = E::V1;
47 if (in == E::V2)
48 out = E::V3;
49 return out;
50}
51)cpp";
52 FileName = "Test.cpp";
53 SCOPED_TRACE(Original);
54 EXPECT_EQ(apply(Original), Expected);
55}
56
57TEST_F(ScopifyEnumTest, ApplyTestWithPrefixAndUnderscore) {
58 std::string Original = R"cpp(
59enum ^E { E_V1, E_V2, E_V3 };
60enum E;
61E func(E in)
62{
63 E out = E_V1;
64 if (in == E_V2)
65 out = E::E_V3;
66 return out;
67}
68)cpp";
69 std::string Expected = R"cpp(
70enum class E { V1, V2, V3 };
71enum class E;
72E func(E in)
73{
74 E out = E::V1;
75 if (in == E::V2)
76 out = E::V3;
77 return out;
78}
79)cpp";
80 FileName = "Test.cpp";
81 SCOPED_TRACE(Original);
82 EXPECT_EQ(apply(Original), Expected);
83}
84
85TEST_F(ScopifyEnumTest, ApplyTestWithoutPrefix) {
86 std::string Original = R"cpp(
87enum ^E { V1, V2, V3 };
88enum E;
89E func(E in)
90{
91 E out = V1;
92 if (in == V2)
93 out = E::V3;
94 return out;
95}
96)cpp";
97 std::string Expected = R"cpp(
98enum class E { V1, V2, V3 };
99enum class E;
100E func(E in)
101{
102 E out = E::V1;
103 if (in == E::V2)
104 out = E::V3;
105 return out;
106}
107)cpp";
108 FileName = "Test.cpp";
109 SCOPED_TRACE(Original);
110 EXPECT_EQ(apply(Original), Expected);
111}
112
113} // namespace
114} // namespace clang::clangd
StringRef FileName
std::vector< const char * > Expected
#define TWEAK_TEST(TweakID)
Definition: TweakTesting.h:107
#define EXPECT_UNAVAILABLE(MarkedCode)
Definition: TweakTesting.h:124
FIXME: Skip testing on windows temporarily due to the different escaping code mode.
Definition: AST.cpp:44
TEST_F(BackgroundIndexTest, NoCrashOnErrorFile)