summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clangd/unittests/TweakTests.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/clangd/unittests/TweakTests.cpp')
-rw-r--r--clang-tools-extra/clangd/unittests/TweakTests.cpp20
1 files changed, 16 insertions, 4 deletions
diff --git a/clang-tools-extra/clangd/unittests/TweakTests.cpp b/clang-tools-extra/clangd/unittests/TweakTests.cpp
index 147a96c32ed..5e8c4a41969 100644
--- a/clang-tools-extra/clangd/unittests/TweakTests.cpp
+++ b/clang-tools-extra/clangd/unittests/TweakTests.cpp
@@ -522,10 +522,7 @@ TEST_F(ExtractFunctionTest, FunctionTest) {
EXPECT_THAT(apply(" [[int a = 5;]] a++; "), StartsWith("fail"));
// Don't extract return
EXPECT_THAT(apply(" if(true) [[return;]] "), StartsWith("fail"));
- // Don't extract break and continue.
- // FIXME: We should be able to extract this since it's non broken.
- EXPECT_THAT(apply(" [[for(;;) break;]] "), StartsWith("fail"));
- EXPECT_THAT(apply(" for(;;) [[continue;]] "), StartsWith("fail"));
+
}
TEST_F(ExtractFunctionTest, FileTest) {
@@ -604,6 +601,21 @@ void f(const int c) {
EXPECT_EQ(apply(MacroFailInput), "unavailable");
}
+TEST_F(ExtractFunctionTest, ControlFlow) {
+ Context = Function;
+ // We should be able to extract break/continue with a parent loop/switch.
+ EXPECT_THAT(apply(" [[for(;;) if(1) break;]] "), HasSubstr("extracted"));
+ EXPECT_THAT(apply(" for(;;) [[while(1) break;]] "), HasSubstr("extracted"));
+ EXPECT_THAT(apply(" [[switch(1) { break; }]]"), HasSubstr("extracted"));
+ EXPECT_THAT(apply(" [[while(1) switch(1) { continue; }]]"),
+ HasSubstr("extracted"));
+ // Don't extract break and continue without a loop/switch parent.
+ EXPECT_THAT(apply(" for(;;) [[if(1) continue;]] "), StartsWith("fail"));
+ EXPECT_THAT(apply(" while(1) [[if(1) break;]] "), StartsWith("fail"));
+ EXPECT_THAT(apply(" switch(1) { [[break;]] }"), StartsWith("fail"));
+ EXPECT_THAT(apply(" for(;;) { [[while(1) break; break;]] }"),
+ StartsWith("fail"));
+}
} // namespace
} // namespace clangd
} // namespace clang
OpenPOWER on IntegriCloud