| 1 |
//===-- ExpandMacroTests.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 "gmock/gmock.h" |
| 11 |
#include "gtest/gtest.h" |
| 12 |
|
| 13 |
namespace clang { |
| 14 |
namespace clangd { |
| 15 |
namespace { |
| 16 |
|
| 17 |
TWEAK_TEST(ExpandMacro); |
| 18 |
|
| 19 |
TEST_F(ExpandMacroTest, Test) { |
| 20 |
Header = R"cpp( |
| 21 |
// error-ok: not real c++, just token manipulation |
| 22 |
#define FOO 1 2 3 |
| 23 |
#define FUNC(X) X+X+X |
| 24 |
#define EMPTY |
| 25 |
#define EMPTY_FN(X) |
| 26 |
)cpp"; |
| 27 |
|
| 28 |
// Available on macro names, not available anywhere else. |
| 29 |
EXPECT_AVAILABLE("^F^O^O^ BAR ^F^O^O^"); |
| 30 |
EXPECT_AVAILABLE("^F^U^N^C^(1)"); |
| 31 |
EXPECT_UNAVAILABLE("^#^d^efine^ ^XY^Z 1 ^2 ^3^"); |
| 32 |
EXPECT_UNAVAILABLE("FOO ^B^A^R^ FOO ^"); |
| 33 |
EXPECT_UNAVAILABLE("FUNC(^1^)^"); |
| 34 |
|
| 35 |
// Works as expected on object-like macros. |
| 36 |
EXPECT_EQ(apply("^FOO BAR FOO"), "1 2 3 BAR FOO"); |
| 37 |
EXPECT_EQ(apply("FOO BAR ^FOO"), "FOO BAR 1 2 3"); |
| 38 |
// And function-like macros. |
| 39 |
EXPECT_EQ(apply("F^UNC(2)"), "2 + 2 + 2"); |
| 40 |
|
| 41 |
// Works on empty macros. |
| 42 |
EXPECT_EQ(apply("int a ^EMPTY;"), "int a ;"); |
| 43 |
EXPECT_EQ(apply("int a ^EMPTY_FN(1 2 3);"), "int a ;"); |
| 44 |
EXPECT_EQ(apply("int a = 123 ^EMPTY EMPTY_FN(1);"), |
| 45 |
"int a = 123 EMPTY_FN(1);"); |
| 46 |
EXPECT_EQ(apply("int a = 123 ^EMPTY_FN(1) EMPTY;"), "int a = 123 EMPTY;"); |
| 47 |
EXPECT_EQ(apply("int a = 123 EMPTY_FN(1) ^EMPTY;"), |
| 48 |
"int a = 123 EMPTY_FN(1) ;"); |
| 49 |
} |
| 50 |
|
| 51 |
} // namespace |
| 52 |
} // namespace clangd |
| 53 |
} // namespace clang |