Files
qt-creator/tests/unit/unittest/activationsequencecontextprocessor-test.cpp
Nikolai Kosjar 7cbc7af022 Clang: Fix completion after qualification (::)
...and maybe other cases.

Since

    Clang: fix findStartOfName handling
    commit 82d0650b11

the proposal's base position was calculated wrong. As a result, an early
return triggert in CodeAssistantPrivate::displayProposal (call to
newProposal->hasItemsToPropose(prefix, reason)) and no completions were
displayed.

Fix by ensuring that the added code from the mentioned commit is only
called when needed, namely only for function expressions.

Task-number: QTCREATORBUG-19083
Change-Id: I8f23c9b7186f9d81159939c8b3ef475a09bbe760
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-10-19 07:43:21 +00:00

222 lines
6.9 KiB
C++

/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://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 The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
****************************************************************************/
#include "googletest.h"
#include <clangactivationsequencecontextprocessor.h>
#include <clangcodemodel/clangcompletionassistinterface.h>
#include <cplusplus/Token.h>
#include <QTextCursor>
#include <QTextDocument>
namespace {
using ContextProcessor = ClangCodeModel::Internal::ActivationSequenceContextProcessor;
using TextEditor::AssistInterface;
using ClangCodeModel::Internal::ClangCompletionAssistInterface;
TEST(ActivationSequenceContextProcessorSlowTest, TextCursorPosition)
{
ClangCompletionAssistInterface interface("foobar", 4);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.textCursor_forTestOnly().position(), 0);
}
TEST(ActivationSequenceContextProcessor, StringLiteral)
{
ClangCompletionAssistInterface interface("auto foo = \"bar\"", 12);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, EndOfStringLiteral)
{
ClangCompletionAssistInterface interface("auto foo = \"bar\"", 16);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, FunctionCallComma)
{
ClangCompletionAssistInterface interface("f(x, ", 4);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_COMMA);
}
TEST(ActivationSequenceContextProcessor, NonFunctionCallComma)
{
ClangCompletionAssistInterface interface("int x, ", 6);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, DoxygenComment)
{
ClangCompletionAssistInterface interface("//! @", 5);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_DOXY_COMMENT);
}
TEST(ActivationSequenceContextProcessor, NonDoxygenComment)
{
ClangCompletionAssistInterface interface("// @", 4);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, Comment)
{
ClangCompletionAssistInterface interface("//", 2);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, InsideALiteral)
{
ClangCompletionAssistInterface interface("\"foo\"", 2);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, ShlashInsideAString)
{
ClangCompletionAssistInterface interface("\"foo/bar\"", 5);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, ShlashOutsideAString)
{
ClangCompletionAssistInterface interface("foo/bar", 4);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, FunctionLeftParen)
{
ClangCompletionAssistInterface interface("foo(", 4);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_LPAREN);
}
TEST(ActivationSequenceContextProcessor, TemplateFunctionLeftParen)
{
ClangCompletionAssistInterface interface("foo<X>(", 7);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_LPAREN);
}
TEST(ActivationSequenceContextProcessor, TemplateFunctionSecondParameter)
{
ClangCompletionAssistInterface interface("foo<X>(", 7);
int startOfname = ContextProcessor::findStartOfName(&interface,
6,
ContextProcessor::NameCategory::Function);
ASSERT_THAT(startOfname, 0);
}
TEST(ActivationSequenceContextProcessor, ExpressionLeftParen)
{
ClangCompletionAssistInterface interface("x * (", 5);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, AngleInclude)
{
ClangCompletionAssistInterface interface("#include <foo/bar>", 10);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_ANGLE_STRING_LITERAL);
}
TEST(ActivationSequenceContextProcessor, SlashInclude)
{
ClangCompletionAssistInterface interface("#include <foo/bar>", 14);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_SLASH);
}
TEST(ActivationSequenceContextProcessor, QuoteInclude)
{
ClangCompletionAssistInterface interface("#include \"foo/bar\"", 10);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_STRING_LITERAL);
}
TEST(ActivationSequenceContextProcessor, SlashInExlude)
{
ClangCompletionAssistInterface interface("#exclude <foo/bar>", 14);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, QuoteExclude)
{
ClangCompletionAssistInterface interface("#exclude \"foo/bar\"", 10);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL);
}
TEST(ActivationSequenceContextProcessor, SkipeWhiteSpacesBeforeCursor)
{
ClangCompletionAssistInterface interface("x-> ", 7);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_ARROW);
}
TEST(ActivationSequenceContextProcessor, SkipIdentifier)
{
ClangCompletionAssistInterface interface("x->foo_", 7);
ContextProcessor processor{&interface};
ASSERT_THAT(processor.completionKind(), CPlusPlus::T_ARROW);
}
}