summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletion_test.cpp
diff options
context:
space:
mode:
authorPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>2013-06-18 23:05:57 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-08-05 10:50:38 +0200
commitbfbf93e64f91630d7fad0bad1c4d38898ed5086b (patch)
tree6b5353d4e2bd383d839e5abf3af7587fa474472a /src/plugins/cpptools/cppcompletion_test.cpp
parent62af8171754f8ec892a609ba7434928793026731 (diff)
downloadqt-creator-bfbf93e64f91630d7fad0bad1c4d38898ed5086b.tar.gz
C++: fix auto completion for template parameters
Fix auto completion for the case when template parameter should be found somewhere of scope of template instantiation declaration. Example: struct A { void foo(); struct B { int b; }; }; template<typename T> struct Template { T* get() { return 0; } T t; }; void A::foo() { Template<B> templ; templ.get()->//no autocompletion templ.t.//no autocompletion } Task-number: QTCREATORBUG-8852 Task-number: QTCREATORBUG-9169 Change-Id: I56b40776e66740f995ae6fc5d69e3c50139a3af2 Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cppcompletion_test.cpp')
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp208
1 files changed, 208 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index f1229a38d3..45f7dd1dc3 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -3027,3 +3027,211 @@ void CppToolsPlugin::test_completion_local_type_and_member_6()
QVERIFY(completions.contains(QLatin1String("OtherType")));
QVERIFY(completions.contains(QLatin1String("otherTypeMember")));
}
+
+void CppToolsPlugin::test_completion_template_parameter_defined_inside_scope_of_declaration_QTCREATORBUG9169_1()
+{
+ TestData data;
+ data.srcText =
+ "struct A\n"
+ "{\n"
+ " void foo();\n"
+ " struct B\n"
+ " {\n"
+ " int b;\n"
+ " };\n"
+ "};\n"
+ "template<typename T>\n"
+ "struct Template\n"
+ "{\n"
+ " T* get();\n"
+ "};\n"
+ "namespace foo\n"
+ "{\n"
+ " struct B\n"
+ " {\n"
+ " int foo_b;\n"
+ " };\n"
+ "}\n"
+ "using namespace foo;\n"
+ "void A::foo()\n"
+ "{\n"
+ " Template<B> templ;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ "}\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("templ.get()->");
+ change.insert(data.pos, txt);
+ QTextCursor cursor(data.doc);
+ change.apply(&cursor);
+ data.pos += txt.length();
+
+ QStringList completions = getCompletions(data);
+
+ QCOMPARE(completions.size(), 2);
+ QVERIFY(completions.contains(QLatin1String("B")));
+ QVERIFY(completions.contains(QLatin1String("b")));
+}
+
+void CppToolsPlugin::test_completion_template_parameter_defined_inside_scope_of_declaration_QTCREATORBUG9169_2()
+{
+ TestData data;
+ data.srcText =
+ "struct A\n"
+ "{\n"
+ " void foo();\n"
+ " struct B\n"
+ " {\n"
+ " int b;\n"
+ " };\n"
+ "};\n"
+ "template<typename T>\n"
+ "struct Template\n"
+ "{\n"
+ " T t;\n"
+ "};\n"
+ "namespace foo\n"
+ "{\n"
+ " struct B\n"
+ " {\n"
+ " int foo_b;\n"
+ " };\n"
+ "}\n"
+ "using namespace foo;\n"
+ "void A::foo()\n"
+ "{\n"
+ " Template<B> templ;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ "}\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("templ.t.");
+ change.insert(data.pos, txt);
+ QTextCursor cursor(data.doc);
+ change.apply(&cursor);
+ data.pos += txt.length();
+
+ QStringList completions = getCompletions(data);
+
+ QCOMPARE(completions.size(), 2);
+ QVERIFY(completions.contains(QLatin1String("B")));
+ QVERIFY(completions.contains(QLatin1String("b")));
+}
+
+void CppToolsPlugin::test_completion_template_parameter_defined_inside_scope_of_declaration_QTCREATORBUG8852_1()
+{
+ TestData data;
+ data.srcText =
+ "template <typename T>\n"
+ "struct QList\n"
+ "{\n"
+ " T at(int i) const;\n"
+ "};\n"
+ "namespace ns\n"
+ "{\n"
+ " struct Foo { int bar; };\n"
+ " void foo()\n"
+ " {\n"
+ " QList<Foo> list;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ " }\n"
+ "}\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("list.at(0).");
+ change.insert(data.pos, txt);
+ QTextCursor cursor(data.doc);
+ change.apply(&cursor);
+ data.pos += txt.length();
+
+ QStringList completions = getCompletions(data);
+
+ QCOMPARE(completions.size(), 2);
+ QVERIFY(completions.contains(QLatin1String("Foo")));
+ QVERIFY(completions.contains(QLatin1String("bar")));
+}
+
+void CppToolsPlugin::test_completion_template_parameter_defined_inside_scope_of_declaration_QTCREATORBUG8852_2()
+{
+ TestData data;
+ data.srcText =
+ "template <typename T>\n"
+ "struct QList\n"
+ "{\n"
+ " T at(int i) const;\n"
+ "};\n"
+ "namespace ns\n"
+ "{\n"
+ " struct Foo { int bar; };\n"
+ " namespace nested\n"
+ " {\n"
+ " void foo()\n"
+ " {\n"
+ " QList<Foo> list;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ " }\n"
+ " }\n"
+ "}\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("list.at(0).");
+ change.insert(data.pos, txt);
+ QTextCursor cursor(data.doc);
+ change.apply(&cursor);
+ data.pos += txt.length();
+
+ QStringList completions = getCompletions(data);
+
+ QCOMPARE(completions.size(), 2);
+ QVERIFY(completions.contains(QLatin1String("Foo")));
+ QVERIFY(completions.contains(QLatin1String("bar")));
+}
+
+void CppToolsPlugin::test_completion_template_parameter_defined_inside_scope_of_declaration_QTCREATORBUG8852_3()
+{
+ TestData data;
+ data.srcText =
+ "template <typename T>\n"
+ "struct QList\n"
+ "{\n"
+ " T at(int i) const;\n"
+ "};\n"
+ "namespace ns\n"
+ "{\n"
+ " struct Foo { int bar; };\n"
+ "}\n"
+ "void foo()\n"
+ "{\n"
+ " using namespace ns;\n"
+ " QList<Foo> list;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ "}\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("list.at(0).");
+ change.insert(data.pos, txt);
+ QTextCursor cursor(data.doc);
+ change.apply(&cursor);
+ data.pos += txt.length();
+
+ QStringList completions = getCompletions(data);
+
+ QCOMPARE(completions.size(), 2);
+ QVERIFY(completions.contains(QLatin1String("Foo")));
+ QVERIFY(completions.contains(QLatin1String("bar")));
+}