C++: Handle recursive using/typedef declarations

Remember using/typedef declarations we have already looked up and
stop if we try it again.

Change-Id: I91bf0aef4df18539a47d015f0113543aef1f692a
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2013-06-11 10:22:10 +02:00
parent 8f1b665667
commit 50a900e509
4 changed files with 155 additions and 4 deletions

View File

@@ -2326,3 +2326,140 @@ void CppToolsPlugin::test_completion_recursive_auto_declarations2_QTCREATORBUG95
QCOMPARE(completions.size(), 0);
}
void CppToolsPlugin::test_completion_recursive_typedefs_declarations1()
{
TestData data;
data.srcText =
"void f()\n"
"{\n"
" typedef A B;\n"
" typedef B A;\n"
" A a;\n"
" @;\n"
" // padding so we get the scope right\n"
"}\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("a.");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 0);
}
void CppToolsPlugin::test_completion_recursive_typedefs_declarations2()
{
TestData data;
data.srcText =
"void f()\n"
"{\n"
" typedef A C;\n"
" typedef C B;\n"
" typedef B A;\n"
" A a;\n"
" @;\n"
" // padding so we get the scope right\n"
"}\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("a.");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 0);
}
void CppToolsPlugin::test_completion_recursive_using_declarations1()
{
TestData data;
data.srcText =
"void f()\n"
"{\n"
" using B = A;\n"
" using A = B;\n"
" A a;\n"
" @;\n"
" // padding so we get the scope right\n"
"}\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("a.");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 0);
}
void CppToolsPlugin::test_completion_recursive_using_declarations2()
{
TestData data;
data.srcText =
"void f()\n"
"{\n"
" using C = A;\n"
" using B = C;\n"
" using A = B;\n"
" A a;\n"
" @;\n"
" // padding so we get the scope right\n"
"}\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("a.");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 0);
}
void CppToolsPlugin::test_completion_recursive_using_typedef_declarations()
{
TestData data;
data.srcText =
"void f()\n"
"{\n"
" using B = A;\n"
" typedef B A;\n"
" A a;\n"
" @;\n"
" // padding so we get the scope right\n"
"}\n"
;
setup(&data);
Utils::ChangeSet change;
QString txt = QLatin1String("a.");
change.insert(data.pos, txt);
QTextCursor cursor(data.doc);
change.apply(&cursor);
data.pos += txt.length();
QStringList completions = getCompletions(data);
QCOMPARE(completions.size(), 0);
}

View File

@@ -140,6 +140,11 @@ private slots:
void test_completion_crash_cloning_template_class_QTCREATORBUG9329();
void test_completion_recursive_auto_declarations1_QTCREATORBUG9503();
void test_completion_recursive_auto_declarations2_QTCREATORBUG9503();
void test_completion_recursive_typedefs_declarations1();
void test_completion_recursive_typedefs_declarations2();
void test_completion_recursive_using_declarations1();
void test_completion_recursive_using_declarations2();
void test_completion_recursive_using_typedef_declarations();
void test_format_pointerdeclaration_in_simpledeclarations();
void test_format_pointerdeclaration_in_simpledeclarations_data();