summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletion_test.cpp
diff options
context:
space:
mode:
authorPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>2013-04-26 14:54:49 +0200
committerNikolai Kosjar <nikolai.kosjar@digia.com>2013-05-02 10:42:19 +0200
commit64d80150faaffa34f0a05c9692d7286c473c0b01 (patch)
tree7d7bc7e28d9d130bad60ae788218def06f3c236d /src/plugins/cpptools/cppcompletion_test.cpp
parent6441c258e61a0de41f3149f8ec7af302f4562189 (diff)
downloadqt-creator-64d80150faaffa34f0a05c9692d7286c473c0b01.tar.gz
C++: fix code completion when 'using' declaration inside function
Looking for using declaration when lookup a type Task-number: QTCREATORBUG-2668 Change-Id: I11600c5be262840472dd4c9e72334760a35aa4a0 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.cpp133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index b8ee95f7c0..d231f6f317 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -1882,3 +1882,136 @@ void CppToolsPlugin::test_completion_QTCREATORBUG9098()
QVERIFY(completions.contains(QLatin1String("c")));
QVERIFY(completions.contains(QLatin1String("B")));
}
+
+void CppToolsPlugin::test_completion_type_and_using_declaration()
+{
+ test_completion();
+}
+
+void CppToolsPlugin::test_completion_type_and_using_declaration_data()
+{
+ QTest::addColumn<QByteArray>("code");
+ QTest::addColumn<QStringList>("expectedCompletions");
+
+ QByteArray code;
+ QStringList completions;
+
+ code = "\n"
+ "namespace NS\n"
+ "{\n"
+ "struct C { int m; };\n"
+ "}\n"
+ "void foo()\n"
+ "{\n"
+ " using NS::C;\n"
+ " C c;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ "}\n";
+ completions.append(QLatin1String("C"));
+ completions.append(QLatin1String("m"));
+ QTest::newRow("case: type and using declaration inside function")
+ << code << completions;
+
+ completions.clear();
+
+ code = "\n"
+ "namespace NS\n"
+ "{\n"
+ "struct C { int m; };\n"
+ "}\n"
+ "using NS::C;\n"
+ "void foo()\n"
+ "{\n"
+ " C c;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ "}\n";
+ completions.append(QLatin1String("C"));
+ completions.append(QLatin1String("m"));
+ QTest::newRow("case: type and using declaration in global namespace")
+ << code << completions;
+
+ completions.clear();
+
+ code = "\n"
+ "struct C { int m; };\n"
+ "namespace NS\n"
+ "{\n"
+ " using ::C;\n"
+ " void foo()\n"
+ " {\n"
+ " C c;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ " }\n"
+ "}\n";
+ completions.append(QLatin1String("C"));
+ completions.append(QLatin1String("m"));
+ QTest::newRow("case: type in global namespace and using declaration in NS namespace")
+ << code << completions;
+
+ completions.clear();
+
+ code = "\n"
+ "struct C { int m; };\n"
+ "namespace NS\n"
+ "{\n"
+ " void foo()\n"
+ " {\n"
+ " using ::C;\n"
+ " C c;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ " }\n"
+ "}\n";
+ completions.append(QLatin1String("C"));
+ completions.append(QLatin1String("m"));
+ QTest::newRow("case: type in global namespace and using declaration inside function in NS namespace")
+ << code << completions;
+
+ completions.clear();
+
+ code = "\n"
+ "namespace NS1\n"
+ "{\n"
+ "struct C { int m; };\n"
+ "}\n"
+ "namespace NS2\n"
+ "{\n"
+ " void foo()\n"
+ " {\n"
+ " using NS1::C;\n"
+ " C c;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ " }\n"
+ "}\n";
+ completions.append(QLatin1String("C"));
+ completions.append(QLatin1String("m"));
+ QTest::newRow("case: type inside namespace NS1 and using declaration in function inside NS2 namespace")
+ << code << completions;
+
+ completions.clear();
+
+ code = "\n"
+ "namespace NS1\n"
+ "{\n"
+ "struct C { int m; };\n"
+ "}\n"
+ "namespace NS2\n"
+ "{\n"
+ " using NS1::C;\n"
+ " void foo()\n"
+ " {\n"
+ " C c;\n"
+ " @\n"
+ " // padding so we get the scope right\n"
+ " }\n"
+ "}\n";
+ completions.append(QLatin1String("C"));
+ completions.append(QLatin1String("m"));
+ QTest::newRow("case: type inside namespace NS1 and using declaration inside NS2 namespace")
+ << code << completions;
+
+}