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.
23 EXPECT_UNAVAILABLE(R"cpp(
24enum E { V };
25enum ^E;
26)cpp");
27}
28
29TEST_F(ScopifyEnumTest, ApplyTest) {
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 { EV1, EV2, EV3 };
43enum class E;
44E 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

source code of clang-tools-extra/clangd/unittests/tweaks/ScopifyEnumTests.cpp