diff options
author | Sam McCall <sam.mccall@gmail.com> | 2019-12-16 15:57:43 +0100 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2019-12-16 15:57:43 +0100 |
commit | 8f876d5105507f874c0fb86bc779c9853eab3fe2 (patch) | |
tree | b2c58b10c688ee22f4216766717e7a2bfb0d41e3 /clang-tools-extra/clangd/unittests/SelectionTests.cpp | |
parent | 2500a8d5d8813a3e31fc9ba8dd45e211439a1e3d (diff) | |
download | bcm5719-llvm-8f876d5105507f874c0fb86bc779c9853eab3fe2.tar.gz bcm5719-llvm-8f876d5105507f874c0fb86bc779c9853eab3fe2.zip |
Revert "[clangd] Reapply b60896fad926 Fall back to selecting token-before-cursor if token-after-cursor fails."
This reverts commit 2500a8d5d8813a3e31fc9ba8dd45e211439a1e3d.
Diffstat (limited to 'clang-tools-extra/clangd/unittests/SelectionTests.cpp')
-rw-r--r-- | clang-tools-extra/clangd/unittests/SelectionTests.cpp | 71 |
1 files changed, 5 insertions, 66 deletions
diff --git a/clang-tools-extra/clangd/unittests/SelectionTests.cpp b/clang-tools-extra/clangd/unittests/SelectionTests.cpp index 4af267b6b3e..9e1a90b55e3 100644 --- a/clang-tools-extra/clangd/unittests/SelectionTests.cpp +++ b/clang-tools-extra/clangd/unittests/SelectionTests.cpp @@ -19,26 +19,20 @@ namespace clangd { namespace { using ::testing::UnorderedElementsAreArray; -// Create a selection tree corresponding to a point or pair of points. -// This uses the precisely-defined createRight semantics. The fuzzier -// createEach is tested separately. SelectionTree makeSelectionTree(const StringRef MarkedCode, ParsedAST &AST) { Annotations Test(MarkedCode); switch (Test.points().size()) { - case 1: { // Point selection. - unsigned Offset = cantFail(positionToOffset(Test.code(), Test.point())); - return SelectionTree::createRight(AST.getASTContext(), AST.getTokens(), - Offset, Offset); - } + case 1: // Point selection. + return SelectionTree(AST.getASTContext(), AST.getTokens(), + cantFail(positionToOffset(Test.code(), Test.point()))); case 2: // Range selection. - return SelectionTree::createRight( + return SelectionTree( AST.getASTContext(), AST.getTokens(), cantFail(positionToOffset(Test.code(), Test.points()[0])), cantFail(positionToOffset(Test.code(), Test.points()[1]))); default: ADD_FAILURE() << "Expected 1-2 points for selection.\n" << MarkedCode; - return SelectionTree::createRight(AST.getASTContext(), AST.getTokens(), 0u, - 0u); + return SelectionTree(AST.getASTContext(), AST.getTokens(), 0u, 0u); } } @@ -513,61 +507,6 @@ TEST(SelectionTest, Implicit) { EXPECT_EQ("CXXConstructExpr", nodeKind(&Str->outerImplicit())); } -TEST(SelectionTest, CreateAll) { - llvm::Annotations Test("int$unique^ a=1$ambiguous^+1; $empty^"); - auto AST = TestTU::withCode(Test.code()).build(); - unsigned Seen = 0; - SelectionTree::createEach( - AST.getASTContext(), AST.getTokens(), Test.point("ambiguous"), - Test.point("ambiguous"), [&](SelectionTree T) { - // Expect to see the right-biased tree first. - if (Seen == 0) - EXPECT_EQ("BinaryOperator", nodeKind(T.commonAncestor())); - else if (Seen == 1) - EXPECT_EQ("IntegerLiteral", nodeKind(T.commonAncestor())); - ++Seen; - return false; - }); - EXPECT_EQ(2u, Seen); - - Seen = 0; - SelectionTree::createEach(AST.getASTContext(), AST.getTokens(), - Test.point("ambiguous"), Test.point("ambiguous"), - [&](SelectionTree T) { - ++Seen; - return true; - }); - EXPECT_EQ(1u, Seen) << "Return true --> stop iterating"; - - Seen = 0; - SelectionTree::createEach(AST.getASTContext(), AST.getTokens(), - Test.point("unique"), Test.point("unique"), - [&](SelectionTree T) { - ++Seen; - return false; - }); - EXPECT_EQ(1u, Seen) << "no ambiguity --> only one tree"; - - Seen = 0; - SelectionTree::createEach(AST.getASTContext(), AST.getTokens(), - Test.point("empty"), Test.point("empty"), - [&](SelectionTree T) { - EXPECT_FALSE(T.commonAncestor()); - ++Seen; - return false; - }); - EXPECT_EQ(1u, Seen) << "empty tree still created"; - - Seen = 0; - SelectionTree::createEach(AST.getASTContext(), AST.getTokens(), - Test.point("unique"), Test.point("ambiguous"), - [&](SelectionTree T) { - ++Seen; - return false; - }); - EXPECT_EQ(1u, Seen) << "one tree for nontrivial selection"; -} - } // namespace } // namespace clangd } // namespace clang |