| 
									
										
										
										
											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-11-30 09:43:50 +01:00
										 |  |  | #include <clangactivationsequencecontextprocessor.h>
 | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #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; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessorSlowTest, TextCursorPosition) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("foobar", 4); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-07-23 16:06:48 +02:00
										 |  |  |     ASSERT_THAT(processor.textCursor_forTestOnly().position(), 0); | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, StringLiteral) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("auto foo = \"bar\"", 12); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, EndOfStringLiteral) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("auto foo = \"bar\"", 16); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, FunctionCallComma) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("f(x, ", 4); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_COMMA); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, NonFunctionCallComma) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("int x, ", 6); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, DoxygenComment) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("//! @", 5); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_DOXY_COMMENT); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, NonDoxygenComment) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("// @", 4); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, Comment) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("//", 2); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, InsideALiteral) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("\"foo\"", 2); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, ShlashInsideAString) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("\"foo/bar\"", 5); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, ShlashOutsideAString) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("foo/bar", 4); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, FunctionLeftParen) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("foo(", 4); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_LPAREN); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, TemplateFunctionLeftParen) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("foo<X>(", 7); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_LPAREN); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-10 09:57:18 +02:00
										 |  |  | TEST(ActivationSequenceContextProcessor, TemplateFunctionSecondParameter) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("foo<X>(", 7); | 
					
						
							| 
									
										
										
										
											2017-10-17 12:48:07 +02:00
										 |  |  |     int startOfname = ContextProcessor::findStartOfName(&interface, | 
					
						
							|  |  |  |                                                         6, | 
					
						
							|  |  |  |                                                         ContextProcessor::NameCategory::Function); | 
					
						
							| 
									
										
										
										
											2017-08-10 09:57:18 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(startOfname, 0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, ExpressionLeftParen) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("x * (", 5); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, AngleInclude) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("#include <foo/bar>", 10); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_ANGLE_STRING_LITERAL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, SlashInclude) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("#include <foo/bar>", 14); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_SLASH); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, QuoteInclude) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("#include \"foo/bar\"", 10); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_STRING_LITERAL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, SlashInExlude) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("#exclude <foo/bar>", 14); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, QuoteExclude) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("#exclude \"foo/bar\"", 10); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_EOF_SYMBOL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, SkipeWhiteSpacesBeforeCursor) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("x->    ", 7); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_ARROW); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-04 11:39:17 +01:00
										 |  |  | TEST(ActivationSequenceContextProcessor, SkipIdentifier) | 
					
						
							| 
									
										
										
										
											2015-07-23 13:01:02 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     ClangCompletionAssistInterface interface("x->foo_", 7); | 
					
						
							|  |  |  |     ContextProcessor processor{&interface}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ASSERT_THAT(processor.completionKind(), CPlusPlus::T_ARROW); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |