| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | /****************************************************************************
 | 
					
						
							|  |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** Copyright (C) 2016 The Qt Company Ltd. | 
					
						
							|  |  |  | ** Contact: https://www.qt.io/licensing/
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ** 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 | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** 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.
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | ** | 
					
						
							| 
									
										
										
										
											2016-01-15 14:55:33 +01:00
										 |  |  | ** 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.
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | ** | 
					
						
							|  |  |  | ****************************************************************************/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-09-15 17:41:41 +02:00
										 |  |  | #include "googletest.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | #include <clangcodemodel/clangcompletioncontextanalyzer.h>
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | #include <clangcodemodel/clangcompletionassistinterface.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <utils/qtcassert.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QTextDocument>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace ClangCodeModel { | 
					
						
							|  |  |  | namespace Internal { | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | void PrintTo(const ClangCompletionContextAnalyzer::CompletionAction &completionAction, | 
					
						
							|  |  |  |              ::std::ostream* os) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     using CCA = ClangCompletionContextAnalyzer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     switch (completionAction) { | 
					
						
							|  |  |  |         case CCA::PassThroughToLibClang: *os << "PassThroughToLibClang"; break; | 
					
						
							|  |  |  |         case CCA::PassThroughToLibClangAfterLeftParen: *os << "PassThroughToLibClangAfterLeftParen"; break; | 
					
						
							|  |  |  |         case CCA::CompleteDoxygenKeyword: *os << "CompleteDoxygenKeyword"; break; | 
					
						
							|  |  |  |         case CCA::CompleteIncludePath: *os << "CompleteIncludePath"; break; | 
					
						
							|  |  |  |         case CCA::CompletePreprocessorDirective: *os << "CompletePreprocessorDirective"; break; | 
					
						
							|  |  |  |         case CCA::CompleteSignal: *os << "CompleteSignal"; break; | 
					
						
							|  |  |  |         case CCA::CompleteSlot: *os << "CompleteSlot"; break; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | } // Internal
 | 
					
						
							|  |  |  | } // ClangCodeModel
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | using ::testing::PrintToString; | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | using ClangCodeModel::Internal::ClangCompletionAssistInterface; | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | using CCA = ClangCodeModel::Internal::ClangCompletionContextAnalyzer; | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | class TestDocument | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     TestDocument(const QByteArray &theSource) | 
					
						
							|  |  |  |         : source(theSource), | 
					
						
							|  |  |  |           position(theSource.lastIndexOf('@')) // Use 'lastIndexOf' due to doxygen: "//! @keyword"
 | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         source.remove(position, 1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     QByteArray source; | 
					
						
							|  |  |  |     int position; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | bool isPassThrough(CCA::CompletionAction completionAction) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return completionAction != CCA::PassThroughToLibClang | 
					
						
							|  |  |  |         && completionAction != CCA::PassThroughToLibClangAfterLeftParen; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | MATCHER(IsPassThroughToClang, std::string(negation ? "isn't" : "is") + " passed through to Clang") | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |     const auto completionAction = arg.completionAction(); | 
					
						
							|  |  |  |     if (isPassThrough(completionAction)) { | 
					
						
							|  |  |  |         *result_listener << "completion action is " << PrintToString(completionAction); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | // Offsets are relative to positionInText
 | 
					
						
							|  |  |  | MATCHER_P4(HasResult, | 
					
						
							|  |  |  |            completionAction, | 
					
						
							|  |  |  |            positionForClangOffset, | 
					
						
							|  |  |  |            positionForProposalOffset, | 
					
						
							|  |  |  |            positionInText, | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  |            std::string(negation ? "hasn't" : "has") | 
					
						
							|  |  |  |            + " result of completion action " + PrintToString(completionAction) | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |            + " and offset for clang " + PrintToString(positionForClangOffset) | 
					
						
							|  |  |  |            + " and offset for proprosal " + PrintToString(positionForProposalOffset)) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |     const int actualPositionForClangOffset = arg.positionForClang() - positionInText; | 
					
						
							|  |  |  |     const int actualPositionForProposalOffset = arg.positionForProposal() - positionInText; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  |     if (arg.completionAction() != completionAction | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |             || actualPositionForClangOffset != positionForClangOffset | 
					
						
							|  |  |  |             || actualPositionForProposalOffset != positionForProposalOffset) { | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  |         *result_listener << "completion action is " << PrintToString(arg.completionAction()) | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |                          << " and offset for clang is " <<  PrintToString(actualPositionForClangOffset) | 
					
						
							|  |  |  |                          << " and offset for proprosal is " <<  PrintToString(actualPositionForProposalOffset); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | // Offsets are relative to positionInText
 | 
					
						
							|  |  |  | MATCHER_P4(HasResultWithoutClangDifference, | 
					
						
							|  |  |  |            completionAction, | 
					
						
							|  |  |  |            positionForClangOffset, | 
					
						
							|  |  |  |            positionForProposalOffset, | 
					
						
							|  |  |  |            positionInText, | 
					
						
							|  |  |  |            std::string(negation ? "hasn't" : "has") | 
					
						
							|  |  |  |            + " result of completion action " + PrintToString(completionAction) | 
					
						
							|  |  |  |            + " and offset for clang " + PrintToString(positionForClangOffset) | 
					
						
							|  |  |  |            + " and offset for proprosal " + PrintToString(positionForProposalOffset)) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |     const int actualPositionForProposalOffset = arg.positionForProposal() - positionInText; | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |     if (arg.completionAction() != completionAction | 
					
						
							|  |  |  |             || arg.positionForClang() != positionForClangOffset | 
					
						
							|  |  |  |             || actualPositionForProposalOffset != positionForProposalOffset) { | 
					
						
							|  |  |  |         *result_listener << "completion action is " << PrintToString(arg.completionAction()) | 
					
						
							|  |  |  |                          << " and offset for clang is " <<  PrintToString(arg.positionForClang()) | 
					
						
							|  |  |  |                          << " and offset for proprosal is " <<  PrintToString(actualPositionForProposalOffset); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ClangCompletionContextAnalyzer : public ::testing::Test | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | protected: | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |     CCA runAnalyzer(const char *text); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     int positionInText = 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | CCA ClangCompletionContextAnalyzer::runAnalyzer(const char *text) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     const TestDocument testDocument(text); | 
					
						
							|  |  |  |     ClangCompletionAssistInterface assistInterface(testDocument.source, testDocument.position); | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  |     CCA analyzer(&assistInterface, CPlusPlus::LanguageFeatures::defaultFeatures()); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     positionInText = testDocument.position; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     analyzer.analyze(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return analyzer; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  | TEST_F(ClangCompletionContextAnalyzer, WordsBeforeCursor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("foo bar@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -3, -3, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterSpace) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("foo @"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | TEST_F(ClangCompletionContextAnalyzer, AtEndOfDotMember) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("o.mem@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -3, -3, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AtEndOfDotMemberWithSpaceInside) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("o. mem@"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -3, -3, positionInText)); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AtBeginOfDotMember) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("o.@mem"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AtBeginOfDotMemberWithSpaceInside) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("o. @mem"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AtEndOfArrow) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("o->mem@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -3, -3, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AtEndOfArrowWithSpaceInside) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("o-> mem@"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -3, -3, positionInText)); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AtBeginOfArrow) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("o->@mem"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AtBeginOfArrowWithSpaceInside) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("o-> @mem"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, ParameteOneAtCall) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("f(@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClangAfterLeftParen, -2, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, ParameteTwoAtCall) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("f(1,@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClangAfterLeftParen, -4, -2, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, ParameteTwoWithSpaceAtCall) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("f(1, @"); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClangAfterLeftParen, -5, -3, positionInText)); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-20 12:54:28 +02:00
										 |  |  | TEST_F(ClangCompletionContextAnalyzer, WhitespaceAfterFunctionName) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("foo (@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClangAfterLeftParen, -5, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterOpeningParenthesis) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("(@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | TEST_F(ClangCompletionContextAnalyzer, ParameteOneAtSignal) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("SIGNAL(@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::CompleteSignal, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, ParameteOneWithLettersAtSignal) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("SIGNAL(foo@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::CompleteSignal, -3, -3, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, ParameteOneAtSlot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("SLOT(@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::CompleteSlot, -0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, ParameteOneWithLettersAtSlot) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("SLOT(foo@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::CompleteSlot, -3, -3, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, DoxygenWithBackslash) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("//! \\@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResultWithoutClangDifference(CCA::CompleteDoxygenKeyword, -1, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, DoxygenWithAt) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("//! @@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResultWithoutClangDifference(CCA::CompleteDoxygenKeyword, -1, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, DoxygenWithParameter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("//! \\par@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResultWithoutClangDifference(CCA::CompleteDoxygenKeyword, -1, -3, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, Preprocessor) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("#@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResultWithoutClangDifference(CCA::CompletePreprocessorDirective, -1, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, PreprocessorIf) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("#if@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResultWithoutClangDifference(CCA::CompletePreprocessorDirective, -1, -2, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, LocalInclude) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("#include \"foo@\""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResultWithoutClangDifference(CCA::CompleteIncludePath, -1, -3, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, GlobalInclude) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("#include <foo@>"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResultWithoutClangDifference(CCA::CompleteIncludePath, -1, -3, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, GlocalIncludeWithDirectory) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("#include <foo/@>"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResultWithoutClangDifference(CCA::CompleteIncludePath, -1, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterQuote) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("\"@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterSpaceQuote) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer(" \"@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterQuotedText) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("\"text\"@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, InQuotedText) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("\"hello cruel@ world\""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, SingleQuote) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("'@'"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterLetterInSingleQuoted) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("'a@'"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, CommaOperator) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("a = b,@\""); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, DoxygenMarkerInNonDoxygenComment) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("@@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, DoxygenMarkerInNonDoxygenComment2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("\\@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  | TEST_F(ClangCompletionContextAnalyzer, AtEndOfOneLineComment) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  |     auto analyzer = runAnalyzer("// comment@"); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterOneLineCommentLine) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("// comment\n" | 
					
						
							|  |  |  |                                 "@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterEmptyOneLineComment) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("//\n" | 
					
						
							|  |  |  |                                 "@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterOneLineDoxygenComment1) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("/// comment\n" | 
					
						
							|  |  |  |                                 "@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AfterOneLineDoxygenComment2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("//! comment \n" | 
					
						
							|  |  |  |                                 "@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | TEST_F(ClangCompletionContextAnalyzer, BeginEndComment) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("/* text@ */"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, Slash) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("5 /@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, LeftParen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("(@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, TwoLeftParen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("((@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | TEST_F(ClangCompletionContextAnalyzer, AsteriskLeftParen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     auto analyzer = runAnalyzer("*(@"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(analyzer, IsPassThroughToClang()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 17:39:50 +02:00
										 |  |  | } |