clang-tools 20.0.0git
SwapBinaryOperandsTests.cpp
Go to the documentation of this file.
1//===-- SwapBinaryOperandsTests.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-matchers.h"
11#include "gmock/gmock.h"
12#include "gtest/gtest.h"
13
14namespace clang {
15namespace clangd {
16namespace {
17
18TWEAK_TEST(SwapBinaryOperands);
19
20TEST_F(SwapBinaryOperandsTest, Test) {
21 Context = Function;
22 EXPECT_EQ(apply("int *p = nullptr; bool c = ^p == nullptr;"),
23 "int *p = nullptr; bool c = nullptr == p;");
24 EXPECT_EQ(apply("int *p = nullptr; bool c = p ^== nullptr;"),
25 "int *p = nullptr; bool c = nullptr == p;");
26 EXPECT_EQ(apply("int x = 3; bool c = ^x >= 5;"),
27 "int x = 3; bool c = 5 <= x;");
28 EXPECT_EQ(apply("int x = 3; bool c = x >^= 5;"),
29 "int x = 3; bool c = 5 <= x;");
30 EXPECT_EQ(apply("int x = 3; bool c = x >=^ 5;"),
31 "int x = 3; bool c = 5 <= x;");
32 EXPECT_EQ(apply("int x = 3; bool c = x >=^ 5;"),
33 "int x = 3; bool c = 5 <= x;");
34 EXPECT_EQ(apply("int f(); int x = 3; bool c = x >=^ f();"),
35 "int f(); int x = 3; bool c = f() <= x;");
36 EXPECT_EQ(apply(R"cpp(
37 int f();
38 #define F f
39 int x = 3; bool c = x >=^ F();
40 )cpp"),
41 R"cpp(
42 int f();
43 #define F f
44 int x = 3; bool c = F() <= x;
45 )cpp");
46 EXPECT_EQ(apply(R"cpp(
47 int f();
48 #define F f()
49 int x = 3; bool c = x >=^ F;
50 )cpp"),
51 R"cpp(
52 int f();
53 #define F f()
54 int x = 3; bool c = F <= x;
55 )cpp");
56 EXPECT_EQ(apply(R"cpp(
57 int f(bool);
58 #define F(v) f(v)
59 int x = 0;
60 bool c = F(x^ < 5);
61 )cpp"),
62 R"cpp(
63 int f(bool);
64 #define F(v) f(v)
65 int x = 0;
66 bool c = F(5 > x);
67 )cpp");
68 ExtraArgs = {"-std=c++20"};
69 Context = CodeContext::File;
71 namespace std {
72 struct strong_ordering {
73 int val;
74 static const strong_ordering less;
75 static const strong_ordering equivalent;
76 static const strong_ordering equal;
77 static const strong_ordering greater;
78 };
79 inline constexpr strong_ordering strong_ordering::less {-1};
80 inline constexpr strong_ordering strong_ordering::equivalent {0};
81 inline constexpr strong_ordering strong_ordering::equal {0};
82 inline constexpr strong_ordering strong_ordering::greater {1};
83 };
84 #define F(v) v
85 int x = 0;
86 auto c = F(5^ <=> x);
87 )cpp");
88}
89
90} // namespace
91} // namespace clangd
92} // namespace clang
#define TWEAK_TEST(TweakID)
Definition: TweakTesting.h:107
#define EXPECT_UNAVAILABLE(MarkedCode)
Definition: TweakTesting.h:124
TEST_F(BackgroundIndexTest, NoCrashOnErrorFile)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//