clang-tools 20.0.0git
SwapIfBranchesTests.cpp
Go to the documentation of this file.
1//===-- SwapIfBranchesTests.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(SwapIfBranches);
19
20TEST_F(SwapIfBranchesTest, Test) {
21 Context = Function;
22 EXPECT_EQ(apply("^if (true) {return;} else {(void)0;}"),
23 "if (true) {(void)0;} else {return;}");
24 EXPECT_EQ(apply("^if (/*error-ok*/) {return;} else {(void)0;}"),
25 "if (/*error-ok*/) {(void)0;} else {return;}")
26 << "broken condition";
27 EXPECT_AVAILABLE("^i^f^^(^t^r^u^e^) { return; } ^e^l^s^e^ { return; }");
28 EXPECT_UNAVAILABLE("if (true) {^return ^;^ } else { ^return^;^ }");
29 // Available in subexpressions of the condition;
30 EXPECT_AVAILABLE("if(2 + [[2]] + 2) { return; } else {return;}");
31 // But not as part of the branches.
32 EXPECT_UNAVAILABLE("if(2 + 2 + 2) { [[return]]; } else { return; }");
33 // Range covers the "else" token, so available.
34 EXPECT_AVAILABLE("if(2 + 2 + 2) { return[[; } else {return;]]}");
35 // Not available in compound statements in condition.
36 EXPECT_UNAVAILABLE("if([]{return [[true]];}()) { return; } else { return; }");
37 // Not available if both sides aren't braced.
38 EXPECT_UNAVAILABLE("^if (1) return; else { return; }");
39 // Only one if statement is supported!
40 EXPECT_UNAVAILABLE("[[if(1){}else{}if(2){}else{}]]");
41}
42
43} // namespace
44} // namespace clangd
45} // namespace clang
#define TWEAK_TEST(TweakID)
Definition: TweakTesting.h:107
#define EXPECT_AVAILABLE(MarkedCode)
Definition: TweakTesting.h:123
#define EXPECT_UNAVAILABLE(MarkedCode)
Definition: TweakTesting.h:124
TEST_F(BackgroundIndexTest, NoCrashOnErrorFile)
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//