summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletion_test.cpp
diff options
context:
space:
mode:
authorPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>2013-04-15 12:50:36 +0200
committerErik Verbruggen <erik.verbruggen@digia.com>2013-04-22 10:06:05 +0200
commit564c9b2842663062658a0febdcc5787098d871b2 (patch)
tree4d10cf5dd7fd48852659d5022f69592e6bad8d6f /src/plugins/cpptools/cppcompletion_test.cpp
parentb782d191cfd81acdb349c2f342133575188db43a (diff)
downloadqt-creator-564c9b2842663062658a0febdcc5787098d871b2.tar.gz
C++: fix support for typedef of templated typedefs
Fix: * code completion * follow symbols * find usages Task-number: QTCREATORBUG-8375 Change-Id: Ia40273fec3dead76acad4695b852a9e53065d8a7 Reviewed-by: Petar Perisin <petar.perisin@gmail.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cppcompletion_test.cpp')
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp135
1 files changed, 135 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index b8ee95f7c0..b5cd103374 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -1882,3 +1882,138 @@ void CppToolsPlugin::test_completion_QTCREATORBUG9098()
QVERIFY(completions.contains(QLatin1String("c")));
QVERIFY(completions.contains(QLatin1String("B")));
}
+
+void CppToolsPlugin::test_completion_typedef_of_templated_typedef_QTCREATORBUG8375()
+{
+ TestData data;
+ data.srcText =
+ "struct Foo\n"
+ "{ void bar(); };\n"
+ "struct A\n"
+ "{ typedef Foo AFoo; };\n"
+ "template <class T>\n"
+ "struct B\n"
+ "{ typedef typename T::AFoo BFoo; };\n"
+ "struct C : public B<A>\n"
+ "{\n"
+ " void test()\n"
+ " {\n"
+ " BFoo foo;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ " }\n"
+ "};\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("foo.");
+ 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_typedef_with_the_same_base_name_and_new_type_name()
+{
+ TestData data;
+ data.srcText =
+ "namespace A\n"
+ "{\n"
+ "struct A { int aa; };\n"
+ "}\n"
+ "struct S\n"
+ "{\n"
+ " typedef A::A A;\n"
+ " A a;\n"
+ "};\n"
+ "void fun()\n"
+ "{\n"
+ " S s;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ "};\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("s.a.");
+ 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("A")));
+ QVERIFY(completions.contains(QLatin1String("aa")));
+}
+
+void CppToolsPlugin::test_completion_qualified_typedef_1()
+{
+ TestData data;
+ data.srcText =
+ "struct S\n"
+ "{\n"
+ " typedef S::type type;\n"
+ "};\n"
+ "void fun()\n"
+ "{\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ "};\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("S::");
+ 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("S")));
+ QVERIFY(completions.contains(QLatin1String("type")));
+}
+
+void CppToolsPlugin::test_completion_qualified_typedef_2()
+{
+ TestData data;
+ data.srcText =
+ "template <typename T>\n"
+ "struct S\n"
+ "{\n"
+ " typedef S<T>::type type;\n"
+ "};\n"
+ "void fun()\n"
+ "{\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ "};\n"
+ ;
+ setup(&data);
+
+ Utils::ChangeSet change;
+ QString txt = QLatin1String("S<int>::");
+ 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("S")));
+ QVERIFY(completions.contains(QLatin1String("type")));
+}
+