CppEditor: Tests: Add basic tests for quick fix CompleteSwitchCaseStatement

Change-Id: Idd9773c9f5165ac8a378ee109bf270641a2b3749
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
Nikolai Kosjar
2013-10-14 14:05:34 +02:00
parent 5be56c073e
commit c79a605b8f
2 changed files with 116 additions and 0 deletions

View File

@@ -153,6 +153,10 @@ private slots:
void test_doxygen_comments_cpp_styleA_indented_continuation();
void test_doxygen_comments_cpp_styleA_corner_case();
void test_quickfix_CompleteSwitchCaseStatement_basic1();
void test_quickfix_CompleteSwitchCaseStatement_basic2();
void test_quickfix_CompleteSwitchCaseStatement_oneValueMissing();
void test_quickfix_GenerateGetterSetter_basicGetterWithPrefix();
void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespace();
void test_quickfix_GenerateGetterSetter_basicGetterWithPrefixAndNamespaceToCpp();

View File

@@ -349,6 +349,118 @@ private:
} // anonymous namespace
/// Checks: All enum values are added as case statements for a blank switch.
void CppEditorPlugin::test_quickfix_CompleteSwitchCaseStatement_basic1()
{
const QByteArray original =
"enum EnumType { V1, V2 };\n"
"\n"
"void f()\n"
"{\n"
" EnumType t;\n"
" @switch (t) {\n"
" }\n"
"}\n";
;
const QByteArray expected =
"enum EnumType { V1, V2 };\n"
"\n"
"void f()\n"
"{\n"
" EnumType t;\n"
" switch (t) {\n"
" case V1:\n"
" break;\n"
" case V2:\n"
" break;\n"
" }\n"
"}\n"
"\n"
;
CompleteSwitchCaseStatement factory;
TestCase data(original, expected);
data.run(&factory);
}
/// Checks: All enum values are added as case statements for a blank switch with a default case.
void CppEditorPlugin::test_quickfix_CompleteSwitchCaseStatement_basic2()
{
const QByteArray original =
"enum EnumType { V1, V2 };\n"
"\n"
"void f()\n"
"{\n"
" EnumType t;\n"
" @switch (t) {\n"
" default:\n"
" break;\n"
" }\n"
"}\n";
;
const QByteArray expected =
"enum EnumType { V1, V2 };\n"
"\n"
"void f()\n"
"{\n"
" EnumType t;\n"
" switch (t) {\n"
" case V1:\n"
" break;\n"
" case V2:\n"
" break;\n"
" default:\n"
" break;\n"
" }\n"
"}\n"
"\n"
;
CompleteSwitchCaseStatement factory;
TestCase data(original, expected);
data.run(&factory);
}
/// Checks: The missing enum value is added.
void CppEditorPlugin::test_quickfix_CompleteSwitchCaseStatement_oneValueMissing()
{
const QByteArray original =
"enum EnumType { V1, V2 };\n"
"\n"
"void f()\n"
"{\n"
" EnumType t;\n"
" @switch (t) {\n"
" case V2:\n"
" break;\n"
" default:\n"
" break;\n"
" }\n"
"}\n";
;
const QByteArray expected =
"enum EnumType { V1, V2 };\n"
"\n"
"void f()\n"
"{\n"
" EnumType t;\n"
" switch (t) {\n"
" case V1:\n"
" break;\n"
" case V2:\n"
" break;\n"
" default:\n"
" break;\n"
" }\n"
"}\n"
"\n"
;
CompleteSwitchCaseStatement factory;
TestCase data(original, expected);
data.run(&factory);
}
/// Checks:
/// 1. If the name does not start with ("m_" or "_") and does not
/// end with "_", we are forced to prefix the getter with "get".