brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.7 KiB · cd63ddb Raw
54 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include "TweakTesting.h"10#include "gmock/gmock.h"11#include "gtest/gtest.h"12 13namespace clang {14namespace clangd {15namespace {16 17TWEAK_TEST(ExpandMacro);18 19TEST_F(ExpandMacroTest, Test) {20  Header = R"cpp(21    // error-ok: not real c++, just token manipulation22    #define FOO 1 2 323    #define FUNC(X) X+X+X24    #define EMPTY25    #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} // namespace52} // namespace clangd53} // namespace clang54