forked from qt-creator/qt-creator
Clang: Add unit-tests for function overloads completion order
Make sure that the same function overloads with different priorities come together in the completions list. Fixes the case when we complete the method without '.' or '->'. Change-Id: Icaf7ea47f5e58b3ae5cc9764ad79c857f6f6e231 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
This commit is contained in:
@@ -115,7 +115,9 @@ static void adaptOverloadsPriorities(CodeCompletions &codeCompletions)
|
||||
std::map<Utf8String, std::vector<CodeCompletion *>> cachedOverloads;
|
||||
for (CodeCompletion ¤tCompletion : codeCompletions) {
|
||||
if (currentCompletion.completionKind != CodeCompletion::ConstructorCompletionKind
|
||||
&& currentCompletion.completionKind != CodeCompletion::FunctionCompletionKind) {
|
||||
&& currentCompletion.completionKind != CodeCompletion::FunctionCompletionKind
|
||||
&& currentCompletion.completionKind
|
||||
!= CodeCompletion::FunctionDefinitionCompletionKind) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@@ -580,6 +580,51 @@ TEST_F(CodeCompleterSlowTest, ConstructorHasOverloadCompletions)
|
||||
ASSERT_THAT(constructorsCount, 2);
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleterSlowTest, FunctionOverloadsNoParametersOrder)
|
||||
{
|
||||
auto myCompleter = setupCompleter(completionsOrder);
|
||||
const ClangBackEnd::CodeCompletions completions = myCompleter.complete(27, 7);
|
||||
|
||||
int firstIndex = Utils::indexOf(completions, [](const CodeCompletion &codeCompletion) {
|
||||
return codeCompletion.text == "foo";
|
||||
});
|
||||
int secondIndex = Utils::indexOf(completions, [i = 0, firstIndex](const CodeCompletion &codeCompletion) mutable {
|
||||
return (i++) > firstIndex && codeCompletion.text == "foo";
|
||||
});
|
||||
|
||||
ASSERT_THAT(abs(firstIndex - secondIndex), 1);
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleterSlowTest, FunctionOverloadsWithParametersOrder)
|
||||
{
|
||||
auto myCompleter = setupCompleter(completionsOrder);
|
||||
const ClangBackEnd::CodeCompletions completions = myCompleter.complete(27, 7);
|
||||
|
||||
int firstIndex = Utils::indexOf(completions, [](const CodeCompletion &codeCompletion) {
|
||||
return codeCompletion.text == "bar";
|
||||
});
|
||||
int secondIndex = Utils::indexOf(completions, [i = 0, firstIndex](const CodeCompletion &codeCompletion) mutable {
|
||||
return (i++) > firstIndex && codeCompletion.text == "bar";
|
||||
});
|
||||
|
||||
ASSERT_THAT(abs(firstIndex - secondIndex), 1);
|
||||
}
|
||||
|
||||
TEST_F(CodeCompleterSlowTest, FunctionOverloadsWithoutDotOrArrowOrder)
|
||||
{
|
||||
auto myCompleter = setupCompleter(completionsOrder);
|
||||
const ClangBackEnd::CodeCompletions completions = myCompleter.complete(21, 1);
|
||||
|
||||
int firstIndex = Utils::indexOf(completions, [](const CodeCompletion &codeCompletion) {
|
||||
return codeCompletion.text == "bar";
|
||||
});
|
||||
int secondIndex = Utils::indexOf(completions, [i = 0, firstIndex](const CodeCompletion &codeCompletion) mutable {
|
||||
return (i++) > firstIndex && codeCompletion.text == "bar";
|
||||
});
|
||||
|
||||
ASSERT_THAT(abs(firstIndex - secondIndex), 1);
|
||||
}
|
||||
|
||||
ClangBackEnd::CodeCompleter CodeCompleter::setupCompleter(
|
||||
const ClangBackEnd::FileContainer &fileContainer)
|
||||
{
|
||||
|
@@ -7,3 +7,22 @@ public:
|
||||
void testConstructor() {
|
||||
|
||||
}
|
||||
|
||||
class Base {
|
||||
virtual void bar(int a) const;
|
||||
};
|
||||
|
||||
class DifferentPriorities : public Base {
|
||||
public:
|
||||
void foo();
|
||||
void foo() const;
|
||||
void bar(int a) const override;
|
||||
void testBar() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
void testPriorities() {
|
||||
DifferentPriorities d;
|
||||
d.
|
||||
}
|
||||
|
Reference in New Issue
Block a user