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:
Ivan Donchevskii
2018-10-25 10:03:21 +02:00
parent fe87339888
commit 93269f3ecd
3 changed files with 67 additions and 1 deletions

View File

@@ -115,7 +115,9 @@ static void adaptOverloadsPriorities(CodeCompletions &codeCompletions)
std::map<Utf8String, std::vector<CodeCompletion *>> cachedOverloads; std::map<Utf8String, std::vector<CodeCompletion *>> cachedOverloads;
for (CodeCompletion &currentCompletion : codeCompletions) { for (CodeCompletion &currentCompletion : codeCompletions) {
if (currentCompletion.completionKind != CodeCompletion::ConstructorCompletionKind if (currentCompletion.completionKind != CodeCompletion::ConstructorCompletionKind
&& currentCompletion.completionKind != CodeCompletion::FunctionCompletionKind) { && currentCompletion.completionKind != CodeCompletion::FunctionCompletionKind
&& currentCompletion.completionKind
!= CodeCompletion::FunctionDefinitionCompletionKind) {
continue; continue;
} }

View File

@@ -580,6 +580,51 @@ TEST_F(CodeCompleterSlowTest, ConstructorHasOverloadCompletions)
ASSERT_THAT(constructorsCount, 2); 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( ClangBackEnd::CodeCompleter CodeCompleter::setupCompleter(
const ClangBackEnd::FileContainer &fileContainer) const ClangBackEnd::FileContainer &fileContainer)
{ {

View File

@@ -7,3 +7,22 @@ public:
void testConstructor() { 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.
}