Commit bd82f038 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

CppEditor: Add basic tests for MoveDeclarationOutOfIf and MoveDeclarationOutOfWhile



Change-Id: I519428496c3139a0ff97ab28d291853eca19887d
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent d39ac6bf
......@@ -141,6 +141,13 @@ private slots:
void test_quickfix_GenerateGetterSetter_notTriggeringOnMemberArray();
void test_quickfix_GenerateGetterSetter_notTriggeringWhenGetterOrSetterExist();
void test_quickfix_MoveDeclarationOutOfIf_ifOnly();
void test_quickfix_MoveDeclarationOutOfIf_ifElse();
void test_quickfix_MoveDeclarationOutOfIf_ifElseIf();
void test_quickfix_MoveDeclarationOutOfWhile_singleWhile();
void test_quickfix_MoveDeclarationOutOfWhile_whileInWhile();
void test_quickfix_ReformatPointerDeclaration();
void test_quickfix_InsertDefFromDecl_basic();
......
......@@ -1003,6 +1003,145 @@ void CppEditorPlugin::test_quickfix_GenerateGetterSetter_notTriggeringWhenGetter
data.run(&factory);
}
void CppEditorPlugin::test_quickfix_MoveDeclarationOutOfIf_ifOnly()
{
const QByteArray original =
"void f()\n"
"{\n"
" if (Foo *@foo = g())\n"
" h();\n"
"}\n";
const QByteArray expected =
"void f()\n"
"{\n"
" Foo *foo = g();\n"
" if (foo)\n"
" h();\n"
"}\n"
"\n";
MoveDeclarationOutOfIf factory;
TestCase data(original, expected);
data.run(&factory);
}
void CppEditorPlugin::test_quickfix_MoveDeclarationOutOfIf_ifElse()
{
const QByteArray original =
"void f()\n"
"{\n"
" if (Foo *@foo = g())\n"
" h();\n"
" else\n"
" i();\n"
"}\n";
const QByteArray expected =
"void f()\n"
"{\n"
" Foo *foo = g();\n"
" if (foo)\n"
" h();\n"
" else\n"
" i();\n"
"}\n"
"\n";
MoveDeclarationOutOfIf factory;
TestCase data(original, expected);
data.run(&factory);
}
void CppEditorPlugin::test_quickfix_MoveDeclarationOutOfIf_ifElseIf()
{
const QByteArray original =
"void f()\n"
"{\n"
" if (Foo *foo = g()) {\n"
" if (Bar *@bar = x()) {\n"
" h();\n"
" j();\n"
" }\n"
" } else {\n"
" i();\n"
" }\n"
"}\n";
const QByteArray expected =
"void f()\n"
"{\n"
" if (Foo *foo = g()) {\n"
" Bar *bar = x();\n"
" if (bar) {\n"
" h();\n"
" j();\n"
" }\n"
" } else {\n"
" i();\n"
" }\n"
"}\n"
"\n";
MoveDeclarationOutOfIf factory;
TestCase data(original, expected);
data.run(&factory);
}
void CppEditorPlugin::test_quickfix_MoveDeclarationOutOfWhile_singleWhile()
{
const QByteArray original =
"void f()\n"
"{\n"
" while (Foo *@foo = g())\n"
" j();\n"
"}\n";
const QByteArray expected =
"void f()\n"
"{\n"
" Foo *foo;\n"
" while ((foo = g()) != 0)\n"
" j();\n"
"}\n"
"\n";
MoveDeclarationOutOfWhile factory;
TestCase data(original, expected);
data.run(&factory);
}
void CppEditorPlugin::test_quickfix_MoveDeclarationOutOfWhile_whileInWhile()
{
const QByteArray original =
"void f()\n"
"{\n"
" while (Foo *foo = g()) {\n"
" while (Bar *@bar = h()) {\n"
" i();\n"
" j();\n"
" }\n"
" }\n"
"}\n";
const QByteArray expected =
"void f()\n"
"{\n"
" while (Foo *foo = g()) {\n"
" Bar *bar;\n"
" while ((bar = h()) != 0) {\n"
" i();\n"
" j();\n"
" }\n"
" }\n"
"}\n"
"\n";
MoveDeclarationOutOfWhile factory;
TestCase data(original, expected);
data.run(&factory);
}
/// Check: Just a basic test since the main functionality is tested in
/// cpppointerdeclarationformatter_test.cpp
void CppEditorPlugin::test_quickfix_ReformatPointerDeclaration()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment