summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-07-23 16:06:48 +0200
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-07-27 13:19:02 +0000
commit91429aa7521dff2006451577514c8954fcc3f793 (patch)
treeaaa7bcdc1b44b78a9696f254d04fc7892f7a6833 /tests
parent49b1d357789e4920245bf15d7f1d5cc727657000 (diff)
downloadqt-creator-91429aa7521dff2006451577514c8954fcc3f793.tar.gz
Clang: Fix completion position for clang and proposal
* Rename some members/functions to clarify their meaning. * Ensure that the position for the proposal widget is at start of the identifer, so that the filter prefix will be found correctly in the GenericProposalWidget. For certain cases the completion were calculated but the widget was never shown: Case 1: void f() { <COMPLETION_CURSOR> } Case 2: void f() { st<COMPLETION_CURSOR> } Case 3: if (true) <COMPLETION_CURSOR> Case 4: foo. mem<COMPLETION_CURSOR> Change-Id: Ie79e01e8a22f8ec306136ec4ccbfffd544edd573 Reviewed-by: Erik Verbruggen <erik.verbruggen@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/unittest/activationsequencecontextprocessortest.cpp2
-rw-r--r--tests/unit/unittest/activationsequenceprocessortest.cpp6
-rw-r--r--tests/unit/unittest/clangcompletioncontextanalyzertest.cpp60
3 files changed, 57 insertions, 11 deletions
diff --git a/tests/unit/unittest/activationsequencecontextprocessortest.cpp b/tests/unit/unittest/activationsequencecontextprocessortest.cpp
index 443a8aeacb..e69f8b97f1 100644
--- a/tests/unit/unittest/activationsequencecontextprocessortest.cpp
+++ b/tests/unit/unittest/activationsequencecontextprocessortest.cpp
@@ -54,7 +54,7 @@ TEST(ActivationSequeneContextProcessor, TextCursorPosition)
ClangCompletionAssistInterface interface("foobar", 4);
ContextProcessor processor{&interface};
- ASSERT_THAT(processor.textCursor_forTestOnly().position(), 4);
+ ASSERT_THAT(processor.textCursor_forTestOnly().position(), 0);
}
TEST(ActivationSequeneContextProcessor, StringLiteral)
diff --git a/tests/unit/unittest/activationsequenceprocessortest.cpp b/tests/unit/unittest/activationsequenceprocessortest.cpp
index 88736f243b..d5962cdc5a 100644
--- a/tests/unit/unittest/activationsequenceprocessortest.cpp
+++ b/tests/unit/unittest/activationsequenceprocessortest.cpp
@@ -47,14 +47,14 @@ 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 position in document" + PrintToString(newPosition))
+ + " and new operator start position" + PrintToString(newPosition))
{
if (arg.completionKind() != completionKind
|| arg.offset() != offset
- || arg.position() != newPosition) {
+ || arg.operatorStartPosition() != newPosition) {
*result_listener << "completion kind is " << PrintToString(Token::name(arg.completionKind()))
<< ", offset is " << PrintToString(arg.offset())
- << " and new position in document is " << PrintToString(arg.position());
+ << " and new operator start position is " << PrintToString(arg.operatorStartPosition());
return false;
}
diff --git a/tests/unit/unittest/clangcompletioncontextanalyzertest.cpp b/tests/unit/unittest/clangcompletioncontextanalyzertest.cpp
index 8603b05c5e..08e92ee2f9 100644
--- a/tests/unit/unittest/clangcompletioncontextanalyzertest.cpp
+++ b/tests/unit/unittest/clangcompletioncontextanalyzertest.cpp
@@ -172,6 +172,20 @@ CCA ClangCompletionContextAnalyzer::runAnalyzer(const char *text)
return analyzer;
}
+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));
+}
+
TEST_F(ClangCompletionContextAnalyzer, AtEndOfDotMember)
{
auto analyzer = runAnalyzer("o.mem@");
@@ -183,7 +197,7 @@ TEST_F(ClangCompletionContextAnalyzer, AtEndOfDotMemberWithSpaceInside)
{
auto analyzer = runAnalyzer("o. mem@");
- ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -4, -4, positionInText));
+ ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -3, -3, positionInText));
}
TEST_F(ClangCompletionContextAnalyzer, AtBeginOfDotMember)
@@ -197,7 +211,7 @@ TEST_F(ClangCompletionContextAnalyzer, AtBeginOfDotMemberWithSpaceInside)
{
auto analyzer = runAnalyzer("o. @mem");
- ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -1, -1, positionInText));
+ ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText));
}
TEST_F(ClangCompletionContextAnalyzer, AtEndOfArrow)
@@ -211,7 +225,7 @@ TEST_F(ClangCompletionContextAnalyzer, AtEndOfArrowWithSpaceInside)
{
auto analyzer = runAnalyzer("o-> mem@");
- ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -4, -4, positionInText));
+ ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -3, -3, positionInText));
}
TEST_F(ClangCompletionContextAnalyzer, AtBeginOfArrow)
@@ -225,7 +239,7 @@ TEST_F(ClangCompletionContextAnalyzer, AtBeginOfArrowWithSpaceInside)
{
auto analyzer = runAnalyzer("o-> @mem");
- ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -1, -1, positionInText));
+ ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, 0, 0, positionInText));
}
TEST_F(ClangCompletionContextAnalyzer, ParameteOneAtCall)
@@ -246,7 +260,7 @@ TEST_F(ClangCompletionContextAnalyzer, ParameteTwoWithSpaceAtCall)
{
auto analyzer = runAnalyzer("f(1, @");
- ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClang, -1, -1, positionInText));
+ ASSERT_THAT(analyzer, HasResult(CCA::PassThroughToLibClangAfterLeftParen, -5, -3, positionInText));
}
TEST_F(ClangCompletionContextAnalyzer, ParameteOneAtSignal)
@@ -396,13 +410,45 @@ TEST_F(ClangCompletionContextAnalyzer, DoxygenMarkerInNonDoxygenComment2)
ASSERT_THAT(analyzer, IsPassThroughToClang());
}
-TEST_F(ClangCompletionContextAnalyzer, OneLineComment)
+TEST_F(ClangCompletionContextAnalyzer, AtEndOfOneLineComment)
{
- auto analyzer = runAnalyzer("// text@");
+ auto analyzer = runAnalyzer("// comment@");
ASSERT_THAT(analyzer, IsPassThroughToClang());
}
+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));
+}
+
TEST_F(ClangCompletionContextAnalyzer, BeginEndComment)
{
auto analyzer = runAnalyzer("/* text@ */");