2015-06-01 18:51:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://www.qt.io/licensing
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/licensing. For further information
|
|
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
|
**
|
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
|
|
#include "gmock/gmock-matchers.h"
|
|
|
|
|
#include "gmock/gmock-generated-matchers.h"
|
|
|
|
|
#include "gtest-qt-printing.h"
|
|
|
|
|
|
|
|
|
|
#include <clang-c/Index.h>
|
|
|
|
|
|
|
|
|
|
#include <codecompletionsextractor.h>
|
|
|
|
|
#include <clangcodecompleteresults.h>
|
|
|
|
|
#include <filecontainer.h>
|
|
|
|
|
#include <translationunit.h>
|
|
|
|
|
#include <unsavedfiles.h>
|
|
|
|
|
#include <projectpart.h>
|
|
|
|
|
#include <utf8stringvector.h>
|
|
|
|
|
|
|
|
|
|
#include <QFile>
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
using ClangBackEnd::CodeCompletionsExtractor;
|
|
|
|
|
using ClangBackEnd::ClangCodeCompleteResults;
|
|
|
|
|
using ClangBackEnd::TranslationUnit;
|
|
|
|
|
using ClangBackEnd::CodeCompletion;
|
|
|
|
|
using ClangBackEnd::UnsavedFiles;
|
|
|
|
|
using ClangBackEnd::CodeCompletionChunk;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
using ::testing::PrintToString;
|
|
|
|
|
using ::testing::Not;
|
|
|
|
|
|
|
|
|
|
MATCHER_P3(HasCompletion, name, kind, availability,
|
|
|
|
|
std::string(negation ? "hasn't" : "has") + " completion of name " + PrintToString(name) +
|
|
|
|
|
", kind " + PrintToString(kind))
|
|
|
|
|
{
|
|
|
|
|
::CodeCompletionsExtractor &extractor = const_cast<::CodeCompletionsExtractor&>(arg);
|
|
|
|
|
while (extractor.next()) {
|
|
|
|
|
if (extractor.currentCodeCompletion().text() == name) {
|
|
|
|
|
if (extractor.currentCodeCompletion().completionKind() == kind) {
|
|
|
|
|
if (extractor.currentCodeCompletion().availability() == availability) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (!extractor.peek(name)) {
|
|
|
|
|
*result_listener << "availability is " << PrintToString(extractor.currentCodeCompletion().availability()) << " and not " << PrintToString(availability);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
} else if (!extractor.peek(name)) {
|
|
|
|
|
*result_listener << "kind is " << PrintToString(extractor.currentCodeCompletion().completionKind()) << " and not " << PrintToString(kind);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MATCHER_P2(HasCompletionChunks, name, chunks,
|
|
|
|
|
std::string(negation ? "hasn't" : "has") + " completion of name " + PrintToString(name) +
|
|
|
|
|
" with the chunks " + PrintToString(chunks))
|
|
|
|
|
{
|
|
|
|
|
::CodeCompletionsExtractor &extractor = const_cast<::CodeCompletionsExtractor&>(arg);
|
|
|
|
|
while (extractor.next()) {
|
|
|
|
|
if (extractor.currentCodeCompletion().text() == name) {
|
|
|
|
|
if (extractor.currentCodeCompletion().chunks() == chunks) {
|
|
|
|
|
return true;
|
|
|
|
|
} else if (!extractor.peek(name)) {
|
|
|
|
|
*result_listener << "chunks are " << PrintToString(arg.currentCodeCompletion().chunks()) << " and not " << PrintToString(chunks);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const Utf8String unsavedFileContent(const char *unsavedFilePath)
|
|
|
|
|
{
|
|
|
|
|
QFile unsavedFileContentFile(QString::fromUtf8(unsavedFilePath));
|
|
|
|
|
bool isOpen = unsavedFileContentFile.open(QIODevice::ReadOnly | QIODevice::Text);
|
|
|
|
|
if (!isOpen)
|
2015-06-16 11:56:00 +02:00
|
|
|
ADD_FAILURE() << "File with the unsaved content cannot be opened!";
|
2015-06-01 18:51:55 +02:00
|
|
|
|
|
|
|
|
return Utf8String::fromByteArray(unsavedFileContentFile.readAll());
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
const ClangBackEnd::FileContainer unsavedDataFileContainer(const char *filePath,
|
|
|
|
|
const char *unsavedFilePath)
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2015-06-16 11:56:00 +02:00
|
|
|
return ClangBackEnd::FileContainer(Utf8String::fromUtf8(filePath),
|
|
|
|
|
Utf8String(),
|
|
|
|
|
unsavedFileContent(unsavedFilePath),
|
|
|
|
|
true);
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangCodeCompleteResults getResults(const TranslationUnit &translationUnit, uint line, uint column = 1)
|
|
|
|
|
{
|
|
|
|
|
return ClangCodeCompleteResults(clang_codeCompleteAt(translationUnit.cxTranslationUnit(),
|
|
|
|
|
translationUnit.filePath().constData(),
|
|
|
|
|
line,
|
|
|
|
|
column,
|
|
|
|
|
translationUnit.cxUnsavedFiles(),
|
|
|
|
|
translationUnit.unsavedFilesCount(),
|
|
|
|
|
CXCodeComplete_IncludeMacros | CXCodeComplete_IncludeCodePatterns));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CodeCompletionsExtractor : public ::testing::Test
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
static void TearDownTestCase();
|
|
|
|
|
|
|
|
|
|
protected:
|
2015-06-16 11:56:00 +02:00
|
|
|
static ClangBackEnd::ProjectPart project;
|
|
|
|
|
static ClangBackEnd::UnsavedFiles unsavedFiles;
|
2015-06-01 18:51:55 +02:00
|
|
|
static TranslationUnit functionTranslationUnit;
|
|
|
|
|
static TranslationUnit variableTranslationUnit;
|
|
|
|
|
static TranslationUnit classTranslationUnit ;
|
|
|
|
|
static TranslationUnit namespaceTranslationUnit;
|
|
|
|
|
static TranslationUnit enumerationTranslationUnit;
|
|
|
|
|
static TranslationUnit constructorTranslationUnit;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-16 11:56:00 +02:00
|
|
|
ClangBackEnd::ProjectPart CodeCompletionsExtractor::project(Utf8StringLiteral("/path/to/projectfile"));
|
|
|
|
|
ClangBackEnd::UnsavedFiles CodeCompletionsExtractor::unsavedFiles;
|
2015-06-01 18:51:55 +02:00
|
|
|
TranslationUnit CodeCompletionsExtractor::functionTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project);
|
|
|
|
|
TranslationUnit CodeCompletionsExtractor::variableTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_variable.cpp"), unsavedFiles, project);
|
|
|
|
|
TranslationUnit CodeCompletionsExtractor::classTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_class.cpp"), unsavedFiles, project);
|
|
|
|
|
TranslationUnit CodeCompletionsExtractor::namespaceTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_namespace.cpp"), unsavedFiles, project);
|
|
|
|
|
TranslationUnit CodeCompletionsExtractor::enumerationTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_enumeration.cpp"), unsavedFiles, project);
|
|
|
|
|
TranslationUnit CodeCompletionsExtractor::constructorTranslationUnit(Utf8StringLiteral(TESTDATA_DIR"/complete_extractor_constructor.cpp"), unsavedFiles, project);
|
|
|
|
|
|
|
|
|
|
void CodeCompletionsExtractor::TearDownTestCase()
|
|
|
|
|
{
|
|
|
|
|
functionTranslationUnit.reset();
|
|
|
|
|
variableTranslationUnit.reset();
|
|
|
|
|
classTranslationUnit.reset();
|
|
|
|
|
namespaceTranslationUnit.reset();
|
|
|
|
|
enumerationTranslationUnit.reset();
|
|
|
|
|
constructorTranslationUnit.reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Function)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Function"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, TemplateFunction)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateFunction"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::TemplateFunctionCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Variable)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 4));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Var"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::VariableCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, NonTypeTemplateParameter)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 25, 19));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NonTypeTemplateParameter"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::VariableCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, VariableReference)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 12));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Var"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::VariableCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Parameter)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 4));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Parameter"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::VariableCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Field)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Field"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::VariableCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Class)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Class"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::ClassCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Struct)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Struct"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::ClassCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Union)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Union"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::ClassCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, TemplateTypeParameter)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateTypeParameter"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::ClassCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, TemplateClass)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateClass"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::TemplateClassCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, TemplateTemplateParameter)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("TemplateTemplateParameter"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::TemplateClassCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, ClassTemplatePartialSpecialization)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("ClassTemplatePartialSpecialization"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::TemplateClassCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Namespace)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(namespaceTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Namespace"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::NamespaceCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, NamespaceAlias)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(namespaceTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NamespaceAlias"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::NamespaceCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Enumeration)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Enumeration"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::EnumerationCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Enumerator)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Enumerator"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::EnumeratorCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Constructor)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(constructorTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Constructor"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::ConstructorCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Destructor)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(constructorTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("~Constructor"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::DestructorCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Method)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_FALSE(extractor.currentCodeCompletion().hasParameters());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, MethodWithParameters)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("MethodWithParameters"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
ASSERT_TRUE(extractor.currentCodeCompletion().hasParameters());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Slot)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Slot"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::SlotCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, Signal)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Signal"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::SignalCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, MacroDefinition)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("MacroDefinition"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::PreProcessorCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, FunctionMacro)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("FunctionMacro"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, IntKeyword)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("int"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::KeywordCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, SwitchKeyword)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("switch"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::KeywordCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, ClassKeyword)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("class"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::KeywordCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, DeprecatedFunction)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("DeprecatedFunction"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::Deprecated));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, NotAccessibleFunction)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NotAccessibleFunction"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::NotAccessible));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, NotAvailableFunction)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("NotAvailableFunction"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::NotAvailable));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, UnsavedFile)
|
|
|
|
|
{
|
2015-06-16 11:56:00 +02:00
|
|
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
|
|
|
|
ClangBackEnd::ProjectPart project(Utf8StringLiteral("/path/to/projectfile"));
|
2015-06-01 18:51:55 +02:00
|
|
|
TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project);
|
|
|
|
|
unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp",
|
2015-06-16 11:56:00 +02:00
|
|
|
TESTDATA_DIR"/complete_extractor_function_unsaved.cpp")});
|
2015-06-01 18:51:55 +02:00
|
|
|
ClangCodeCompleteResults completeResults(getResults(translationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method2"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, ChangeUnsavedFile)
|
|
|
|
|
{
|
2015-06-16 11:56:00 +02:00
|
|
|
ClangBackEnd::UnsavedFiles unsavedFiles;
|
|
|
|
|
ClangBackEnd::ProjectPart project(Utf8StringLiteral("/path/to/projectfile"));
|
2015-06-01 18:51:55 +02:00
|
|
|
TranslationUnit translationUnit(Utf8String::fromUtf8(TESTDATA_DIR"/complete_extractor_function.cpp"), unsavedFiles, project);
|
|
|
|
|
unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp",
|
2015-06-16 11:56:00 +02:00
|
|
|
TESTDATA_DIR"/complete_extractor_function_unsaved.cpp")});
|
2015-06-01 18:51:55 +02:00
|
|
|
ClangCodeCompleteResults completeResults(getResults(translationUnit, 20));
|
|
|
|
|
unsavedFiles.createOrUpdate({unsavedDataFileContainer(TESTDATA_DIR"/complete_extractor_function.cpp",
|
2015-06-16 11:56:00 +02:00
|
|
|
TESTDATA_DIR"/complete_extractor_function_unsaved_2.cpp")});
|
2015-06-01 18:51:55 +02:00
|
|
|
completeResults = getResults(translationUnit, 20);
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("Method3"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::FunctionCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, ArgumentDefinition)
|
|
|
|
|
{
|
|
|
|
|
variableTranslationUnit.cxTranslationUnit();
|
|
|
|
|
project.setArguments({Utf8StringLiteral("-DArgumentDefinition")});
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::VariableCompletionKind,
|
|
|
|
|
CodeCompletion::Available));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, NoArgumentDefinition)
|
|
|
|
|
{
|
|
|
|
|
variableTranslationUnit.cxTranslationUnit();
|
|
|
|
|
project.setArguments(Utf8StringVector());
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 35));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, Not(HasCompletion(Utf8StringLiteral("ArgumentDefinitionVariable"),
|
2015-06-16 11:56:00 +02:00
|
|
|
CodeCompletion::VariableCompletionKind,
|
|
|
|
|
CodeCompletion::Available)));
|
2015-06-01 18:51:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, CompletionChunksFunction)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Function"),
|
|
|
|
|
QVector<CodeCompletionChunk>({{CodeCompletionChunk::ResultType, Utf8StringLiteral("void")},
|
|
|
|
|
{CodeCompletionChunk::TypedText, Utf8StringLiteral("Function")},
|
|
|
|
|
{CodeCompletionChunk::LeftParen, Utf8StringLiteral("(")},
|
|
|
|
|
{CodeCompletionChunk::RightParen, Utf8StringLiteral(")")}})));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, CompletionChunksFunctionWithOptionalChunks)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(functionTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("FunctionWithOptional"),
|
|
|
|
|
QVector<CodeCompletionChunk>({{CodeCompletionChunk::ResultType, Utf8StringLiteral("void")},
|
|
|
|
|
{CodeCompletionChunk::TypedText, Utf8StringLiteral("FunctionWithOptional")},
|
|
|
|
|
{CodeCompletionChunk::LeftParen, Utf8StringLiteral("(")},
|
|
|
|
|
{CodeCompletionChunk::Placeholder, Utf8StringLiteral("int x")},
|
|
|
|
|
{CodeCompletionChunk::Optional, Utf8String(), QVector<CodeCompletionChunk>({
|
|
|
|
|
{CodeCompletionChunk::Comma, Utf8StringLiteral(", ")},
|
|
|
|
|
{CodeCompletionChunk::Placeholder, Utf8StringLiteral("char y")},
|
|
|
|
|
{CodeCompletionChunk::Comma, Utf8StringLiteral(", ")},
|
|
|
|
|
{CodeCompletionChunk::Placeholder, Utf8StringLiteral("int z")}})},
|
|
|
|
|
{CodeCompletionChunk::RightParen, Utf8StringLiteral(")")}})));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, CompletionChunksField)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(variableTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Field"),
|
|
|
|
|
QVector<CodeCompletionChunk>({{CodeCompletionChunk::ResultType, Utf8StringLiteral("int")},
|
|
|
|
|
{CodeCompletionChunk::TypedText, Utf8StringLiteral("Field")}})));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, CompletionChunksEnumerator)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Enumerator"),
|
|
|
|
|
QVector<CodeCompletionChunk>({{CodeCompletionChunk::ResultType, Utf8StringLiteral("Enumeration")},
|
|
|
|
|
{CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumerator")}})));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, CompletionChunksEnumeration)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(enumerationTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Enumeration"),
|
|
|
|
|
QVector<CodeCompletionChunk>({{CodeCompletionChunk::TypedText, Utf8StringLiteral("Enumeration")}})));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TEST_F(CodeCompletionsExtractor, CompletionChunksClass)
|
|
|
|
|
{
|
|
|
|
|
ClangCodeCompleteResults completeResults(getResults(classTranslationUnit, 20));
|
|
|
|
|
|
|
|
|
|
::CodeCompletionsExtractor extractor(completeResults.data());
|
|
|
|
|
|
|
|
|
|
ASSERT_THAT(extractor, HasCompletionChunks(Utf8StringLiteral("Class"),
|
|
|
|
|
QVector<CodeCompletionChunk>({{CodeCompletionChunk::TypedText, Utf8StringLiteral("Class")}})));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|