diff options
author | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-02-07 09:02:56 +0100 |
---|---|---|
committer | Nikolai Kosjar <nikolai.kosjar@digia.com> | 2013-02-12 11:49:07 +0100 |
commit | aafbf2eaf041c9afd518db6dddc7ea702b05c599 (patch) | |
tree | 7d715a5af2a3ee0b430f2c4eb71da19d0984187d /src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp | |
parent | bd7dfeee921474975268abcea62fa7c90bd31953 (diff) | |
download | qt-creator-aafbf2eaf041c9afd518db6dddc7ea702b05c599.tar.gz |
C++: Make pointer declaration formatter more robust
- Abort on expanded tokens
- Abort on simple declarations starting with "class"/"struct"/"enum"
- Abort if rewritten declaration does not contain '*'/'&'
Change-Id: Ifddb6f20d6bc5c0afc3fcd1d742615198515a04c
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
Diffstat (limited to 'src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp')
-rw-r--r-- | src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp index dbffa14c68..092a2efdd2 100644 --- a/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp +++ b/src/plugins/cpptools/cpppointerdeclarationformatter_test.cpp @@ -575,3 +575,113 @@ void CppToolsPlugin::test_format_pointerdeclaration_multiple_matches_data() " return 0;\n" "}\n"; } + +void CppToolsPlugin::test_format_pointerdeclaration_macros() +{ + QFETCH(QString, source); + QFETCH(QString, reformattedSource); + + TestEnvironment env(source.toLatin1(), Document::ParseTranlationUnit); + AST *ast = env.translationUnit->ast(); + QVERIFY(ast); + + env.applyFormatting(ast, PointerDeclarationFormatter::RespectCursor); + + QCOMPARE(env.textDocument->toPlainText(), reformattedSource); +} + +void CppToolsPlugin::test_format_pointerdeclaration_macros_data() +{ + QTest::addColumn<QString>("source"); + QTest::addColumn<QString>("reformattedSource"); + + QString source; + + source = QLatin1String( + "#define FOO int*\n" + "FOO @bla;\n"); + QTest::newRow("macro-in-simple-declaration") + << source << stripCursor(source); + + source = QLatin1String( + "#define FOO int*\n" + "FOO @f();\n"); + QTest::newRow("macro-in-function-declaration-returntype") + << source << stripCursor(source); + + source = QLatin1String( + "#define FOO int*\n" + "int f(@FOO a);\n"); + QTest::newRow("macro-in-function-declaration-param") + << source << stripCursor(source); + + source = QLatin1String( + "#define FOO int*\n" + "FOO @f() {};\n"); + QTest::newRow("macro-in-function-definition-returntype") + << source << stripCursor(source); + + source = QLatin1String( + "#define FOO int*\n" + "int f(FOO @a) {};\n"); + QTest::newRow("macro-in-function-definition-param") + << source << stripCursor(source); + + source = QLatin1String( + "#define FOO int*\n" + "while (FOO @s = 0);\n"); + QTest::newRow("macro-in-if-while-for") + << source << stripCursor(source); + + source = QLatin1String( + "#define FOO int*\n" + "foreach (FOO @s, list);\n"); + QTest::newRow("macro-in-foreach") + << source << stripCursor(source); + + // The bug was that we got "Reformat to 'QMetaObject staticMetaObject'" + // at the cursor position below, which was completelty wrong. + QTest::newRow("wrong-reformat-suggestion") + << + "#define Q_OBJECT \\\n" + "public: \\\n" + " template <typename T> inline void qt_check_for_QOBJECT_macro(T &_q_argument) \\\n" + " { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i; } \\\n" + " QMetaObject staticMetaObject; \\\n" + " void *qt_metacast(const char *); \\\n" + " static inline QString tr(const char *s, const char *f = 0); \\\n" + " \n" + "class KitInformation\n" + "{\n" + " Q_OBJECT\n" + "public:\n" + " typedef QPair<QString, QString> Item;\n" + " \n" + " Core::Id dataId(); // the higher the closer to top.\n" + " \n" + " unsigned int priority() = 0;\n" + " \n" + " QVariant defaultValue(Kit@*) = 0;\n" + "};\n" + << + "#define Q_OBJECT \\\n" + "public: \\\n" + " template <typename T> inline void qt_check_for_QOBJECT_macro(T &_q_argument) \\\n" + " { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i; } \\\n" + " QMetaObject staticMetaObject; \\\n" + " void *qt_metacast(const char *); \\\n" + " static inline QString tr(const char *s, const char *f = 0); \\\n" + " \n" + "class KitInformation\n" + "{\n" + " Q_OBJECT\n" + "public:\n" + " typedef QPair<QString, QString> Item;\n" + " \n" + " Core::Id dataId(); // the higher the closer to top.\n" + " \n" + " unsigned int priority() = 0;\n" + " \n" + " QVariant defaultValue(Kit *) = 0;\n" + "};\n"; +} |