summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcompletion_test.cpp
diff options
context:
space:
mode:
authorPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>2017-05-24 11:08:24 +0200
committerPrzemyslaw Gorszkowski <pgorszkowski@gmail.com>2017-06-15 17:18:20 +0000
commit7bcf4831891536992607b5a7b43675590790ee59 (patch)
tree4b71a2479d5dd31d500d2d0a8c17b4538866ee42 /src/plugins/cpptools/cppcompletion_test.cpp
parentd3d3e2ace5485d3812d98b5b3f3ccd8e7c12b4f1 (diff)
downloadqt-creator-7bcf4831891536992607b5a7b43675590790ee59.tar.gz
C++: fix code completion of stl containers in internal code model
This fix makes some trick and replaces existing typedef of 'pointer' to the simplest one(only in class unique_ptr), e.g.: template <class _Tp> class unique_ptr { typedef some_strange_things pointer; pointer operator->(); } is replace with template <class _Tp> class unique_ptr { typedef _Tp* pointer; pointer operator->(); } In most of the implementation of unique_ptr it should work. Similar approach is done for std::list, std::vector, std::queue, std::set, std::multiset, std::unordered_set. It is done in this hacky way to omit problems with cyclic and complex resolving of typedefs. Change-Id: I1363dfc5e23d3cd2fa7af7fc27423bfbac2d894d Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cppcompletion_test.cpp')
-rw-r--r--src/plugins/cpptools/cppcompletion_test.cpp163
1 files changed, 163 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp
index 1fd80aad13..b494476351 100644
--- a/src/plugins/cpptools/cppcompletion_test.cpp
+++ b/src/plugins/cpptools/cppcompletion_test.cpp
@@ -2584,6 +2584,169 @@ void CppToolsPlugin::test_completion_data()
" @\n"
"}\n"
) << _("t.p->") << QStringList({"Foo", "bar"});
+
+ QTest::newRow("fix_code_completion_for_unique_ptr_operator_arrow") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct unique_ptr\n"
+ "{\n"
+ " typedef FOO pointer;\n"
+ " pointer operator->();\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::unique_ptr<Foo> ptr;\n"
+ " @\n"
+ "}\n"
+ ) << _("ptr->") << QStringList({"Foo", "bar"});
+ QTest::newRow("fix_code_completion_for_unique_ptr_method_get") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct unique_ptr\n"
+ "{\n"
+ " typedef FOO pointer;\n"
+ " pointer get();\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::unique_ptr<Foo> ptr;\n"
+ " @\n"
+ "}\n"
+ ) << _("ptr.get()->") << QStringList({"Foo", "bar"});
+ QTest::newRow("fix_code_completion_for_std_vector_method_at") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct vector\n"
+ "{\n"
+ " typedef FOO reference;\n"
+ " reference at(size_t i);\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::vector<Foo> v;\n"
+ " @\n"
+ "}\n"
+ ) << _("v.at(0).") << QStringList({"Foo", "bar"});
+ QTest::newRow("fix_code_completion_for_std_vector_operator_square_brackets") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct vector\n"
+ "{\n"
+ " typedef FOO reference;\n"
+ " reference operator[](size_t i);\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::vector<Foo> v;\n"
+ " @\n"
+ "}\n"
+ ) << _("v[0].") << QStringList({"Foo", "bar"});
+ QTest::newRow("fix_code_completion_for_std_list_method_front") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct list\n"
+ "{\n"
+ " typedef FOO reference;\n"
+ " reference front();\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::list<Foo> l;\n"
+ " @\n"
+ "}\n"
+ ) << _("l.front().") << QStringList({"Foo", "bar"});
+ QTest::newRow("fix_code_completion_for_std_queue_method_front") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct queue\n"
+ "{\n"
+ " typedef FOO reference;\n"
+ " reference front();\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::queue<Foo> l;\n"
+ " @\n"
+ "}\n"
+ ) << _("l.front().") << QStringList({"Foo", "bar"});
+ QTest::newRow("fix_code_completion_for_std_set_method_begin") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct set\n"
+ "{\n"
+ " typedef FOO iterator;\n"
+ " iterator begin();\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::set<Foo> s;\n"
+ " @\n"
+ "}\n"
+ ) << _("s.begin()->") << QStringList({"Foo", "bar"});
+ QTest::newRow("fix_code_completion_for_std_multiset_method_begin") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct multiset\n"
+ "{\n"
+ " typedef FOO iterator;\n"
+ " iterator begin();\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::multiset<Foo> s;\n"
+ " @\n"
+ "}\n"
+ ) << _("s.begin()->") << QStringList({"Foo", "bar"});
+ QTest::newRow("fix_code_completion_for_std_unordered_set_method_begin") << _(
+ "namespace std {\n"
+ "template<typename _Tp>\n"
+ "struct unordered_set\n"
+ "{\n"
+ " typedef FOO iterator;\n"
+ " iterator begin();\n"
+ "};\n"
+ "}\n"
+ "\n"
+ "struct Foo { int bar; };\n"
+ "\n"
+ "void func()\n"
+ "{\n"
+ " std::unordered_set<Foo> s;\n"
+ " @\n"
+ "}\n"
+ ) << _("s.begin()->") << QStringList({"Foo", "bar"});
}
void CppToolsPlugin::test_completion_member_access_operator()