forked from qt-creator/qt-creator
ClangCodeModel: Move a test over from unittest
Change-Id: Iac295216fff274fbe4a109477b1a4c2bd2c98d5d Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -46,6 +46,7 @@ extend_qtc_plugin(ClangCodeModel
|
||||
extend_qtc_plugin(ClangCodeModel
|
||||
CONDITION WITH_TESTS
|
||||
SOURCES
|
||||
test/activationsequenceprocessortest.cpp test/activationsequenceprocessortest.h
|
||||
test/clangbatchfileprocessor.cpp test/clangbatchfileprocessor.h
|
||||
test/clangdtests.cpp test/clangdtests.h
|
||||
test/clangfixittest.cpp test/clangfixittest.h
|
||||
|
@@ -92,6 +92,8 @@ QtcPlugin {
|
||||
condition: qtc.testsEnabled
|
||||
prefix: "test/"
|
||||
files: [
|
||||
"activationsequenceprocessortest.cpp",
|
||||
"activationsequenceprocessortest.h",
|
||||
"clangbatchfileprocessor.cpp",
|
||||
"clangbatchfileprocessor.h",
|
||||
"clangdtests.cpp",
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "clangutils.h"
|
||||
|
||||
#ifdef WITH_TESTS
|
||||
# include "test/activationsequenceprocessortest.h"
|
||||
# include "test/clangbatchfileprocessor.h"
|
||||
# include "test/clangdtests.h"
|
||||
# include "test/clangfixittest.h"
|
||||
@@ -203,6 +204,7 @@ void ClangCodeModelPlugin::maybeHandleBatchFileAndExit() const
|
||||
QVector<QObject *> ClangCodeModelPlugin::createTestObjects() const
|
||||
{
|
||||
return {
|
||||
new Tests::ActivationSequenceProcessorTest,
|
||||
new Tests::ClangdTestCompletion,
|
||||
new Tests::ClangdTestExternalChanges,
|
||||
new Tests::ClangdTestFindReferences,
|
||||
@@ -215,6 +217,5 @@ QVector<QObject *> ClangCodeModelPlugin::createTestObjects() const
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Clang
|
||||
|
@@ -0,0 +1,180 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2022 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 "activationsequenceprocessortest.h"
|
||||
|
||||
#include "../clangactivationsequenceprocessor.h"
|
||||
|
||||
#include <cplusplus/Token.h>
|
||||
|
||||
#include <QtTest>
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
namespace ClangCodeModel::Internal::Tests {
|
||||
|
||||
static bool resultIs(const ActivationSequenceProcessor &processor, Kind expectedKind,
|
||||
int expectedOffset, int expectedNewPos)
|
||||
{
|
||||
return processor.completionKind() == expectedKind
|
||||
&& processor.offset() == expectedOffset
|
||||
&& processor.operatorStartPosition() == expectedNewPos;
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testCouldNotProcesseRandomCharacters()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("xxx"), 3, false);
|
||||
QVERIFY(resultIs(processor, T_EOF_SYMBOL, 0, 3));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testCouldNotProcesseEmptyString()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(""), 0, true);
|
||||
QVERIFY(resultIs(processor, T_EOF_SYMBOL, 0, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testDot()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("."), 1, true);
|
||||
QVERIFY(resultIs(processor, T_DOT, 1, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testComma()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(","), 2, false);
|
||||
QVERIFY(resultIs(processor, T_COMMA, 1, 1));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testLeftParenAsFunctionCall()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("("), 3, true);
|
||||
QVERIFY(resultIs(processor, T_LPAREN, 1, 2));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testLeftParenNotAsFunctionCall()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("("), 3, false);
|
||||
QVERIFY(resultIs(processor, T_EOF_SYMBOL, 0, 3));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testColonColon()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("::"), 20, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_COLON_COLON, 2, 18));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testArrow()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("->"), 2, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_ARROW, 2, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testDotStar()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(".*"), 3, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_DOT_STAR, 2, 1));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testArrowStar()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("->*"), 3, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_ARROW_STAR, 3, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testDoxyGenCommentBackSlash()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(" \\"), 3, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_DOXY_COMMENT, 1, 2));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testDoxyGenCommentAt()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(" @"), 2, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_DOXY_COMMENT, 1, 1));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testAngleStringLiteral()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("<"), 1, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_ANGLE_STRING_LITERAL, 1, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testStringLiteral()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("\""), 1, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_STRING_LITERAL, 1, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testSlash()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("/"), 1, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_SLASH, 1, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testPound()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("#"), 1, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_POUND, 1, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testPositionIsOne()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("<xx"), 1, false);
|
||||
|
||||
QVERIFY(resultIs(processor, T_ANGLE_STRING_LITERAL, 1, 0));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testPositionIsTwo()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(" @x"), 2, true);
|
||||
|
||||
QVERIFY(resultIs(processor, T_DOXY_COMMENT, 1, 1));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testPositionIsTwoWithASingleSign()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("x<x"), 2, false);
|
||||
|
||||
QVERIFY(resultIs(processor, T_ANGLE_STRING_LITERAL, 1, 1));
|
||||
}
|
||||
|
||||
void ActivationSequenceProcessorTest::testPositionIsThree()
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("xx<"), 3, false);
|
||||
|
||||
QVERIFY(resultIs(processor, T_ANGLE_STRING_LITERAL, 1, 2));
|
||||
}
|
||||
|
||||
} // namespace ClangCodeModel::Internal::Tests
|
@@ -0,0 +1,59 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2022 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.
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QObject>
|
||||
|
||||
namespace ClangCodeModel::Internal::Tests {
|
||||
|
||||
class ActivationSequenceProcessorTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void testCouldNotProcesseRandomCharacters();
|
||||
void testCouldNotProcesseEmptyString();
|
||||
void testDot();
|
||||
void testComma();
|
||||
void testLeftParenAsFunctionCall();
|
||||
void testLeftParenNotAsFunctionCall();
|
||||
void testColonColon();
|
||||
void testArrow();
|
||||
void testDotStar();
|
||||
void testArrowStar();
|
||||
void testDoxyGenCommentBackSlash();
|
||||
void testDoxyGenCommentAt();
|
||||
void testAngleStringLiteral();
|
||||
void testStringLiteral();
|
||||
void testSlash();
|
||||
void testPound();
|
||||
void testPositionIsOne();
|
||||
void testPositionIsTwo();
|
||||
void testPositionIsTwoWithASingleSign();
|
||||
void testPositionIsThree();
|
||||
};
|
||||
|
||||
} // namespace ClangCodeModel::Internal::Tests
|
@@ -143,7 +143,6 @@ add_custom_command(TARGET unittest POST_BUILD
|
||||
|
||||
extend_qtc_test(unittest
|
||||
SOURCES
|
||||
activationsequenceprocessor-test.cpp
|
||||
readexporteddiagnostics-test.cpp
|
||||
)
|
||||
|
||||
@@ -328,12 +327,6 @@ endif()
|
||||
|
||||
extend_qtc_test(unittest DEPENDS Utils CPlusPlus)
|
||||
|
||||
extend_qtc_test(unittest
|
||||
SOURCES_PREFIX ../../../src/plugins/clangcodemodel
|
||||
SOURCES
|
||||
clangactivationsequenceprocessor.cpp clangactivationsequenceprocessor.h
|
||||
)
|
||||
|
||||
find_package(yaml-cpp QUIET MODULE)
|
||||
|
||||
extend_qtc_test(unittest
|
||||
|
@@ -1,195 +0,0 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 <clangactivationsequenceprocessor.h>
|
||||
|
||||
#include <cplusplus/Token.h>
|
||||
|
||||
namespace {
|
||||
|
||||
using testing::PrintToString;
|
||||
using namespace CPlusPlus;
|
||||
using ClangCodeModel::Internal::ActivationSequenceProcessor;
|
||||
|
||||
MATCHER_P3(HasResult, completionKind, offset, newPosition,
|
||||
std::string(negation ? "hasn't" : "has")
|
||||
+ " result of completion kind " + PrintToString(Token::name(completionKind))
|
||||
+ ", offset " + PrintToString(offset)
|
||||
+ " and new operator start position" + PrintToString(newPosition))
|
||||
{
|
||||
if (arg.completionKind() != completionKind
|
||||
|| arg.offset() != offset
|
||||
|| arg.operatorStartPosition() != newPosition) {
|
||||
*result_listener << "completion kind is " << PrintToString(Token::name(arg.completionKind()))
|
||||
<< ", offset is " << PrintToString(arg.offset())
|
||||
<< " and new operator start position is " << PrintToString(arg.operatorStartPosition());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, CouldNotProcesseRandomCharacters)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("xxx"), 3, false);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_EOF_SYMBOL, 0, 3));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, CouldNotProcesseEmptyString)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(""), 0, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_EOF_SYMBOL, 0, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, Dot)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("."), 1, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_DOT, 1, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, Comma)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(","), 2, false);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_COMMA, 1, 1));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, LeftParenAsFunctionCall)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("("), 3, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_LPAREN, 1, 2));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, LeftParenNotAsFunctionCall)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("("), 3, false);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_EOF_SYMBOL, 0, 3));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, ColonColon)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("::"), 20, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_COLON_COLON, 2, 18));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, Arrow)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("->"), 2, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_ARROW, 2, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, DotStar)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(".*"), 3, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_DOT_STAR, 2, 1));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, ArrowStar)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("->*"), 3, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_ARROW_STAR, 3, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, DoxyGenCommentBackSlash)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(" \\"), 3, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_DOXY_COMMENT, 1, 2));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, DoxyGenCommentAt)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(" @"), 2, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_DOXY_COMMENT, 1, 1));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, AngleStringLiteral)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("<"), 1, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_ANGLE_STRING_LITERAL, 1, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, StringLiteral)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("\""), 1, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_STRING_LITERAL, 1, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, Slash)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("/"), 1, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_SLASH, 1, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, Pound)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("#"), 1, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_POUND, 1, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, PositionIsOne)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("<xx"), 1, false);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_ANGLE_STRING_LITERAL, 1, 0));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, PositionIsTwo)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral(" @x"), 2, true);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_DOXY_COMMENT, 1, 1));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, PositionIsTwoWithASingleSign)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("x<x"), 2, false);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_ANGLE_STRING_LITERAL, 1, 1));
|
||||
}
|
||||
|
||||
TEST(ActivationSequenceProcessor, PositionIsThree)
|
||||
{
|
||||
ActivationSequenceProcessor processor(QStringLiteral("xx<"), 3, false);
|
||||
|
||||
ASSERT_THAT(processor, HasResult(T_ANGLE_STRING_LITERAL, 1, 2));
|
||||
}
|
||||
}
|
@@ -176,7 +176,6 @@ Project {
|
||||
name: "libclang tests"
|
||||
condition: libclang.present && (!qbs.targetOS.contains("windows") || libclang.llvmBuildModeMatches)
|
||||
files: [
|
||||
"activationsequenceprocessor-test.cpp",
|
||||
"readexporteddiagnostics-test.cpp",
|
||||
]
|
||||
}
|
||||
@@ -196,15 +195,6 @@ Project {
|
||||
fileTags: []
|
||||
}
|
||||
|
||||
Group {
|
||||
name: "sources from clangcodemodel"
|
||||
prefix: "../../../src/plugins/clangcodemodel/"
|
||||
files: [
|
||||
"clangactivationsequenceprocessor.cpp",
|
||||
"clangactivationsequenceprocessor.h",
|
||||
]
|
||||
}
|
||||
|
||||
Group {
|
||||
name: "sources from cppeditor"
|
||||
prefix: "../../../src/plugins/cppeditor/"
|
||||
|
Reference in New Issue
Block a user