diff options
author | Przemyslaw Gorszkowski <pgorszkowski@gmail.com> | 2012-12-05 09:20:52 +0100 |
---|---|---|
committer | Erik Verbruggen <erik.verbruggen@digia.com> | 2012-12-06 10:57:35 +0100 |
commit | 31ce303ee71214d40fdd714fdc287f3772e8474e (patch) | |
tree | 8b0d51ff43669e612eea1b6845f86ff9ce3787c1 /src/plugins/cpptools | |
parent | d9571f2ecd5678856c91467fb02f2aaaae1fa772 (diff) | |
download | qt-creator-31ce303ee71214d40fdd714fdc287f3772e8474e.tar.gz |
C++: fix code completion: casting inside parentheses
Included unit tests.
Task-number: QTCREATORBUG-8368
Change-Id: I1b04124bc2c9eac050cfb2e6d3a5c1aca5311f4b
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cpptools')
-rw-r--r-- | src/plugins/cpptools/cppcompletion_test.cpp | 81 | ||||
-rw-r--r-- | src/plugins/cpptools/cpptoolsplugin.h | 2 |
2 files changed, 83 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cppcompletion_test.cpp b/src/plugins/cpptools/cppcompletion_test.cpp index 4df7400978..9eb28dca97 100644 --- a/src/plugins/cpptools/cppcompletion_test.cpp +++ b/src/plugins/cpptools/cppcompletion_test.cpp @@ -152,6 +152,87 @@ void CppToolsPlugin::test_completion_forward_declarations_present() QCOMPARE(completions, expected); } +void CppToolsPlugin::test_completion_inside_parentheses_c_style_conversion() +{ + TestData data; + data.srcText = "\n" + "class Base\n" + "{\n" + " int i_base;\n" + "};\n" + "\n" + "class Derived : public Base\n" + "{\n" + " int i_derived;\n" + "};\n" + "\n" + "void fun()\n" + "{\n" + " Base *b = new Derived;\n" + " if (1)\n" + " @\n" + "}\n" + ; + + setup(&data); + + Utils::ChangeSet change; + QString txt = QLatin1String("((Derived *)b)->"); + change.insert(data.pos, txt); + QTextCursor cursor(data.doc); + change.apply(&cursor); + data.pos += txt.length(); + + QStringList completions = getCompletions(data); + + QCOMPARE(completions.size(), 4); + QVERIFY(completions.contains(QLatin1String("Derived"))); + QVERIFY(completions.contains(QLatin1String("Base"))); + QVERIFY(completions.contains(QLatin1String("i_derived"))); + QVERIFY(completions.contains(QLatin1String("i_base"))); + +} + +void CppToolsPlugin::test_completion_inside_parentheses_cast_operator_conversion() +{ + TestData data; + data.srcText = "\n" + "class Base\n" + "{\n" + " int i_base;\n" + "};\n" + "\n" + "class Derived : public Base\n" + "{\n" + " int i_derived;\n" + "};\n" + "\n" + "void fun()\n" + "{\n" + " Base *b = new Derived;\n" + " if (1)\n" + " @\n" + "}\n" + ; + + setup(&data); + + Utils::ChangeSet change; + QString txt = QLatin1String("(static_cast<Derived *>(b))->"); + change.insert(data.pos, txt); + QTextCursor cursor(data.doc); + change.apply(&cursor); + data.pos += txt.length(); + + QStringList completions = getCompletions(data); + + QCOMPARE(completions.size(), 4); + QVERIFY(completions.contains(QLatin1String("Derived"))); + QVERIFY(completions.contains(QLatin1String("Base"))); + QVERIFY(completions.contains(QLatin1String("i_derived"))); + QVERIFY(completions.contains(QLatin1String("i_base"))); +} + void CppToolsPlugin::test_completion_basic_1() { TestData data; diff --git a/src/plugins/cpptools/cpptoolsplugin.h b/src/plugins/cpptools/cpptoolsplugin.h index c338a24dfe..b56ee4aa0d 100644 --- a/src/plugins/cpptools/cpptoolsplugin.h +++ b/src/plugins/cpptools/cpptoolsplugin.h @@ -90,6 +90,8 @@ private slots: void test_codegen_definition_middle_member(); void test_completion_forward_declarations_present(); + void test_completion_inside_parentheses_c_style_conversion(); + void test_completion_inside_parentheses_cast_operator_conversion(); void test_completion_basic_1(); void test_completion_template_1(); void test_completion_template_2(); |