diff --git a/src/plugins/cppeditor/cppeditorplugin.h b/src/plugins/cppeditor/cppeditorplugin.h index c1eb519de1e04f2e2c7675e9b291804e866a85bb..d4c5474c64b2d4fda980bb80834617109bb6d625 100644 --- a/src/plugins/cppeditor/cppeditorplugin.h +++ b/src/plugins/cppeditor/cppeditorplugin.h @@ -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(); diff --git a/src/plugins/cppeditor/cppquickfix_test.cpp b/src/plugins/cppeditor/cppquickfix_test.cpp index 31c4b6513f18a75cd62a144280ace890bdea0945..b1bc78d29205a00f07fe5e27838526a968fed74b 100644 --- a/src/plugins/cppeditor/cppquickfix_test.cpp +++ b/src/plugins/cppeditor/cppquickfix_test.cpp @@ -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".