CppEditor: Don't create 'namespace xyz{}' if there is 'using namespace xyz'

Change-Id: Idc08de5f44ccac0de8490158199c4e44f7efe79e
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
Leander Schulten
2020-07-21 02:46:43 +02:00
parent 8469886ab8
commit fdd70d898d
2 changed files with 288 additions and 11 deletions

View File

@@ -2218,6 +2218,85 @@ void CppEditorPlugin::test_quickfix_GenerateGetterSetter_createNamespaceInCpp_da
QTest::addRow("all namespaces already present")
<< QByteArrayList{originalHeader, expectedHeader}
<< QByteArrayList{originalSource, expectedSource};
originalSource = "#include \"file.h\"\n"
"namespace N1 {\n"
"using namespace N2::N3;\n"
"using namespace N2;\n"
"using namespace N2;\n"
"using namespace N3;\n"
"}\n";
expectedSource = "#include \"file.h\"\n"
"namespace N1 {\n"
"using namespace N2::N3;\n"
"using namespace N2;\n"
"using namespace N2;\n"
"using namespace N3;\n"
"\n"
"int Something::getIt() const\n"
"{\n"
" return it;\n"
"}\n"
"\n"
"void Something::setIt(int value)\n"
"{\n"
" it = value;\n"
"}\n\n"
"}\n";
QTest::addRow("namespaces present and using namespace")
<< QByteArrayList{originalHeader, expectedHeader}
<< QByteArrayList{originalSource, expectedSource};
originalSource = "#include \"file.h\"\n"
"using namespace N1::N2::N3;\n"
"using namespace N1::N2;\n"
"namespace N1 {\n"
"using namespace N3;\n"
"}\n";
expectedSource = "#include \"file.h\"\n"
"using namespace N1::N2::N3;\n"
"using namespace N1::N2;\n"
"namespace N1 {\n"
"using namespace N3;\n"
"\n"
"int Something::getIt() const\n"
"{\n"
" return it;\n"
"}\n"
"\n"
"void Something::setIt(int value)\n"
"{\n"
" it = value;\n"
"}\n"
"\n"
"}\n";
QTest::addRow("namespaces present and outer using namespace")
<< QByteArrayList{originalHeader, expectedHeader}
<< QByteArrayList{originalSource, expectedSource};
originalSource = "#include \"file.h\"\n"
"using namespace N1;\n"
"using namespace N2;\n"
"namespace N3 {\n"
"}\n";
expectedSource = "#include \"file.h\"\n"
"using namespace N1;\n"
"using namespace N2;\n"
"namespace N3 {\n"
"}\n"
"\n"
"int Something::getIt() const\n"
"{\n"
" return it;\n"
"}\n"
"\n"
"void Something::setIt(int value)\n"
"{\n"
" it = value;\n"
"}\n";
QTest::addRow("namespaces present and outer using namespace")
<< QByteArrayList{originalHeader, expectedHeader}
<< QByteArrayList{originalSource, expectedSource};
}
void CppEditorPlugin::test_quickfix_GenerateGetterSetter_createNamespaceInCpp()