forked from qt-creator/qt-creator
CppEditor: Insert/move member definition right after enclosing class
When triggering move or insert definition outside and no other class symbol is found in the file, the definition is moved or inserted right after the enclosing Class. Change-Id: I74ffa872015753ba7372e21b868d3cf7fa49e84a Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com>
This commit is contained in:
committed by
Nikolai Kosjar
parent
6558df08d0
commit
a338851a10
@@ -781,6 +781,50 @@ void CppEditorPlugin::test_quickfix_InsertDefFromDecl_basic()
|
||||
data.run(&factory);
|
||||
}
|
||||
|
||||
/// Check if definition is inserted right after class for insert definition outside
|
||||
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_afterClass()
|
||||
{
|
||||
QList<TestDocumentPtr> testFiles;
|
||||
QByteArray original;
|
||||
QByteArray expected;
|
||||
|
||||
// Header File
|
||||
original =
|
||||
"class Foo\n"
|
||||
"{\n"
|
||||
" Foo();\n"
|
||||
" void a@();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"class Bar {};\n";
|
||||
expected =
|
||||
"class Foo\n"
|
||||
"{\n"
|
||||
" Foo();\n"
|
||||
" void a();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void Foo::a()\n"
|
||||
"{\n\n}\n"
|
||||
"\n"
|
||||
"class Bar {};\n\n";
|
||||
testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
|
||||
|
||||
// Source File
|
||||
original =
|
||||
"#include \"file.h\"\n"
|
||||
"\n"
|
||||
"Foo::Foo()\n"
|
||||
"{\n\n"
|
||||
"}\n";
|
||||
expected = original + "\n";
|
||||
testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
|
||||
|
||||
InsertDefFromDecl factory;
|
||||
TestCase data(testFiles);
|
||||
data.run(&factory, 1);
|
||||
}
|
||||
|
||||
/// Check from header file: If there is a source file, insert the definition in the source file.
|
||||
void CppEditorPlugin::test_quickfix_InsertDefFromDecl_headerSource_basic1()
|
||||
{
|
||||
@@ -1877,7 +1921,6 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_MemberFuncOutside2()
|
||||
" void f3();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"\n"
|
||||
"int Foo::f2()\n"
|
||||
"{\n"
|
||||
" return 1;\n"
|
||||
@@ -2180,6 +2223,49 @@ void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_CtorWithInitialization2()
|
||||
data.run(&factory);
|
||||
}
|
||||
|
||||
/// Check if definition is inserted right after class for move definition outside
|
||||
void CppEditorPlugin::test_quickfix_MoveFuncDefOutside_afterClass()
|
||||
{
|
||||
QList<TestDocumentPtr> testFiles;
|
||||
QByteArray original;
|
||||
QByteArray expected;
|
||||
|
||||
// Header File
|
||||
original =
|
||||
"class Foo\n"
|
||||
"{\n"
|
||||
" Foo();\n"
|
||||
" void a@() {}\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"class Bar {};\n";
|
||||
expected =
|
||||
"class Foo\n"
|
||||
"{\n"
|
||||
" Foo();\n"
|
||||
" void a();\n"
|
||||
"};\n"
|
||||
"\n"
|
||||
"void Foo::a() {}\n"
|
||||
"\n"
|
||||
"class Bar {};\n\n";
|
||||
testFiles << TestDocument::create(original, expected, QLatin1String("file.h"));
|
||||
|
||||
// Source File
|
||||
original =
|
||||
"#include \"file.h\"\n"
|
||||
"\n"
|
||||
"Foo::Foo()\n"
|
||||
"{\n\n"
|
||||
"}\n";
|
||||
expected = original + "\n";
|
||||
testFiles << TestDocument::create(original, expected, QLatin1String("file.cpp"));
|
||||
|
||||
MoveFuncDefOutside factory;
|
||||
TestCase data(testFiles);
|
||||
data.run(&factory, 1);
|
||||
}
|
||||
|
||||
/// Check: revert test_quickfix_MoveFuncDefOutside_MemberFuncToCpp()
|
||||
void CppEditorPlugin::test_quickfix_MoveFuncDefToDecl_MemberFunc()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user